Skip to content

Commit

Permalink
Fixing bug + changelog + test (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon authored and modelonrobinandersson committed Dec 19, 2024
1 parent fed759f commit c8d1e0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--- CHANGELOG ---
--- Future ---
* Fixed an issue with `get_variables_data` returning full trajectories when mixed with `get_variable_data` calls.

--- PyFMI-2.16.0 ---
* Added verification against the available free disk space when storing the result on disk (i.e. a protection
Expand Down
2 changes: 2 additions & 0 deletions src/common/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,8 @@ def get_variable_data(self, name: str) -> Trajectory:
A Trajectory object containing the time vector and the data vector
of the variable.
"""
# prevent caching interference with 'get_variables_data'
self._last_set_of_indices = (None, None)
return self._get_variable_data_as_trajectory(name)

def get_variables_data(self,
Expand Down
22 changes: 20 additions & 2 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ def test_exception_simulation_start(self):

bouncingBall = ResultHandlerBinaryFile(model)
bouncingBall.set_options(opts)
msg = "Unable to start simulation. The following keyword argument\(s\) are empty:"
msg += " 'diagnostics\_params' and 'diagnostics\_vars'."
msg = r"Unable to start simulation. The following keyword argument\(s\) are empty:"
msg += r" 'diagnostics\_params' and 'diagnostics\_vars'."
with pytest.raises(FMUException, match = msg):
bouncingBall.simulation_start()

Expand Down Expand Up @@ -1934,6 +1934,24 @@ def test_trajectory_lengths(self):
assert rdb.get_variables_data([], start_index = 1)[1] == 1
assert rdb.get_variables_data([], start_index = 5)[1] == 5

def test_mixes_get_variable_s_data(self):
"""Test there are no issues when mixing calls of get_variable_data and get_variables_data."""
fmu = Dummy_FMUModelME2([], os.path.join(file_path, "files", "FMUs", "XML", "ME2.0", "bouncingBall.fmu"), _connect_dll=False)
ncp = 500
fmu.simulate(options = {"ncp": ncp})
rdb = ResultDymolaBinary(fmu.get_last_result_file(), allow_file_updates = True)

vars = ["time"]
start_index, stop_index = 0, 5

partial_1, _ = rdb.get_variables_data(vars, start_index, stop_index)
full_traj = rdb.get_variable_data(vars[0])
partial_2, _ = rdb.get_variables_data(vars, start_index, stop_index)

assert len(partial_1[vars[0]].x) == (stop_index - start_index)
assert len(full_traj.x) == (ncp + 1)
assert len(partial_2[vars[0]].x) == (stop_index - start_index)

@pytest.mark.assimulo
class TestFileSizeLimit:
def _setup(self, result_type, result_file_name="", fmi_type="me"):
Expand Down

0 comments on commit c8d1e0d

Please sign in to comment.