-
Notifications
You must be signed in to change notification settings - Fork 74
Description
When trying to append to existing trajectories, I construct my reporter like so:
reporter = TrajectoryReporter(
filenames=relax_filenames,
state_frequency=1,
metadata=self.metadata,
trajectory_kwargs=dict(mode="a"),
)Here, the trajectories inside relax_filenames already contain partial trajectories. Now, if I continue from these trajectories into ts.integrate, I get an error in _validate_arrays():
File "/opt/miniconda/envs/env/lib/python3.12/site-packages/torch_sim/runners.py", line 499, in optimize
trajectory_reporter.report(state, step, model=model)
File "/opt/miniconda/envs/env/lib/python3.12/site-packages/torch_sim/trajectory.py", line 264, in report
self.trajectories[idx].write_state(substate, step, **self.state_kwargs)
File "/opt/miniconda/envs/env/lib/python3.12/site-packages/torch_sim/trajectory.py", line 782, in write_state
self.write_arrays(data, steps)
File "/opt/miniconda/envs/env/lib/python3.12/site-packages/torch_sim/trajectory.py", line 510, in write_arrays
self._validate_array(name, array, steps)
File "/opt/miniconda/envs/env/lib/python3.12/site-packages/torch_sim/trajectory.py", line 587, in _validate_array
raise ValueError(
ValueError: steps[0]=1 must be greater than the last recorded step 10 for array positions
The issue appears to be that in ts.optimize/ts.integrate we always start from step=1, even if we're in append mode. In that case, the validation will fail and lead to a crash. Thus, I don't see a way currently to actually append to a trajectory via ts.optimize/ts.integrate.
From my perspective, a solution could be to auto-detect the current step from the trajectory if we're in a mode and start the integration from there, not 1. If you agree I can draft a small PR to address that.
Thanks!