Repository navigation
Add analytic nuclear gradients for ROHF-CASCI and GBCI - #208
Conversation
| self.assertAlmostEqual( | ||
| float(grad[0, 2]), LIF_TRIPLET_ROHF_GRAD_Z, 9) | ||
| self.assert_response( | ||
| bath_response_norm, LIF_TRIPLET_ROHF_BATH_RESPONSE_NORM, places=9) |
There was a problem hiding this comment.
Are some of these tolerances too tight? On my laptop:
(pyscf) herme068@herme068:test$ pytest test_gbci_grad.py
======================================================== test session starts ========================================================
platform linux -- Python 3.12.7, pytest-9.0.2, pluggy-1.5.0
rootdir: /home/herme068/gits/pyscf_ext/pyscf-forge
configfile: pyproject.toml
plugins: anyio-4.6.2
collected 4 items
test_gbci_grad.py .F.. [100%]
============================================================= FAILURES ==============================================================
______________________________________________ KnownValues.test_lif_triplet_rohf_4o4e _______________________________________________
self = <test_gbci_grad.KnownValues testMethod=test_lif_triplet_rohf_4o4e>
def test_lif_triplet_rohf_4o4e(self):
grad, bath_response_norm, rohf_response_fp = get_gbci_grad(
f"Li 0 0 0; F 0 0 {BOND_LENGTH}", 4, (2, 2),
spin=2, mf_cls=scf.ROHF)
self.assertAlmostEqual(
float(grad[0, 2]), LIF_TRIPLET_ROHF_GRAD_Z, 9)
> self.assert_response(
bath_response_norm, LIF_TRIPLET_ROHF_BATH_RESPONSE_NORM, places=9)
test_gbci_grad.py:155:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_gbci_grad.py:121: in assert_response
self.assertAlmostEqual(value, ref, places)
E AssertionError: 0.008977610258204424 != 0.008977611205020856 within 9 places (9.468164325482364e-10 difference)
====================================================== short test summary info ======================================================
FAILED test_gbci_grad.py::KnownValues::test_lif_triplet_rohf_4o4e - AssertionError: 0.008977610258204424 != 0.008977611205020856 within 9 places (9.468164325482364e-10 difference)
There was a problem hiding this comment.
and it looks like the next assert after this (that my laptop didn't get to) consistently fails outright in the github actions, so there's clearly something wrong with this test
There was a problem hiding this comment.
Thank you for your comments. Previously, I tested the intermediate Z-vectors against reference values obtained using lib.fp. However, I found that these values are sensitive to the orbital gauge, which can lead to spurious CI failures even when the solutions are physically equivalent. I therefore replaced these checks with comparisons of the Z-vector norms, which are more robust to orbital-gauge changes. This resolved the gauge-related CI failures.
Summary
This PR adds analytic nuclear-gradient implementations for both ROHF-CASCI and grouped-bath configuration interaction (GBCI).
The ROHF-CASCI implementation provides the orbital-response framework required for CASCI calculations based on ROHF orbitals. This framework is further extended to ROHF-based GBCI calculations, including the additional response contributions arising from group-dependent bath-orbital relaxation.
Main changes
ROHF-CASCI gradients
pyscf/grad/rohf_casci.pyGBCI gradients
pyscf/grad/gbci.pypyscf/grad/rohf_gbci.pyGBCI interface and solver updates
pyscf/gbci/gbci.pynuc_grad_method()to the GBCI interface.pyscf/gbci/fasscf.pypyscf/gbci/direct_gbci.pyTests and examples
pyscf/grad/test/test_gbci_grad.pyexamples/grad/30-gbci_gradient.pypyscf/gbci/test/test_msgbpdft.pyUsage
Reference