Skip to content

Fix TimeInterpolatedPotential evaluating to zero after pickling - #663

Draft
Mohit-Ak wants to merge 1 commit into
adrn:mainfrom
Mohit-Ak:fix/timeinterp-pickle-G
Draft

Mohit-Ak wants to merge 1 commit into
adrn:mainfrom
Mohit-Ak:fix/timeinterp-pickle-G

Conversation

@Mohit-Ak

Copy link
Copy Markdown

Pickling or deep-copying a TimeInterpolatedPotential gave back a potential whose energy, gradient and density were all zero.

TimeInterpolatedWrapper called self.init([0.0], ...), and __reduce__ passes self._params[0] back as G. So the rebuilt wrapper set up its interpolation state with G = 0. This change passes the real G to init(). The time_interp_* C functions never read pars, so nothing changes for a potential that was not pickled.

Tested:

  • test_potential_timeinterpolated_539.py now compares energy, gradient and density before and after unpickling. On main it fails (0. vs -0.0189); with this change it passes.
  • I also checked pickle and deepcopy by hand for Kepler (interpolated m), Hernquist (m, c, moving origin), SCF, and inside CompositePotential/CCompositePotential.
  • The full tests/ suite (benchmarks excluded) passes locally with GSL 2.8.

Fixes #542

TimeInterpolatedWrapper stored 0.0 as G in _params, and __reduce__
passes _params[0] back as G, so the unpickled wrapper interpolated
with G = 0. Pass the real G to init().

Fixes adrn#542

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential bug with pickling/unpickling TimeInterpolatedPotential

1 participant