Optimize MP2 with blocked AO-to-MO contractions - #74
Merged
Merged
Conversation
mveril
force-pushed
the
perf/blocked-ao-to-mo-mp2
branch
from
September 16, 2026 19:13
5f29cf2 to
e6459ad
Compare
mveril
force-pushed
the
perf/blocked-ao-to-mo-mp2
branch
2 times, most recently
from
September 17, 2026 07:29
5f9c1e0 to
40bca14
Compare
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.
The previous MP2 implementation expanded a dense AO-pair matrix and retained complete occupied/virtual MO tensors. Replace it for RHF and UHF with four successive contractions blocked over active occupied orbitals, accumulating each block's energy immediately.
Add
[mp2] memory_limit = "auto"(default) or explicit sizes such as"512 MiB". Automatic selection uses half of available system memory, with correct KiB conversion and a 512 MiB fallback. Preserve automatic/fixed selection in the Rust API and round-trip explicit sizes without losing integer bytes. Text reports include the chosen block, workspace budget, dense-method upper bound, and resident inputs; JSON schema v1 is unchanged.The budget covers owned matrix payloads, including coefficient copies and panels. It excludes existing HF data, allocator overhead and matrix-kernel scratch storage, so it is not an RSS limit. Tiny budgets fail with a located, typed error before transformation allocation. Adding the configuration field requires Rust struct literals to specify it or use
..Default::default().Validation:
cargo test --workspace --locked --offline, followed by the focused MP2 suite after final adjustments.cargo test --workspace --no-default-features --locked --offline.cargo clippy --workspace --all-targets --all-features --locked --offline -- -D warnings.cargo fmt --all -- --check, Ruff checks and formatting checks for the reference tooling.pytest tools/referenceagainst the built binary: 17 passed, including 8 MP2 comparisons. New frozen-core H₂O/6-31G and OH/STO-3G cases cover small and large budgets.Synthetic RHF release benchmark, four Rayon threads, median of three runs after warm-up; input/ERI construction and SCF are excluded:
With a 4 MiB budget, the 48-AO case selects three occupied orbitals per block and uses 3.4 MiB of matrix payload, but takes about 182 ms. Small blocks trade speed for memory by repeating AO reads. These synthetic results are machine-dependent, not a speed guarantee for molecular calculations.
Run
cargo bench --bench mp2_timings --features bench-support;RUSTIQ_MP2_MEMORY,RUSTIQ_MP2_SIZES, andRAYON_NUM_THREADSselect the budget, dimensions and thread count.