Skip to content

[PR-6] feat: implement Schwarz screening for two-electron integral optimization#240

Draft
San1357 wants to merge 11 commits intotheochem:masterfrom
San1357:feat/schwarz-screening
Draft

[PR-6] feat: implement Schwarz screening for two-electron integral optimization#240
San1357 wants to merge 11 commits intotheochem:masterfrom
San1357:feat/schwarz-screening

Conversation

@San1357
Copy link

@San1357 San1357 commented Mar 8, 2026

Summary

What Changed

File Lines What
gbasis/integrals/_schwarz_screening.py +218 New module: compute_schwarz_bound_shell_pair, compute_schwarz_bounds, shell_pair_significant, SchwarzScreener class with is_significant() and get_statistics()
gbasis/integrals/electron_repulsion.py +67 Added _screener and _contraction_index_map class attributes to ElectronRepulsionIntegralImproved, Schwarz screening block in construct_array_contraction, schwarz_threshold parameter in electron_repulsion_integral_improved()
tests/test_schwarz_screening.py +460 23 tests: TestShellPairPrescreening, TestSchwarzBounds, TestSchwarzScreener, TestScreeningCorrectness, TestBenchmarkImprovedAlgorithm
tests/test_two_elec_int_improved.py +83 Added TestSchwarzScreening class: test_schwarz_no_effect, test_schwarz_screening_tight, test_schwarz_statistics

Mathematical Reference

The Schwarz inequality for electron repulsion integrals:

$$|(\mu\nu|\lambda\sigma)| \leq \sqrt{(\mu\nu|\mu\nu)} \cdot \sqrt{(\lambda\sigma|\lambda\sigma)}$$

If $\sqrt{(\mu\nu|\mu\nu)} \cdot \sqrt{(\lambda\sigma|\lambda\sigma)} < \tau$, the quartet $(\mu\nu|\lambda\sigma)$ is skipped.

Shell-pair prescreening uses the Gaussian product decay factor:

$$\exp\left(-\frac{ab}{a+b}|\mathbf{A}-\mathbf{B}|^2\right)$$

References:

  • Häser, M. & Ahlrichs, R. J. Comput. Chem. 1989, 10, 104.
  • Gill, P. M. W.; Johnson, B. G.; Pople, J. A. Int. J. Quantum Chem. 1991, 40, 745.

How To Test

# Schwarz screening unit tests
python -m pytest tests/test_schwarz_screening.py -v

# Integration tests (includes TestSchwarzScreening)
python -m pytest tests/test_two_elec_int_improved.py -v

# All 44 tests together
python -m pytest tests/test_schwarz_screening.py tests/test_two_elec_int_improved.py -v

# Coverage
python -m pytest tests/test_schwarz_screening.py tests/test_two_elec_int_improved.py --cov=gbasis/integrals --cov-report=term-missing

Proof That It Works

Unit tests (SchwarzScreener)

image

Integration tests (screening inside ERI computation)

image

All 44 tests

image

Coverage

image

black & ruff

image

First Checklist

  • ✅ Tests added for each new function
  • ✅ All 44 tests pass
  • ✅ Black formatted
  • ✅ Ruff linting clean
  • ✅ Existing tests not broken
  • ✅ Docstrings in numpydoc format
  • ✅ No new dependencies added (uses existing numpy)
  • ✅ Pure Python only (no C/Fortran)

Scope Of this PR

  • Implements Schwarz screening as optional optimization for electron_repulsion_integral_improved()
  • Adds SchwarzScreener class with precomputed bounds matrix and statistics tracking
  • Does not modify existing electron_repulsion_integral() — only improved version gets screening
  • Screening is opt-in via schwarz_threshold parameter — default 0.0 disables it (backward compatible)
  • Week 7 deliverable building on OS+HGP pipeline (PR [PR-5] feat: integrate OS+HGP algorithm into electron_repulsion module #239)

Second Checklist

  • ✅ Write a good description of what the PR does.
  • ✅ Add tests for each unit of code added (e.g. function, class)
  • ☐ Update documentation
  • ☐ Squash commits that can be grouped together
  • ☐ Rebase onto master

Type of Changes

Type Checked
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

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.

1 participant