From c1cd6a7e3aa4115d8796c44134757a5173333274 Mon Sep 17 00:00:00 2001 From: Mathis Kelm Date: Thu, 15 Aug 2024 17:12:33 +0200 Subject: [PATCH] Add lazy ininialization for local adaptivity --- micro_manager/adaptivity/local_adaptivity.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/micro_manager/adaptivity/local_adaptivity.py b/micro_manager/adaptivity/local_adaptivity.py index a2defb8c..1c253ae4 100644 --- a/micro_manager/adaptivity/local_adaptivity.py +++ b/micro_manager/adaptivity/local_adaptivity.py @@ -6,6 +6,7 @@ import numpy as np from .adaptivity import AdaptivityCalculator +from ..micro_simulation import create_simulation_class class LocalAdaptivityCalculator(AdaptivityCalculator): @@ -130,6 +131,16 @@ def _update_inactive_sims( if not _is_sim_active[i]: # if id is inactive if self._check_for_activation(i, similarity_dists, _is_sim_active): associated_active_local_id = _sim_is_associated_to[i] + if micro_sims[i] == None: + self._logger.info(f"{i} to be solved, lazy initialization") + micro_problem = getattr( + importlib.import_module( + self._micro_file_name, "MicroSimulation" + ), + "MicroSimulation", + ) + micro_sims[i] = create_simulation_class(micro_problem)(i) + self._logger.info(f"lazy initalization of {i} successful") micro_sims[i].set_state( micro_sims[associated_active_local_id].get_state() )