From 2171142ad7e7874de9dcbace5ecce64c16505c6a Mon Sep 17 00:00:00 2001 From: Peter Meisrimel Date: Wed, 28 May 2025 09:19:38 +0200 Subject: [PATCH 1/2] Fixed race condition for trajectory reading --- src/common/io.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/io.py b/src/common/io.py index 701b23a9..da7f725f 100644 --- a/src/common/io.py +++ b/src/common/io.py @@ -1412,7 +1412,8 @@ def _read_trajectory_data(self, data_index, read_diag_data, start_index = 0, sto note that 'read_diag_data' is a boolean used when this function is invoked for diagnostic variables. """ - self._verify_file_data() + # Assume self._verify_file_data() was called before, since + # we typically have 2 calls to _read_trajectory_data(...); time & data file_position = int(self._data_2_info["file_position"]) sizeof_type = int(self._data_2_info["sizeof_type"]) @@ -1442,7 +1443,7 @@ def _read_trajectory_data(self, data_index, read_diag_data, start_index = 0, sto return data - def _get_interpolated_trajectory(self, data_index: int, start_index: int = 0, stop_index: int = None) -> Trajectory: + def _get_interpolated_trajectory(self, data_index: int, start_index: int = 0, stop_index: int | None = None) -> Trajectory: """ Returns an interpolated trajectory for variable of corresponding index 'data_index'. """ self._verify_file_data() @@ -1455,7 +1456,8 @@ def _get_interpolated_trajectory(self, data_index: int, start_index: int = 0, st time_vector = self._read_trajectory_data(0, False, start_index, stop_index) data = self._read_trajectory_data(data_index, False, start_index, stop_index) - f = scipy.interpolate.interp1d(time_vector, data, fill_value="extrapolate") + n = min(len(time_vector), len(data)) # safety for reading wiith allow_file_updates = True + f = scipy.interpolate.interp1d(time_vector[:n], data[:n], fill_value = "extrapolate") # note that we dont need to slice here because diag_time_vector is already sliced accordingly self._data_2[data_index] = f(diag_time_vector) From 8272131e4d959792e93fbfaf7e328212ce19a942 Mon Sep 17 00:00:00 2001 From: Peter Meisrimel Date: Wed, 28 May 2025 10:45:57 +0200 Subject: [PATCH 2/2] changelog entry --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 0a7530cd..2053f0df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ --- CHANGELOG --- --- PyFMI-FUTURE --- * Fixed an issue for dynamic_diagnostics, where failures to evaluate the Jacobian would result in invalid XML. + * Fixed a race-condition in using ResultDymolaBinary.get_variables_data(). --- PyFMI-2.17.1 --- * Fixed compilation issue with Cython 3.1.