From b4e20697daeb2cef6d063a31f9e7156e7feb6f3f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen <pauli.t.virtanen@jyu.fi> Date: Wed, 21 Sep 2022 16:00:27 +0300 Subject: [PATCH] tests: check also grad in gauge-invariance test --- tests/test_basic.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index cf7cffa..caded57 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -201,3 +201,12 @@ def test_gauge_invariance(omega, use_numdifftools): D = numdifftools.Derivative(S_s) dS_ds = D(0.0) / 16 assert_allclose(div_J, dS_ds, rtol=1e-12) + + # The derivative must also match the gradient + dS_dPhi = s._core.grad(Phi).reshape(Phi.shape) + dPhi = 0 * Phi + dPhi[i, j, 0] = 2 * Phi[i, j, 0] + dPhi[i, j, 1] = -2 * Phi[i, j, 1] + dS_ds2 = (dS_dPhi * dPhi).sum() / 16 + + assert_allclose(div_J, dS_ds2, rtol=1e-12) -- GitLab