Skip to content

Commit f457916

Browse files
Adding some experimental profiling for do_step
1 parent 3b00639 commit f457916

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/pyfmi/master.pyx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ cdef perform_do_step_serial_with_downsampling(
8080
list models,
8181
list downsampling_rates,
8282
dict time_spent,
83+
dict do_step_profiling,
8384
double cur_time,
8485
double final_time,
8586
double step_size,
@@ -96,7 +97,9 @@ cdef perform_do_step_serial_with_downsampling(
9697
time_start = timer()
9798
h = min(ds_rate*step_size, abs(final_time - cur_time)) # TODO: eps adjustments here?
9899
status = model.do_step(cur_time, h, new_step)
99-
time_spent[model] += timer() - time_start
100+
time_spent_for_do_step = timer() - time_start
101+
time_spent[model] += time_spent_for_do_step
102+
do_step_profiling[model].append(time_spent_for_do_step)
100103
if status != 0:
101104
raise FMUException("The step failed for model %s at time %f. See the log for more information. Return flag %d."%(model.get_name(), cur_time, status))
102105

@@ -470,6 +473,7 @@ cdef class Master:
470473
cdef public bool _last_step
471474
cdef public dict step_size_downsampling_factor
472475
cdef public bool _uses_step_size_downsampling
476+
cdef public dict _do_step_profiling
473477

474478
def __init__(self, models, connections):
475479
"""
@@ -509,6 +513,7 @@ cdef class Master:
509513
"direct_dependence": []}) for model in models)
510514
self.models_id_mapping = {str(id(model)): model for model in models}
511515
self.elapsed_time = {model: 0.0 for model in models}
516+
self._do_step_profiling = {model: [] for model in models}
512517
self.elapsed_time_init = {model: 0.0 for model in models}
513518
self.elapsed_time["result_handling"] = 0.0
514519
self._display_counter = 1
@@ -1432,6 +1437,7 @@ cdef class Master:
14321437
self.models,
14331438
list(self.step_size_downsampling_factor.values()),
14341439
self.elapsed_time,
1440+
self._do_step_profiling,
14351441
tcur,
14361442
final_time,
14371443
step_size,
@@ -1777,6 +1783,10 @@ cdef class Master:
17771783
print(' Number of global steps : %d'%self.statistics["nsteps"])
17781784
if self.error_controlled:
17791785
print(' Number of rejected steps : %d'%self.statistics["nreject"])
1786+
1787+
def get_do_step_profiling(self):
1788+
"""TODO"""
1789+
return self._do_step_profiling
17801790

17811791
def _get_support_directional_derivatives(self):
17821792
if self._support_directional_derivatives == -1:

tests/test_fmi_master.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,11 @@ def test_serial_downsampling(self, test_case: SerialDownsamplingTestCase):
981981
fmu2.do_step_history,
982982
test_case.expected_stepsizes_2)
983983

984+
# check do_step_profiling, TODO: FUTURE; should maybe be a separate test?
985+
do_step_profiling = master.get_do_step_profiling()
986+
assert len(do_step_profiling[fmu1]) == len(test_case.expected_stepsizes_1)
987+
assert len(do_step_profiling[fmu2]) == len(test_case.expected_stepsizes_2)
988+
984989
@pytest.mark.parametrize("factor", [1, 2, 5, 10])
985990
def test_rescale_step_size_and_downsampling(self, factor):
986991
"""Test that rescaling both the step-size and downsampling gives identical results."""
@@ -1021,4 +1026,3 @@ def test_rescale_step_size_and_downsampling(self, factor):
10211026
np.testing.assert_array_equal(
10221027
fmu2.do_step_history,
10231028
[3, 3, 3, 1])
1024-

0 commit comments

Comments
 (0)