Repository navigation
A replay backend for the tests, and Dimer.from_backend: the SAPT core needs nothing beyond the backend contract - #15
Merged
Merged
Conversation
…eady The backend-neutral part of Dimer.__init__ (the SAPT arrays and the empty amplitude caches) moves into _setup(backend). __init__ still builds a Psi4Backend inside Psi4's timer, with the same output; from_backend takes any finished Backend, times the construction with the backend's own timer and sets no geometry string. The replay backend of the tests and later backends reach the SAPT code through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReplayBackend replays the arrays of a recorded RHF calculation and redoes only the operations of the contract in NumPy: J/K from Qpq (df_jk, now shared with matched_integrals) and the orbital-Hessian product from that J/K. It is a test double, not a backend option. no_psi4_calls makes every call into psi4.core and Psi4's driver fail, but print_out, which the package-wide log handler writes through. The session fixtures matched_psi4_dimer (Psi4's J/K fitted in the DF_BASIS_SAPT basis, options restored afterwards) and replay_dimer (Dimer.from_backend on its replay) set up the comparison. On He-H2 the J/K agree to 6e-13 and the Hessian products to 1.1e-10; the Hessian's symmetry is checked on Qpq symmetrized, as Psi4's is symmetric in p and q only to round-off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kend A dimer on the replay backend runs calc_sapt_energy (coupled and uncoupled), calc_property (the dipole and an AO matrix), calc_densities and the CPSCF solves with every call into Psi4 blocked, and matches the Psi4 dimer on the same fitted integrals: on He-H2 to 3e-15 in the energies, 5e-14 in the properties, 5e-13 in the induction amplitudes and 4.4e-11 in the AO density matrices. None of these calculations needed a change in the package. A test of the guard checks that it blocks Psi4 and gives it back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…support With the replay backend, the saving paths that read Psi4 objects of the dimer fail with the error of its Psi4 attributes: the bundle metadata and save_densities, the deprecated .npy matrices with their wavefunction files, the runner's monomer cubes and .fchk files, and the TREXIO export. Step 1.5 of the backend work moves them onto the backend; these tests record them until then. The replay also rejects RKS calculations and CPSCF J/K types, leaving the dimer's CPSCF state as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Step 1.4 of the backend work: check that propSAPT needs nothing from a backend beyond the contract of
prop_sapt/backends/base.py. Psi4 stays the only real backend. The check uses a replay backend, a test double intests/and not a backend option: it replays a recorded Psi4 RHF calculation and redoes only the contract's operations in NumPy.Dimer.from_backend(backend). A dimer of a backend calculation that has run already, such as aPsi4Backendbuilt beforehand. Later backends will reach the SAPT code the same way.Dimer.__init__(the SAPT arrays and the empty amplitude caches) moves into_setup(backend).Dimer(...)still builds aPsi4Backendinside Psi4's timer. Itsoutput.datmatchesmain's except for timings and date stamps.from_backendtimes the construction with the backend's owntimer()and sets nogeometrystring. It raises aTypeErrorfor anything that is not aBackend.tests/replay_backend.py).ReplayBackend.record(backend)copies every array of an RHF backend. It builds J/K fromQpq, and the orbital-Hessian product from that J/K:(eps_r - eps_a) x + C_occ^T (4J - K - K^T) C_vir, for the densityC_occ x C_vir^T. It rejects RKS, whose Hessian needs the XC kernel, and the CPSCF J/K types.df_jkintests/matched_integrals.py, whichdf_compute_jknow calls too.no_psi4_calls()makes every call intopsi4.coreand Psi4's driver fail inside its block. The exception ispsi4.core.print_out, which the package-wide log handler writes every record through, whatever the backend.matched_psi4_dimeris He–H2 withscf_type dfanddf_basis_scfset to theDF_BASIS_SAPTbasis, so Psi4's SCF, J/K andcphf_Hxall use the fitted integrals thatQpqfactors. It restores the two options afterwards.replay_dimerisDimer.from_backendon its replay.What it found:
calc_sapt_energy(coupled and uncoupled),calc_property(the dipole and an AO matrix),calc_densities,save_densities,.npymatrices with their wavefunction files,.fchkfiles,Qpqis symmetric in p and q only to round-off (8e-13 on He–H2). The diffuse virtual orbitals amplify that to about 2e-11 in the Hessian, by an amount that varies from run to run. The symmetry test therefore usesQpqsymmetrized; positive definiteness is checked on the recordedQpq.Out of scope (step 1.5): the analysis modules (
evaluate,partition,cubes,forces), the saving paths above, and the log handler'sprint_out.Tested:
New tests in
tests/test_replay_backend.py, against the matched Psi4 dimer on He–H2:cphf_Hxagainst DiskDFJK incompute_jk)Also new:
Dimer.from_backendreproduces a dimer's arrays and induction amplitudes without running an SCF, and rejects anything that is not aBackend.The full suite passes locally (612 passed, 2 skipped, 2 xfailed). The replay tests add about a minute, mostly one fixture that runs the full calculations on both dimers.
The docs build with
-W.output.datof a He–H2Dimer(...)(single-threaded) differs frommain's only in timings and date stamps.🤖 Generated with Claude Code