Skip to content

Commit d7cf365

Browse files
awvwgkCopilot
andcommitted
Address SkalaXC binding, ownership, batching, and packaging review
Exercise installed Python bindings and stubs across native backend variants; fix mixed pytest collection, resolved GauXC test paths, MPI package dependencies, elemental Fortran ownership, CUDA launch-sized task tiles, and checked HDF5 density reads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6ee1c77 commit d7cf365

25 files changed

Lines changed: 556 additions & 65 deletions

‎.github/workflows/pyscf-skalaxc-parity.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ jobs:
6868
--no-build-isolation --no-deps --force-reinstall
6969
7070
- name: Run direct-binding parity tests
71-
run: pytest -v tests/test_pyscf_skalaxc_parity.py
71+
run: |
72+
python -c "import skalaxc; assert skalaxc.HDF5_ENABLED and not skalaxc.CUDA_ENABLED and not skalaxc.MPI_ENABLED"
73+
pytest -v tests/test_pyscf_skalaxc_parity.py

‎.github/workflows/skala-test.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'pixi.toml'
1111
- 'pyproject.toml'
1212
- 'skala/**'
13+
- 'tests/**'
1314
- 'tools/**'
1415
pull_request:
1516
branches: [main]
@@ -59,6 +60,9 @@ jobs:
5960
--cov-report=term-missing --cov-report=html --durations=50
6061
--durations-min=1.0 skala/src/skala/ skala/tests/
6162
63+
- name: Check combined root and runtime collection
64+
run: python -m pytest --collect-only -q -ra tests/ skala/tests/test_build_release.py
65+
6266
- name: Print CPU diagnostics on failure
6367
if: ${{ failure() }}
6468
uses: ./.github/actions/cpu-diagnostics

‎.github/workflows/skalaxc-ci.yml‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
steps:
8686
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
8787
with:
88-
submodules: recursive
88+
submodules: ${{ matrix.name != 'serial-debug' && 'recursive' || 'false' }}
8989

9090
- name: Setup Pixi
9191
uses: ./.github/actions/setup-pixi
@@ -144,6 +144,27 @@ jobs:
144144
ctest --test-dir SkalaXC/build-installed-consumers-${{ matrix.name }} \
145145
--no-tests=error --output-on-failure
146146
147+
- name: Install Python binding against tested native package
148+
if: matrix.name == 'serial-release' || matrix.name == 'mpi-release'
149+
env:
150+
SkalaXC_DIR: ${{ github.workspace }}/SkalaXC/install-ci-${{ matrix.name }}/lib/cmake/SkalaXC
151+
SKALAXC_PYTHON_LAYOUT: WHEEL
152+
run: python -m pip install SkalaXC/python --no-build-isolation --no-deps --force-reinstall
153+
154+
- name: Test installed CPU binding and generated stubs
155+
if: matrix.name == 'serial-release' || matrix.name == 'mpi-release'
156+
env:
157+
EXPECT_MPI: ${{ matrix.mpi }}
158+
run: |
159+
python -c "import os, skalaxc, h5py, mypy; assert skalaxc.HDF5_ENABLED and not skalaxc.CUDA_ENABLED; assert skalaxc.MPI_ENABLED == (os.environ['EXPECT_MPI'] == 'ON'); assert skalaxc.PYTHON_LAYOUT == 'WHEEL'"
160+
python -m pytest -v -ra SkalaXC/python/tests --ignore=SkalaXC/python/tests/test_mpi.py
161+
162+
- name: Test installed MPI binding on two ranks
163+
if: matrix.name == 'mpi-release'
164+
run: |
165+
mpiexec --oversubscribe -n 2 python -c "import skalaxc; from mpi4py import MPI; assert skalaxc.MPI_ENABLED and MPI.COMM_WORLD.size == 2"
166+
mpiexec --oversubscribe -n 2 python -m pytest -v -ra SkalaXC/python/tests/test_mpi.py
167+
147168
sanitizer:
148169
name: gcc-asan-ubsan
149170
runs-on: ubuntu-latest

