Skip to content

Introduce standalone SkalaXC with ABI-isolated CPU, CUDA, MPI, and language bindings - #129

Closed
Jens (JensWehner) wants to merge 51 commits into
mainfrom
gauxc_migration
Closed

Jens (JensWehner) wants to merge 51 commits into
mainfrom
gauxc_migration

Conversation

@JensWehner

@JensWehner Jens (JensWehner) commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces SkalaXC, a standalone C++17 shared library for evaluating Skala exchange-correlation functionals. It reuses GauXC’s lower-level numerical infrastructure while keeping GauXC, LibTorch, Eigen, and other implementation dependencies behind a stable, ABI-isolated public boundary.

The change also replaces the previous GauXC integration examples and Python export tooling with maintained C++, C, Fortran, and Python SkalaXC interfaces, dedicated packaging, and comprehensive CI coverage.

Standalone SkalaXC library

  • Adds host-side UKS evaluation for:
    • XC energy
    • scalar and spin-density XC potentials
    • XC nuclear gradients
  • Loads and owns the selected TorchScript model for the lifetime of each integrator.
  • Uses GauXC’s grid, load-balancing, collocation, molecular-weight, and local-work infrastructure.
  • Keeps model features, derivative propagation, matrix assembly, and Skala-specific transformations within SkalaXC.

Public APIs and ABI isolation

  • Adds C++, C, and Fortran interfaces.
  • Adds a nanobind-based Python binding.
  • Keeps public matrices column-major and uses caller-owned output buffers at the C and Fortran boundaries.
  • Embeds private dependencies and restricts exported symbols through hidden visibility, linker export maps, and archive exclusion.

Host, MPI, and CUDA execution

  • Adds OpenMP-parallel host evaluation.
  • Assigns complete atomic grid domains to MPI ranks and performs only final result reductions.
  • Broadcasts model archive bytes from communicator rank zero so only that rank needs filesystem access to the model.
  • Adds optional CUDA kernels and device-side feature, potential, and gradient orchestration.

CUDA and host-compiler compatibility

  • Separates the CUDA build toolchains from unrestricted CPU toolchains.
  • Locks the currently validated combinations:
    • CUDA 12.8/12.9 with GCC 14
    • CUDA 13.x with GCC 15
    • CUDA 13.x with Clang 20
  • Constrains cuda-compiler to the same major family as the CUDA headers and runtime libraries, preventing mixed CUDA 12 headers with CUDA 13 nvcc.- Applies a temporary Clang compatibility patch to a generated build-tree copy of GauXC’s grid_to_center.cu, removing the C++17-invalid register specifier without modifying the pinned GauXC submodule.

Packaging and dependency management

  • Adds Pixi environments for host, MPI, CUDA 12, CUDA 13, Clang, packaging, and development tools.
  • Adds a Rattler Build split-package recipe producing:
    • libskalaxc
    • skalaxc-fortran
    • skalaxc-python
  • Keeps CUDA 12 and CUDA 13 in separate custom Pixi platform solutions.
  • Bundles the validated baseline and Skala model archives.
  • Adds relocatable CMake package metadata and separate core/full installation components.

Testing and CI

  • Adds Catch2 unit and integration coverage for:
    • model loading and reuse
    • host and CUDA evaluation
    • LDA, PBE, and TPSS behavior
    • matrix views and reordering
    • spin transformations
    • gradients
    • diagnostics
    • OpenMP stress behavior
    • MPI subcommunicators
  • Adds black-box C++, C, and Fortran API tests.
  • Adds CPU and GPU parity tests against the existing PySCF/GPU4PySCF implementations.
  • Adds ABI checks for exported symbols and public consumer dependencies.
  • Adds sanitizer, Clang release, clang-tidy, Doxygen, host, MPI, CUDA, and package workflows.

Documentation and examples

  • Adds comprehensive architecture, build, API, diagnostics, threading, MPI, CUDA, and packaging documentation.
  • Adds minimal public API examples for C++, C, and Fortran.
  • Updates the LibTorch and FTorch examples to use the revised model and interface contracts.
  • Updates repository-level installation and model-card references.

