Skip to content
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,6 +1,7 @@
--- CHANGELOG ---
--- PyFMI-FUTURE ---
* Fixed a crash with the `Master` algorithm option `block_initialization`.
* Fixed a result handling issue for `dynamic_diagnostics = True` and `["<solver>_options"]["clock_step"] = False`.

--- PyFMI-2.20.1 ---
* Resolved issue where caching in result handling was too persistent and could prevent automatic garbage collection.
Expand Down
6 changes: 4 additions & 2 deletions src/common/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ def prepare_calculated_diagnostics(self, diagnostics_vars: dict) -> dict:
"""
# Fixed variables
calc_diags = {
f"{DIAGNOSTICS_PREFIX}cpu_time" : (0.0, "Cumulative CPU time"),
f"{DIAGNOSTICS_PREFIX}nbr_events" : (0, "Cumulative number of events"),
f"{DIAGNOSTICS_PREFIX}nbr_time_events" : (0, "Cumulative number of time events"),
f"{DIAGNOSTICS_PREFIX}nbr_state_events": (0, "Cumulative number of state events"),
f"{DIAGNOSTICS_PREFIX}nbr_steps" : (0, "Cumulative number of steps"),
}
if f"{DIAGNOSTICS_PREFIX}cpu_time_per_step" in diagnostics_vars.keys():
calc_diags[f"{DIAGNOSTICS_PREFIX}cpu_time"] = (0.0, "Cumulative CPU time")

diagnostics_vars_names = list(diagnostics_vars.keys())

Expand All @@ -100,13 +101,14 @@ def prepare_calculated_diagnostics(self, diagnostics_vars: dict) -> dict:
# index maps for calculating diagnostics variables
calc_diags_names = list(calc_diags.keys())
self._idx_map_calc_diags = {
"cpu_time": calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}cpu_time'),
"nbr_events": calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}nbr_events'),
"nbr_time_events": calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}nbr_time_events'),
"nbr_state_events": calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}nbr_state_events'),
"nbr_steps": calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}nbr_steps'),
"nbr_state_limits": len(calc_diags_names) - self._number_states,
}
if f"{DIAGNOSTICS_PREFIX}cpu_time" in calc_diags_names:
self._idx_map_calc_diags["cpu_time"] = calc_diags_names.index(f'{DIAGNOSTICS_PREFIX}cpu_time')

idx_state_errors = None
for idx, key in enumerate(diagnostics_vars):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_fmi3_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,13 @@ def test_dynamic_diagnostics_scalar_atol(self, atol):
opts["ncp"] = 1

model.simulate(options = opts)

def test_dynamic_diagnostics_no_time_per_step_should_not_set_cpu_time(self):
model = load_fmu(FMI3_REF_FMU_PATH / "VanDerPol.fmu")

opts = model.simulate_options()
opts["dynamic_diagnostics"] = True
opts["CVode_options"]["clock_step"] = False
res = model.simulate(options = opts)

assert "@Diagnostics.cpu_time" not in res.keys()
Loading