From be5087e28578adbb3c204920f8a9266b8996aab5 Mon Sep 17 00:00:00 2001 From: orionarcher Date: Wed, 4 Mar 2026 11:50:18 -0500 Subject: [PATCH 1/4] Add log line clarifying BinningAutoBatcher is used only for optimizer state init --- torch_sim/runners.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/torch_sim/runners.py b/torch_sim/runners.py index e718577ee..4f60d3cd5 100644 --- a/torch_sim/runners.py +++ b/torch_sim/runners.py @@ -629,6 +629,10 @@ def optimize[T: OptimState]( # noqa: C901, PLR0915 if isinstance(initial_state, OptimState): state = initial_state else: + logger.info( + "optimize: initializing optimizer state via chunked apply " + "(BinningAutoBatcher); InFlightAutoBatcher will be used for optimization" + ) state = _chunked_apply( init_fn, initial_state, From 3463eceb802560037cbb22ee1e2cbd2493953c76 Mon Sep 17 00:00:00 2001 From: orionarcher Date: Wed, 4 Mar 2026 12:08:20 -0500 Subject: [PATCH 2/4] Explicitly close trajectory file handles before reopening in reopen_trajectories --- torch_sim/trajectory.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_sim/trajectory.py b/torch_sim/trajectory.py index 290351496..1fe933626 100644 --- a/torch_sim/trajectory.py +++ b/torch_sim/trajectory.py @@ -197,6 +197,8 @@ def reopen_trajectories( # we set to "a" mode temporarily (read mode is unaffected). _mode = self.trajectory_kwargs.get("mode", "w") self.trajectory_kwargs["mode"] = "a" if _mode in ["a", "w"] else "r" + for traj in self.trajectories: + traj.close() self.trajectories = [ TorchSimTrajectory( filename=filename, From e439fa24bf8adea5d8949f910fc999165ca3cf67 Mon Sep 17 00:00:00 2001 From: orionarcher Date: Wed, 4 Mar 2026 12:09:32 -0500 Subject: [PATCH 3/4] Revert "Explicitly close trajectory file handles before reopening in reopen_trajectories" This reverts commit 3463eceb802560037cbb22ee1e2cbd2493953c76. --- torch_sim/trajectory.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/torch_sim/trajectory.py b/torch_sim/trajectory.py index 1fe933626..290351496 100644 --- a/torch_sim/trajectory.py +++ b/torch_sim/trajectory.py @@ -197,8 +197,6 @@ def reopen_trajectories( # we set to "a" mode temporarily (read mode is unaffected). _mode = self.trajectory_kwargs.get("mode", "w") self.trajectory_kwargs["mode"] = "a" if _mode in ["a", "w"] else "r" - for traj in self.trajectories: - traj.close() self.trajectories = [ TorchSimTrajectory( filename=filename, From 5c3b61d268d1c35a46639e132d02b1584e3ec70e Mon Sep 17 00:00:00 2001 From: orionarcher Date: Wed, 4 Mar 2026 12:45:22 -0500 Subject: [PATCH 4/4] Fix HDF5 file lock collision in reopen_trajectories Drop self.trajectories references before opening new handles so CPython's reference counting finalizes old HDF5 file objects before the new opens. Remove the incomplete TODO workaround from TorchSimTrajectory.__init__ that was a band-aid for the same issue. --- torch_sim/trajectory.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/torch_sim/trajectory.py b/torch_sim/trajectory.py index 290351496..5a73d5802 100644 --- a/torch_sim/trajectory.py +++ b/torch_sim/trajectory.py @@ -186,6 +186,7 @@ def reopen_trajectories( ValueError: If filenames are not unique """ self.finish() + self.trajectories = [] # drop refs so HDF5 finalizes before new opens filenames = ( [filenames] if isinstance(filenames, (str, pathlib.Path)) else list(filenames) @@ -524,12 +525,6 @@ def __init__( else: compression = None - # TODO FIX THIS - if hasattr(tables, "file") and ( - handles := tables.file._open_files.get_handlers_by_name(str(filename)) - ): - list(handles)[-1].close() - # create parent directory if it doesn't exist filename.parent.mkdir(parents=True, exist_ok=True) self._file = tables.open_file(str(filename), mode=mode, filters=compression)