diff --git a/CHANGES.rst b/CHANGES.rst index 603b44cf1..981776940 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,9 @@ New Features Bug fixes --------- +- Fixed ``TimeInterpolatedPotential`` returning zero energy, gradient, and density + after being pickled or deep-copied. + - Fixed ``find_actions_o2gf()`` raising an error whenever any toy action or angle was NaN. NaN samples are now dropped with a warning, and it raises only if more than half of the samples are NaN. diff --git a/src/gala/potential/potential/builtin/cytimeinterp.pyx b/src/gala/potential/potential/builtin/cytimeinterp.pyx index 9b6df6398..2ba076175 100644 --- a/src/gala/potential/potential/builtin/cytimeinterp.pyx +++ b/src/gala/potential/potential/builtin/cytimeinterp.pyx @@ -283,7 +283,7 @@ cdef class TimeInterpolatedWrapper(CPotentialWrapper): self.interp_state.wrapped_potential = self.wrapped_potential.cpotential self.init( - [0.0], # value of G doesn't matter for this wrapper + [G], np.zeros(n_dim, dtype=np.float64), # placeholder origin np.eye(n_dim, dtype=np.float64), # placeholder rotation n_dim=n_dim diff --git a/tests/regression/test_potential_timeinterpolated_539.py b/tests/regression/test_potential_timeinterpolated_539.py index 6651b4375..2af24f3e6 100644 --- a/tests/regression/test_potential_timeinterpolated_539.py +++ b/tests/regression/test_potential_timeinterpolated_539.py @@ -23,4 +23,10 @@ def test_timeinterpolated_pickle(tmpdir): pickle.dump(pot, f) with open(tmpdir.join("time_interp_pot.pkl"), "rb") as f: - pot = pickle.load(f) + new_pot = pickle.load(f) + + q = [8.0, 1.0, 0.5] * u.kpc + for t in [0.0, 3.3, 10.0] * u.Gyr: + assert u.allclose(new_pot.energy(q, t=t), pot.energy(q, t=t)) + assert u.allclose(new_pot.gradient(q, t=t), pot.gradient(q, t=t)) + assert u.allclose(new_pot.density(q, t=t), pot.density(q, t=t))