Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue when mixing get_variables_data & get_variable_data calls #279

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading