From 4d410bae4718847d3081641887a5fa830bcfd4eb Mon Sep 17 00:00:00 2001 From: Joachim Moeyens Date: Thu, 23 Jan 2025 18:11:51 -0800 Subject: [PATCH 1/2] Add failing test --- tests/test_propagate.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_propagate.py b/tests/test_propagate.py index 02c3276..fb2dc9a 100644 --- a/tests/test_propagate.py +++ b/tests/test_propagate.py @@ -6,6 +6,7 @@ from adam_core.coordinates.residuals import Residuals from adam_core.orbits import Orbits from adam_core.orbits.query.horizons import query_horizons +from adam_core.orbits.query import query_sbdb from adam_core.time import Timestamp from astropy import units as u @@ -208,4 +209,26 @@ def test_propagate_different_input_times(mocker): assert watched_propagate_orbits_inner.call_count == 2, "Inner function should be called once for each unique input epoch" assert len(propagated_orbits.coordinates.time.unique()) == 2 - assert len(propagated_orbits) == 8, "Should have input orbits x epochs number of results" \ No newline at end of file + assert len(propagated_orbits) == 8, "Should have input orbits x epochs number of results" + + +def test_back_to_back_propagations(): + """ + Ensure that back-to-back multiprocessed propagations work. This test should + fail at the moment since the ray remote cannot initialize a propagator object with an already + defined simulation. + + """ + prop = ASSISTPropagator() + orbits = query_sbdb(["2013 RR165"]) + + time = Timestamp.from_mjd([60000], scale="tdb") + first_prop = prop.propagate_orbits(orbits, time, max_processes=1) + + # This doesn't work (which is problematic here: https://github.com/B612-Asteroid-Institute/adam_core/blob/main/src/adam_core/propagator/propagator.py#L554-L555) + first_dict = first_prop.__dict__ + second_prop = ASSISTPropagator(**first_dict) + + # This works + first_dict.pop("_last_simulation") + third_prop = ASSISTPropagator(**first_dict) \ No newline at end of file From 416f0bb73bc1cc9520263f5b9069f53ee61aeeca Mon Sep 17 00:00:00 2001 From: Alec Koumjian Date: Fri, 24 Jan 2025 10:21:59 -0500 Subject: [PATCH 2/2] Uses new serialization in adam-core --- pyproject.toml | 4 ++-- src/adam_assist/propagator.py | 8 ++++++++ tests/test_propagate.py | 11 ++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d8f8581..769c44b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Astronomy" ] -requires-python = ">=3.10,<4.0" +requires-python = ">=3.11,<3.13" dependencies = [ "adam-core>=0.2.5", "naif-de440", @@ -57,7 +57,7 @@ dev = [ "pytest-benchmark", "black", "isort", - "ipython" + "ipython", ] [tool.pdm.scripts] diff --git a/src/adam_assist/propagator.py b/src/adam_assist/propagator.py index 13f5e97..a143d94 100644 --- a/src/adam_assist/propagator.py +++ b/src/adam_assist/propagator.py @@ -81,6 +81,14 @@ def __init__( self.adaptive_mode = adaptive_mode self.epsilon = epsilon + def __getstate__(self): + state = self.__dict__.copy() + state.pop("_last_simulation", None) + return state + + def __setstate__(self, state): + self.__dict__.update(state) + def _propagate_orbits(self, orbits: OrbitType, times: TimestampType) -> OrbitType: """ Propagate the orbits to the specified times. diff --git a/tests/test_propagate.py b/tests/test_propagate.py index fb2dc9a..09d6c35 100644 --- a/tests/test_propagate.py +++ b/tests/test_propagate.py @@ -5,8 +5,8 @@ from adam_core.coordinates import CartesianCoordinates, Origin from adam_core.coordinates.residuals import Residuals from adam_core.orbits import Orbits -from adam_core.orbits.query.horizons import query_horizons from adam_core.orbits.query import query_sbdb +from adam_core.orbits.query.horizons import query_horizons from adam_core.time import Timestamp from astropy import units as u @@ -225,10 +225,7 @@ def test_back_to_back_propagations(): time = Timestamp.from_mjd([60000], scale="tdb") first_prop = prop.propagate_orbits(orbits, time, max_processes=1) - # This doesn't work (which is problematic here: https://github.com/B612-Asteroid-Institute/adam_core/blob/main/src/adam_core/propagator/propagator.py#L554-L555) - first_dict = first_prop.__dict__ + # Propagator has to be pickleable, which uses __getstate__ and __setstate__ + # This doesn't work if _last_simulation is in the state + first_dict = prop.__getstate__() second_prop = ASSISTPropagator(**first_dict) - - # This works - first_dict.pop("_last_simulation") - third_prop = ASSISTPropagator(**first_dict) \ No newline at end of file