Skip to content

Commit 5d86d84

Browse files
committed
wip: python support
1 parent 26f3e8b commit 5d86d84

8 files changed

Lines changed: 676 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ Testing/
7171
# spack environment artifacts (spack.yaml is tracked; these are generated)
7272
.spack-env/
7373
spack.lock
74+
75+
# python binding artifacts
76+
python/graphos/_core*.so
77+
python/graphos/__pycache__/
78+
python/tests/__pycache__/

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ if(GRAPHOS_BUILD_BENCH AND PROJECT_IS_TOP_LEVEL)
7575
add_subdirectory(bench)
7676
endif()
7777

78+
option(GRAPHOS_BUILD_PYTHON "Build the Python bindings (graphos._core)" OFF)
79+
if(GRAPHOS_BUILD_PYTHON AND PROJECT_IS_TOP_LEVEL)
80+
add_subdirectory(python)
81+
endif()
82+
7883
# ---- installation ----------------------------------------------------------
7984
include(GNUInstallDirs)
8085
include(CMakePackageConfigHelpers)

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ Two disciplines follow:
127127
`freeze(c, halo_depth)` records the ghost-ring depth (default 1) that Local
128128
queries are guaranteed correct within.
129129

130+
## Python bindings
131+
132+
`-DGRAPHOS_BUILD_PYTHON=ON` builds `graphos._core` (pybind11, fetched
133+
automatically) into `python/graphos/`; run with `PYTHONPATH=python`. The
134+
whole calculus and query surface is exposed with the same names; markers
135+
take Python callables as predicates (`marker.mark_where(1, lambda e: ...)`),
136+
identifications and glue are lists of `(from, to[, sign])` tuples, and
137+
chain maps come back as NumPy arrays. Lifetime follows the builder/frozen
138+
split: accessors on `Complex` and on operation results return array
139+
copies; `FrozenComplex.boundary/coboundary` return zero-copy views whose
140+
base keeps the frozen complex alive. `python/tests/test_graphos.py`
141+
re-asserts the mathematical certificates through the bindings and runs as
142+
the `python.test_graphos` ctest entry.
143+
130144
## Build, test, install
131145

132146
```bash

include/graphos/core/frozen.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class FrozenComplex {
6969
}
7070
}
7171

72+
// frozen storage is move-only (exec::Array owns device-capable memory);
73+
// stating it explicitly keeps type traits honest for bindings
74+
FrozenComplex(const FrozenComplex&) = delete;
75+
FrozenComplex& operator=(const FrozenComplex&) = delete;
76+
FrozenComplex(FrozenComplex&&) = default;
77+
FrozenComplex& operator=(FrozenComplex&&) = default;
78+
7279
int dim() const { return dim_; }
7380

7481
int halo_depth() const { return halo_depth_; }

python/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include(FetchContent)
2+
FetchContent_Declare(pybind11
3+
GIT_REPOSITORY https://github.com/pybind/pybind11.git
4+
GIT_TAG stable)
5+
FetchContent_MakeAvailable(pybind11)
6+
7+
pybind11_add_module(_core bindings.cpp)
8+
target_link_libraries(_core PRIVATE graphos::graphos)
9+
set_target_properties(_core PROPERTIES
10+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/graphos)
11+
12+
if(BUILD_TESTING)
13+
add_test(NAME python.test_graphos
14+
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_graphos.py)
15+
set_tests_properties(python.test_graphos PROPERTIES
16+
ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}")
17+
endif()

0 commit comments

Comments
 (0)