Skip to content

Commit

Permalink
Add logic to calculate peak memory usage of micro simulation for adap…
Browse files Browse the repository at this point in the history
…tive case
  • Loading branch information
IshaanDesai committed Dec 19, 2024
1 parent e222e9f commit 1af9496
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ def _solve_micro_simulations(self, micro_sims_input: list, dt: float) -> tuple:
if not self._has_sim_crashed[count]:
# Attempt to solve the micro simulation
try:
_, pre_peak = tracemalloc.get_traced_memory()
start_time = time.process_time()
pre_size, pre_peak = tracemalloc.get_traced_memory()
micro_sims_output[count] = sim.solve(micro_sims_input[count], dt)
post_size, post_peak = tracemalloc.get_traced_memory()
end_time = time.process_time()
_, post_peak = tracemalloc.get_traced_memory()
# Write solve time of the macro simulation if required and the simulation has not crashed
if self._is_micro_solve_time_required:
micro_sims_output[count]["solve_cpu_time"] = (
Expand Down Expand Up @@ -761,17 +761,24 @@ def _solve_micro_simulations_with_adaptivity(
if not self._has_sim_crashed[active_id]:
# Attempt to solve the micro simulation
try:
_, pre_peak = tracemalloc.get_traced_memory()
start_time = time.process_time()
micro_sims_output[active_id] = self._micro_sims[active_id].solve(
micro_sims_input[active_id], dt
)
end_time = time.process_time()
_, post_peak = tracemalloc.get_traced_memory()
# Write solve time of the macro simulation if required and the simulation has not crashed
if self._is_micro_solve_time_required:
micro_sims_output[active_id]["solve_cpu_time"] = (
end_time - start_time
)

if self._is_micro_solve_mem_use_required:
micro_sims_output[active_id]["solve_mem_use"] = (
post_peak - pre_peak
)

# Mark the micro sim as active for export
micro_sims_output[active_id]["active_state"] = 1
micro_sims_output[active_id][
Expand Down Expand Up @@ -838,6 +845,9 @@ def _solve_micro_simulations_with_adaptivity(
if self._is_micro_solve_time_required:
micro_sims_output[inactive_id]["solve_cpu_time"] = 0

if self._is_micro_solve_mem_use_required:
micro_sims_output[inactive_id]["solve_mem_use"] = 0

# Collect micro sim output for adaptivity calculation
for i in range(self._local_number_of_sims):
for name in self._adaptivity_micro_data_names:
Expand Down

0 comments on commit 1af9496

Please sign in to comment.