Improve Vxc Screening - #100
Draft
Jens (JensWehner) wants to merge 22 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces global spatial AO screening for Skala’s PySCF and GPU4PySCF integrations, evaluating AO-derived features in spatially grouped blocks (with atom-major restoration) and using chunk-local autograd plus blockwise VJP/JVP to bound memory while preserving a dense fallback.
Changes:
- Add a global screened feature-evaluation path (spatial grid sorting + blockwise AO screening) for first- and second-order XC / response computations.
- Update memory estimation to account for full-grid raw-feature/cotangent buffers and add targeted unit tests for the estimators.
- Expand CPU/GPU test coverage for screening decisions, ordering/permutations, dense-vs-screened equivalence, and profiling/benchmark harnesses (with new pytest markers/deps).
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_memory_estimators.py | Adds unit tests for the new global raw-feature buffer memory estimator and reserved-memory chunk sizing. |
| tests/test_gpu4pyscf_gradients.py | Extends GPU gradient tests to compare CPU/GPU and dense/screened routes against stored references. |
| tests/test_gpu4pyscf_classes.py | Marks GPU4PySCF class tests with a GPU marker and adjusts import ordering for CUDA gating. |
| tests/test_gpu4pyscf_ao_screening.py | Adds GPU-focused AO screening tests covering sorting, response equivalence, masking/scatter, and CPU-vs-GPU validation. |
| tests/test_ao_screening.py | Adds CPU AO screening tests for screening decisions, permutations, masking behavior, and screened response correctness. |
| tests/test_ao_screening_benchmark.py | Adds benchmark/profiling tests to compare screened vs dense runtime and peak memory (CPU + CUDA). |
| src/skala/pyscf/numint.py | Switches atom-chunked path to global screened evaluation, adds _should_screen_aos, and updates response/HVP logic accordingly. |
| src/skala/pyscf/memory_estimators.py | Adds reserved-memory support and a new estimator for global raw-feature buffer storage. |
| src/skala/pyscf/gradients.py | Minor dict-comprehension cleanup while building gradient feature dictionaries. |
| src/skala/pyscf/features.py | Adds spatial grid ordering, caching, AO screening block loop helpers, and global screened feature evaluation machinery. |
| src/skala/pyscf/backend.py | Reorders/cleans __all__ exports. |
| src/skala/gpu4pyscf/gradients.py | Minor dict-comprehension cleanup mirroring the CPU gradients module. |
| src/skala/functional/utils/irreps.py | Reorders __slots__ entries. |
| src/skala/functional/load.py | Simplifies all(...) checks (removes unnecessary list creation). |
| src/skala/functional/init.py | Reorders __all__ exports. |
| src/skala/ase/init.py | Removes a now-redundant # noqa: F401 from the Skala export. |
| pyproject.toml | Adds pytest timeout/addopts/markers and new dev dependencies (benchmark/timeout/memray). |
| environment-gpu.yml | Adds pytest-benchmark and pytest-timeout to the GPU development/test environment. |
| environment-cpu.yml | Adds pytest-benchmark and pytest-timeout to the CPU development/test environment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Jens (JensWehner)
force-pushed
the
screening
branch
from
August 5, 2026 14:35
9aca3f7 to
60385d5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
src/skala/pyscf/xc_integrator.py:292
sorted_raw_features(and the model-chunk raw features derived from it) are computed fromdm0.double(), butscreened_feature_jvp()is called withdm0/dm1directly. Ifdm0/dm1are not float64 this will produce a tangent with a different dtype thanlocal_raw_features, and the subsequenttorch.autograd.grad(..., grad_outputs=atom_major_tangent[...])will error due to dtype mismatch.
atom_major_tangent = screened_feature_jvp(
dm0,
dm1,
mol,
spatial_grid_layout,
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch changes compared with main
This summary compares the current
screeningbranch withorigin/main. The localmainbranch is one commit behindorigin/main; using it literally would also includean unrelated upstream allocator commit. Uncommitted files are excluded.
Automatic AO screening for large systems
XC evaluation now switches from dense AO contractions to screened contractions when
the functional supports atom-aligned grids and
mol.nao_nr()exceeds PySCF'sSWITCH_SIZE. Smaller systems and unsupported functionals retain the dense path.Spatially localized integration grids
Grid points are recursively grouped into spatial blocks so each block touches fewer
basis functions. Forward and inverse permutations restore the atom-major ordering
expected by Skala.
Reusable, backend-aware screening metadata
A
SpatialGridLayoutis cached on the original grid and shared acrossSkalaNumIntinstances. CPU evaluation rebuilds PySCF shell masks, while GPU evaluation invalidates
GPU4PySCF's AO-index cache for the reordered grid.
Sparse blockwise AO autograd
New custom PyTorch autograd functions evaluate only active AO submatrices and scatter
derivatives back into full density-matrix shapes. They handle CPU shell masks, GPU AO
sorting, empty blocks, VJPs, JVPs, and higher-order differentiation.
Screened energy and potential integration
The screened first-order path evaluates raw AO features globally once, processes the
neural functional in memory-sized atom chunks, collects feature cotangents, and
performs one final sparse VJP to obtain the XC potential.
Screened response and Hessian-vector products
Response evaluation computes a screened feature JVP, chunk-local model Hessian
actions, and a final sparse AO VJP.
XCIntegratorreturns the XC-only response, whileSkalaNumIntadds the Coulomb response required by PySCF.AO traversal and model chunking are decoupled
AO screening traverses the spatial grid independently of neural-model batching. Model
chunks preserve complete atomic grids and are sized using available memory after
reserving space for global feature and cotangent buffers.
PySCF integration is split into focused modules
The former large
features.pymodule is now a thin public feature generator. Featurepolicy, feature mathematics, AO evaluation, screening, model chunking, and XC
integration have separate owners;
SkalaNumIntprimarily adapts NumPy and CuPy datato Torch.
Feature support is deliberately narrowed
The unsupported nonlinear kinetic-tensor features
ked_varandked_detwereremoved. Screened raw features are restricted to density-matrix-linear meta-GGA
quantities:
density,grad,kin, andlapl. Directsecond_order=Truecalls nowraise an error in favor of
gen_response().Correctness and performance coverage is substantially expanded
New tests compare dense and screened CPU/GPU results for RKS, UKS, the XC potential,
response/HVP, sparse and empty AO blocks, and nuclear gradients. Benchmark
infrastructure measures runtime and peak memory, with
pytest-benchmark,pytest-timeout, Memray support, and dedicated benchmark, GPU, and profiling markers.