‎.github/workflows/skalaxc-cuda.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ jobs:
187187
python -c "import skalaxc, torch; assert skalaxc.CUDA_ENABLED and torch.cuda.is_available()"
188188
pytest -v -m gpu tests/test_pyscf_skalaxc_gpu_parity.py
189189
190+
- name: Test installed CUDA binding and generated stubs
191+
run: |
192+
python -c "import skalaxc, torch, h5py, mypy; assert skalaxc.CUDA_ENABLED and skalaxc.HDF5_ENABLED and not skalaxc.MPI_ENABLED; assert torch.cuda.is_available(); assert skalaxc.PYTHON_LAYOUT == 'WHEEL'"
193+
python -m pytest -v -ra SkalaXC/python/tests --ignore=SkalaXC/python/tests/test_mpi.py
194+
190195
cuda-mpi-test:
191196
name: ${{ matrix.name }} MPI runtime
192197
runs-on: ${{ matrix.runner }}
@@ -257,3 +262,25 @@ jobs:
257262
-R '^skalaxc_unit_mpi\.(cuda_idle_rank|cuda_subcommunicator)$'
258263
--no-tests=error
259264
--output-on-failure
265+
266+
- name: Install CUDA MPI Python binding
267+
env:
268+
SkalaXC_DIR: ${{ github.workspace }}/SkalaXC/install-cuda-mpi-${{ matrix.version }}/lib/cmake/SkalaXC
269+
SKALAXC_PYTHON_LAYOUT: WHEEL
270+
run: |
271+
cmake --install SkalaXC/build-cuda-mpi-${{ matrix.version }} \
272+
--prefix SkalaXC/install-cuda-mpi-${{ matrix.version }} --component Core
273+
python -m pip install SkalaXC/python --no-build-isolation --no-deps --force-reinstall
274+
275+
- name: Test installed CUDA MPI binding and generated stubs
276+
run: |
277+
python -c "import skalaxc, torch, h5py, mypy; from mpi4py import MPI; assert skalaxc.MPI_ENABLED and skalaxc.CUDA_ENABLED and skalaxc.HDF5_ENABLED; assert torch.cuda.is_available(); assert skalaxc.PYTHON_LAYOUT == 'WHEEL'"
278+
python -m pytest -v -ra SkalaXC/python/tests --ignore=SkalaXC/python/tests/test_mpi.py
279+
mpiexec --oversubscribe -n 2 python -c "from mpi4py import MPI; assert MPI.COMM_WORLD.size == 2"
280+
mpiexec --oversubscribe -n 2 python -m pytest -v -ra SkalaXC/python/tests/test_mpi.py
281+
mpiexec --oversubscribe -n 3 python -c "from mpi4py import MPI; assert MPI.COMM_WORLD.size == 3"
282+
mpiexec --oversubscribe -n 3 python -m pytest -v -ra \
283+
SkalaXC/python/tests/test_cuda.py::test_cuda_uses_mpi_world_with_an_idle_domain_rank
284+
mpiexec --oversubscribe -n 4 python -c "from mpi4py import MPI; assert MPI.COMM_WORLD.size == 4"
285+
mpiexec --oversubscribe -n 4 python -m pytest -v -ra \
286+
SkalaXC/python/tests/test_cuda.py::test_cuda_uses_runtime_mpi_subcommunicator

‎.github/workflows/skalaxc-package.yml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,24 @@ jobs:
6565
if-no-files-found: error
6666

6767
cpu-package:
68-
name: CPU package (${{ matrix.target-platform }})
68+
name: CPU package (${{ matrix.target-platform }}, ${{ matrix.mpi }})
6969
runs-on: ${{ matrix.runner }}
7070
strategy:
7171
fail-fast: false
7272
matrix:
7373
include:
7474
- runner: ubuntu-latest
7575
target-platform: linux-64
76+
mpi: nompi
7677
- runner: ubuntu-24.04-arm
7778
target-platform: linux-aarch64
79+
mpi: nompi
7880
- runner: macos-14
7981
target-platform: osx-arm64
82+
mpi: nompi
83+
- runner: ubuntu-latest
84+
target-platform: linux-64
85+
mpi: openmpi
8086