Legacy cleanup

  • Removes the old gauxc Python export package, duplicated GauXC documentation, and external integration examples.
  • Replaces the old GauXC example workflow with dedicated SkalaXC workflows.
  • Keeps GauXC as a pinned source-tree implementation dependency under SkalaXC rather than exposing or modifying GauXC’s public API.

@JensWehner
Jens (JensWehner) force-pushed the gauxc_migration branch 2 times, most recently from ef41033 to 5277ab5 Compare August 26, 2026 11:43
Base automatically changed from restructure to main August 27, 2026 07:22
@JensWehner Jens (JensWehner) changed the title Gauxc migration Introduce standalone SkalaXC with ABI-isolated CPU, CUDA, MPI, and language bindings Aug 28, 2026
Comment thread .github/workflows/pypi.yml Resolved
Comment thread SkalaXC/python/src/bindings/module.cxx Resolved
Comment thread SkalaXC/python/src/bindings/module.cxx Resolved
@JensWehner
Jens (JensWehner) force-pushed the gauxc_migration branch 2 times, most recently from 9e86ed9 to 7f4310f Compare September 4, 2026 14:40
@JensWehner
Jens (JensWehner) changed the base branch from main to model_chunking September 4, 2026 14:41
Base automatically changed from model_chunking to main September 9, 2026 11:35
Match both backends on the unpruned 75x302 FINE grid without changing parity tolerances. Validate GPU-side gradients on a 4 GiB device.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Offload saved backward tensors instead of reducing quadrature accuracy. Dense neural GPU gradients fit a 4 GiB device with 1198 MiB peak Torch allocation; preserve all parity tolerances.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run CPU MPI coverage on hosted Ubuntu and both CUDA families on the active small GPU pool. The pool's A10 driver supports CUDA 13; retain all compiler variants, runtime checks, and package tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid unavailable MANA RDMA via Open MPI self/TCP transport. Show formatter diffs in CI to diagnose changes introduced by PR merge commits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Retain main's postponed annotations and remove the now-redundant quoted union so the PR merge result passes Ruff.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pass the existing CUDA MPI oversubscription setting to host MPI configuration as well. Validated broadcast and reduction with three ranks on two declared slots.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@awvwgk

Copy link
Copy Markdown
Member

Aaron Kaplan (@esoteric-ephemera), Jan Hermann (@jhrmnn), shall we go ahead and merge this? We can iterate on main afterwards.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] Important CI gap — the new Python binding test suite is not executed

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Scope: SkalaXC/python/tests and the new SkalaXC CI workflow.

None of the checked-in workflows invokes pytest SkalaXC/python/tests/. The CPU/GPU parity workflows install the binding but run only the root parity tests. Native CTest, package import/pip-check smoke tests, and parity checks do not replace the binding suite's array/ownership/value validation, typing/stub checks, Torch configuration compatibility tests, or Python MPI behavior. The root pytest testpaths also do not include this suite. Thus all current checks can be green while these new binding-specific tests are failing.

Suggested fix:

  • After installing the binding against the exact native installation, run the full applicable Python binding suite in at least one required CPU job.
  • Add an MPI-enabled binding job that runs the Python MPI tests with the rank count/communicator setup they require.
  • Run CUDA-specific binding tests in the existing GPU job, and include generated-stub/type checks for supported feature variants.
  • Explicitly assert the expected native feature flags and required dependencies before running tests; do not allow a missing binding/backend to turn an intended coverage gate into skipped tests.

Further validation:

  • Record collected/executed/skipped test counts for CPU, MPI, and CUDA configurations and confirm skips are only for intentionally unavailable features.
  • Confirm the workflows trigger on binding, stub, native API, and dependency changes.
  • Include at least one installed-package execution so CI checks the distributed binding/assets rather than only an in-tree configuration.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P2 — New root test package breaks combined pytest collection

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Locations: tests/init.py, pyproject.toml, and tests/test_pyscf_skalaxc_parity.py.

Root tests and skala/tests now both resolve as the import package tests. With pytest's configured/default collection behavior, collecting these together can bind the root package first and then fail to import runtime tests.

Reproduction on the reviewed checkout:

python -m pytest --collect-only -q tests/test_package_metadata.py skala/tests/test_build_release.py

This fails with ModuleNotFoundError: No module named 'tests.test_build_release'. The corresponding combined test selection passed in the original checkout, and the PR selections pass when run separately.

