Skip to content

Commit bb748b4

Browse files
committed
mcscf: stabilize N2 state-average energy regression
1 parent 1ec5d4f commit bb748b4

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎pyscf/mcscf/test/test_gasscf.py‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,14 +1360,33 @@ def test_n2_numerical_regression_state_average(self):
13601360
mc.fcisolver.spin = 0
13611361
mc.fcisolver.max_cycle = 300
13621362
mc.fcisolver.max_space = 30
1363-
mc.fcisolver.conv_tol = 1e-10
1364-
e_tot = float(mc.kernel(mo)[0])
1363+
self.addCleanup(mc.close)
1364+
# This is an energy regression at 1e-7 Eh, not a test of a particular
1365+
# Newton trajectory. Tighter outer thresholds can linger in a noisy
1366+
# SA tail and occasionally exhaust the macro limit across platforms.
1367+
# Keep the CI residual well below the orbital stopping threshold;
1368+
# Davidson otherwise defaults to sqrt(conv_tol) for its residual.
1369+
mc.conv_tol = 1e-9
1370+
mc.conv_tol_grad = 1e-4
1371+
mc.fcisolver.conv_tol = 1e-12
1372+
mc.fcisolver.conv_tol_residual = 1e-7
1373+
progress = {}
1374+
1375+
def record_progress(env):
1376+
for key in ('imacro', 'de', 'norm_gall'):
1377+
progress[key] = env[key]
1378+
1379+
e_tot = float(mc.kernel(mo, callback=record_progress)[0])
13651380
weighted = float(numpy.dot(
13661381
numpy.asarray(mc.weights, dtype=float),
13671382
numpy.asarray(mc.e_states, dtype=float),
13681383
))
13691384

1370-
self.assertTrue(mc.converged)
1385+
self.assertTrue(mc.converged,
1386+
"N2 SA failed to converge: E=%.15f, last macro=%s" %
1387+
(e_tot, progress))
1388+
self.assertTrue(numpy.all(mc.fcisolver.converged),
1389+
"N2 SA final CI roots did not converge")
13711390
self.assertAlmostEqual(
13721391
e_tot, self.N2_REF_SA_HALF_HALF_ENERGY,
13731392
delta=self.N2_REGRESSION_TOL)

0 commit comments

Comments
 (0)