8187
steps:
8288
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
@@ -93,7 +99,7 @@ jobs:
9399
rattler-build build
94100
--recipe SkalaXC/recipe/recipe.yaml
95101
--target-platform ${{ matrix.target-platform }}
96-
--variant mpi=nompi
102+
--variant mpi=${{ matrix.mpi }}
97103
--variant cuda=cpu
98104
--variant python=3.12
99105
--output-dir SkalaXC/output-packages
@@ -102,7 +108,7 @@ jobs:
102108
- name: Store CPU packages
103109
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
104110
with:
105-
name: skalaxc-${{ matrix.target-platform }}-cpu
111+
name: skalaxc-${{ matrix.target-platform }}-cpu-${{ matrix.mpi }}
106112
path: SkalaXC/output-packages/${{ matrix.target-platform }}/*.conda
107113
if-no-files-found: error
108114

‎SkalaXC/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ The Python binding releases the GIL during synchronous `eval_exc_vxc` and
177177
the same restriction applies to Python threads.
178178

179179
### 4. CUDA is optional and private
180+
181+
Device task tiles are bounded by the selected device's grid Y/Z launch limits
182+
before GauXC applies its memory-arena limit. This protects upstream collocation
183+
and density kernels as well as Skala feature/potential/gradient launches; the
184+
two independent limits can split a task sequence without dropping tasks.
185+
180186
`SKALAXC_ENABLE_CUDA` (**OFF** by default) builds a private device driver on
181187
GauXC's Scheme1 CUDA work engine. Collocation, density variables, AO assembly,
182188
Pulay terms, and partition-weight derivatives remain on the GPU. SkalaXC owns
@@ -379,6 +385,11 @@ builds select `cuda12` or `cuda13` while retaining `linux-64` as the target
379385
platform. `SkalaXC/pixi.toml` registers the package with the root Pixi workspace,
380386
so package builds and future Python tests share the root `pixi.lock` and environments.
381387

388+
Select `--variant mpi=openmpi` for MPI packages. The Python output declares
389+
`mpi4py >=4` for both building and execution and selects the Open MPI variant.
390+
Linux package CI builds this triplet and tests the installed binding with two
391+
ranks, including communicator ownership and subcommunicator evaluation.
392+
382393
### Querying the library version
383394

384395
The public APIs return the semantic version of the loaded SkalaXC library as a
@@ -408,6 +419,11 @@ assignment terminates with an ownership error. Transfer ownership explicitly
408419
with `call destination%move_from(source)`; the source becomes invalid and may
409420
be checked with `source%is_valid()`. Calling a creation method on an already
410421
valid handle replaces its object only after the new construction succeeds.
422+
Assignment rejection and finalization are impure elemental procedures, so
423+
these rules also apply to arrays of any rank. Transfer array elements
424+
individually with `move_from`; whole-array assignment is not an ownership
425+
transfer. Allocatable-array deallocation and scope exit finalize each live
426+
element exactly once.
411427

412428
For a CUDA build, select the architecture explicitly. For example, Blackwell
413429
(`sm_120`) with a CUDA-enabled LibTorch installation can be configured with:

‎SkalaXC/cmake/skalaxc-gauxc.cmake‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ else()
150150
CACHE PATH "Path to GauXC reference fixture directory" FORCE)
151151
endif()
152152

153+
# Keep the requested source path distinct from the acquired checkout.
154+
set(SKALAXC_GAUXC_RESOLVED_SOURCE_DIR "${_skalaxc_gauxc_source_dir}")
155+
153156
# The IntegratorXX revision pinned by GauXC uses std::back_inserter without
154157
# including <iterator>. libstdc++ currently exposes it transitively, but libc++
155158
# does not. Patch only the populated build-tree dependency until this is fixed

‎SkalaXC/examples/c/density_io.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef SKALAXC_EXAMPLE_DENSITY_IO_H
2+
#define SKALAXC_EXAMPLE_DENSITY_IO_H
3+
4+
#include <hdf5.h>
5+
#include <stdint.h>
6+
#include <stdio.h>
7+
8+
static int density_matrix_size(int64_t nbf, size_t* count) {
9+
if (nbf <= 0 || (uint64_t)nbf > SIZE_MAX ||
10+
(size_t)nbf > SIZE_MAX / (size_t)nbf / sizeof(double)) {
11+
fprintf(stderr, "Invalid or oversized density matrix dimension\n");
12+
return -1;
13+
}
14+
*count = (size_t)nbf * (size_t)nbf;
15+
return 0;
16+
}
17+
18+
static int read_density_matrix(hid_t file, const char* name, size_t nbf,
19+
double* buffer) {
20+
hid_t dataset = -1, file_space = -1, memory_space = -1;
21+
hsize_t dimensions[2];
22+
int result = -1;
23+
dataset = H5Dopen2(file, name, H5P_DEFAULT);
24+
if (dataset < 0) goto cleanup;
25+
file_space = H5Dget_space(dataset);
26+
if (file_space < 0) goto cleanup;
27+
if (H5Sget_simple_extent_ndims(file_space) != 2 ||
28+
H5Sget_simple_extent_dims(file_space, dimensions, NULL) < 0 ||
29+
dimensions[0] != nbf || dimensions[1] != nbf) {
30+
fprintf(stderr, "%s: expected density shape (%zu, %zu)\n", name, nbf, nbf);
31+
goto cleanup;
32+
}
33+
memory_space = H5Screate_simple(2, dimensions, NULL);
34+
if (memory_space < 0) goto cleanup;
35+
if (H5Dread(dataset, H5T_NATIVE_DOUBLE, memory_space, file_space, H5P_DEFAULT,
36+
buffer) < 0)
37+
goto cleanup;
38+
result = 0;
39+
40+
cleanup:
41+
if (memory_space >= 0) H5Sclose(memory_space);
42+
if (file_space >= 0) H5Sclose(file_space);
43+
if (dataset >= 0) H5Dclose(dataset);
44+
if (result != 0) fprintf(stderr, "HDF5 density read failed: %s\n", name);
45+
return result;
46+
}
47+
48+
#endif

‎SkalaXC/examples/c/skalaxc_eval.c‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525

26-
static int read_doubles(hid_t file, const char* dset, double* buf) {
27-
hid_t d = H5Dopen2(file, dset, H5P_DEFAULT);
28-
herr_t st;
29-
if (d < 0) return -1;
30-
st = H5Dread(d, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
31-
H5Dclose(d);
32-
return st < 0 ? -1 : 0;
33-
}
26+
#include "density_io.h"
3427

3528
int main(int argc, char** argv) {
3629
const char* path;
@@ -108,11 +101,7 @@ int main(int argc, char** argv) {
108101
goto fail;
109102

110103
nbf = skalaxc_xc_integrator_nbf(xc);
111-
if (nbf <= 0) {
112-
fprintf(stderr, "SkalaXC error: invalid nbf\n");
113-
goto cleanup;
114-
}
115-
n2 = (size_t)nbf * (size_t)nbf;
104+
if (density_matrix_size(nbf, &n2) != 0) goto cleanup;
116105
Ps = (double*)calloc(n2, sizeof(double));
117106
Pz = (double*)calloc(n2, sizeof(double));
118107
VXCs = (double*)calloc(n2, sizeof(double));
@@ -128,8 +117,8 @@ int main(int argc, char** argv) {
128117
fprintf(stderr, "H5Fopen failed\n");
129118
goto cleanup;
130119
}
131-
if (read_doubles(file, "/DENSITY_SCALAR", Ps) ||
132-
read_doubles(file, "/DENSITY_Z", Pz)) {
120+
if (read_density_matrix(file, "/DENSITY_SCALAR", (size_t)nbf, Ps) ||
121+
read_density_matrix(file, "/DENSITY_Z", (size_t)nbf, Pz)) {
133122
fprintf(stderr, "HDF5 read failed\n");
134123
H5Fclose(file);
135124
goto cleanup;

‎SkalaXC/python/README.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,22 @@ mypy tests/typing/interface.py tests/typing/cuda_mpi.py
136136

137137
The other build fixtures are `cpu.py`, `cuda.py`, and `mpi.py` in the same
138138
directory. Unused-ignore checking ensures each fixture also verifies that
139-
constructors unavailable in that build remain rejected.
139+
constructors unavailable in that build remain rejected.
140+
141+
## CI coverage
142+
143+
The native Linux release and MPI release jobs install this binding against
144+
their tested native installation and run the applicable full suite, including
145+
generated-stub checks. MPI-specific tests run on two ranks. CUDA runtime jobs
146+
test the installed CUDA binding; CUDA+MPI jobs additionally run the idle-rank
147+
and split-communicator tests on three and four ranks. Each job asserts native
148+
feature flags and dependencies before pytest, and reports executed and skipped
149+
tests with `-v -ra`. Single-process runs skip CUDA tests on CPU builds and
150+
multi-rank tests outside their required launch; dedicated launches cover those
151+
cases rather than treating those skips as coverage.
152+
153+
The root parity tests are optional in a Python-only checkout: a missing
154+
`skalaxc` installation is reported as a module-level skip. Native parity CI
155+
asserts the binding and backend features before pytest. Root test helpers use
156+
the unique `skalaxc_test_utils` module rather than a second `tests` package, so
157+
root and runtime suites can be collected together.

0 commit comments

Comments
 (0)