There is also a related collection prerequisite: the root parity test unconditionally imports skalaxc, while the normal Python development environment does not automatically build/install that native binding. Its focused collection fails with ModuleNotFoundError: No module named 'skalaxc' in that environment.

Suggested fix:

  • Eliminate the duplicate import-package name, for example by moving shared parity support into a uniquely named support namespace and removing the new root tests package requirement.
  • Make the native-test prerequisite explicit. If ordinary Python-only runs should skip native parity tests, gate the optional import; dedicated native CI must explicitly assert the binding is installed so a missing build cannot silently become a green skip.

Further validation:

  • Add combined root/runtime collection to CI.
  • Check both the documented Python-only environment and the native parity environment, verifying intended skip versus execution behavior.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P2 — Native tests use the absent submodule path after GauXC FetchContent fallback

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Locations: SkalaXC/tests/CMakeLists.txt and SkalaXC/cmake/skalaxc-gauxc.cmake.

When the submodule is absent, dependency acquisition falls back to the pinned GauXC FetchContent checkout. However, the tests still use SKALAXC_GAUXC_SOURCE_DIR for the Gaussian basis parser source, include directory, and basis fixtures. That variable remains the original absent submodule path, rather than the fetched checkout. Consequently the fallback can acquire GauXC successfully but fail when generating/building native tests.

This is a static path-flow finding; a complete fallback build was not executed locally. Current native CI initializes submodules and therefore does not exercise the fallback.

Suggested fix:

  • Publish one resolved GauXC source directory for either acquisition route, while retaining the user-supplied source option separately if needed.
  • Use the resolved directory consistently for parser sources, includes, and basis fixtures, as already done for the resolved reference-data directory.

Further validation:

  • Configure/build with SKALAXC_BUILD_TESTS=ON from a checkout or source archive without an initialized GauXC submodule.
  • Exercise the normal submodule path and explicit source-directory override too, confirming all routes use the intended pinned/source tree.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P2 — MPI Python package variants do not declare their mpi4py dependency

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Locations: SkalaXC/recipe/recipe.yaml and SkalaXC/python/CMakeLists.txt.

The split recipe advertises mpi=nompi and mpi=openmpi, but skalaxc-python declares no mpi4py dependency in either its host or run requirements. MPI-enabled binding configuration explicitly imports mpi4py to locate its headers and fails if unavailable. The Python MPI interface also needs it at runtime. The optional pip extra does not install it for the recipe's --no-deps build.

This is a declared-dependency/build-contract finding; a full clean MPI package build was not run locally. Current package CI explicitly selects mpi=nompi, so successful package checks do not exercise this combination.

Suggested fix:

  • Add conditional mpi4py >=4 host and run requirements for MPI-enabled Python outputs.
  • Ensure mpi4py and the native library use the same MPI implementation/compatible variant.

Further validation:

  • Build and install at least one mpi=openmpi,cuda=cpu split-package combination in a clean environment.
  • Import the installed binding and execute a two-rank Python evaluation/subcommunicator test.
  • Add this representative MPI package combination to CI rather than relying only on render-only matrix checks.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P1 — Fortran handle arrays bypass ownership safeguards

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Location: SkalaXC/src/fortran/skalaxc.F90, and the corresponding assignment/finalization procedures for all eight handle types.

The assignment-rejection procedures and finalizers are scalar and non-elemental. They do not cover whole-array operands: array assignment falls back to intrinsic assignment, copying the c_ptr components, and array destruction does not invoke these scalar finalizers elementwise. Recreating/destroying a source element can leave a destination alias dangling; deallocating handle arrays can leak their owned native objects.

Evidence: a standalone GNU Fortran 15 reproduction of these procedure shapes produced zero defined-assignment calls, aliased pointers after whole-array assignment, and zero finalizer calls after array deallocation. This validates the language behavior, not an end-to-end SkalaXC use-after-free execution. Existing assignment tests cover scalar handles.

Suggested fix:

  • Provide array-capable assignment rejection and destruction for every owning handle type, using appropriate impure-elemental procedures or explicit rank-specific procedures.
  • Keep ownership transfer explicit through move_from; do not make pointer-copy assignment appear safe.

Further validation:

  • Test rank-one and rank-two arrays, allocatable-array deallocation, and scope exit.
  • Verify that forbidden whole-array assignment fails with the documented diagnostic.
  • Verify that each live native object is destroyed exactly once, including after element-level ownership transfers.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P2 — CUDA task tiles need a launch-dimension cap as well as a memory cap

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Location: SkalaXC/src/device/cuda/kernels/model_grid.cu, with equivalent task-count dimensions in potential/weight-derivative/VXC launches and upstream collocation/U-variable kernels.

Task count is used as CUDA grid dimension Y or Z. The driver passes remaining tasks to GauXC's memory-based buffer generation, which has no corresponding task-count cap. A sufficiently large tile can therefore fit in memory but exceed the device's launch limit and fail with an invalid launch configuration.

Evidence: the available A100 reports Y/Z limits of 65,535; focused in-memory CUDA launches accepted 65,535 and rejected 65,536. Inspection of the pinned GauXC tiling implementation showed a memory-based stopping condition without this task cap. A complete large-molecule SkalaXC reproduction was not run, so the finding is conditional on a tile reaching that size.

Suggested fix:

  • Bound task tiles by the relevant device launch limits before buffer generation/collocation, not just inside the later Skala-specific kernels.
  • Alternatively redesign the affected launches to flatten task indexing, while also handling upstream kernels consistently.

Further validation:

  • Test tiles immediately below, at, and above the limit, with enough memory that task count is the limiting factor.
  • Check energy/potential/gradient equivalence after splitting and ensure every task is processed exactly once.
  • Include low-memory and many-small-task cases to exercise both independent limits.

@esoteric-ephemera

Copy link
Copy Markdown
Contributor

[agent] P2 — C example can read an oversized HDF5 dataset past its density allocation

Reviewed revision: 341b79bbff5a644c8215c345f59bb15f6ea900fc.
Location: SkalaXC/examples/c/skalaxc_eval.c.

The example allocates density buffers using nbf * nbf, but its reader calls H5Dread with H5S_ALL for both dataspaces and does not validate dataset extents. A density dataset larger than the basis-derived allocation therefore writes beyond that allocation before integrator input validation can help. This finding concerns the example, not the core integrator.

Evidence: a focused HDF5 runtime reproduction read eight dataset elements into a logical four-element output followed by four allocated guard slots. The read returned success and overwrote all four guards; no actual out-of-allocation write was needed to demonstrate the capacity mismatch.

Suggested fix:

  • Pass the expected dimensions/capacity into the reader.
  • Query and validate dataset rank and extents against the documented density-matrix shape before reading.
  • Supply an explicit matching memory dataspace, check size arithmetic, and close all HDF5 handles on error.

Further validation:

  • Exercise both scalar and spin-density reads with correctly shaped, oversized, undersized, and wrong-rank datasets.
  • Require a clear failure diagnostic for invalid shapes and run the malformed-input cases under ASan where available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit hard to review when the diff is so huge, but can we address a few cycles of agentic review and then merge? Would want to make sure basic functionality is integrated + tested

Preserve GPU-first documentation and D3 scanner fixes alongside SkalaXC setup instructions. All 150 class tests pass; local CuPy reports an unraisable allocator teardown warning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Use the declared OpenBLAS provider at build and runtime instead of accidentally linking transitive MKL. Preserve scanner energy/gradient accuracy assertions and orbital-gradient convergence while allowing float32 energy noise.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Test LDA/PBE gradients and TPSS energy/potentials across both batch modes, matching the documented native TensorExpr limitation. Include and explicitly select the binding pytest configuration in conda tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Disable pytest-randomly for multi-rank launches after CUDA13 CI showed different per-rank seeds entering incompatible collectives. Retain randomized serial coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fail collective-test hangs promptly instead of consuming the six-hour job limit. Retry CUDA12 MPI after its runner exhausted disk space during compilation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JensWehner

Copy link
Copy Markdown
Contributor Author

Sebastian Ehlert (@awvwgk) feel free to close this one then, thanks for splitting it up into individual ones and improving the conda handling + documentation upgrade. Looks much better.

@awvwgk

Copy link
Copy Markdown
Member

Continuing this in #155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants