diff --git a/micro_manager/adaptivity/adaptivity.py b/micro_manager/adaptivity/adaptivity.py index ec9b31b0..ae2b9411 100644 --- a/micro_manager/adaptivity/adaptivity.py +++ b/micro_manager/adaptivity/adaptivity.py @@ -53,7 +53,7 @@ def _get_similarity_dists(self, dt: float, similarity_dists: np.ndarray, data: d _similarity_dists = np.copy(similarity_dists) data_diff = np.zeros_like(_similarity_dists) - for name in self._adaptivity_data_names: + for name in data.keys(): data_vals = data[name] if data_vals.ndim == 1: # If the adaptivity-data is a scalar for each simulation, diff --git a/micro_manager/adaptivity/global_adaptivity.py b/micro_manager/adaptivity/global_adaptivity.py index c217b8a6..155853a7 100644 --- a/micro_manager/adaptivity/global_adaptivity.py +++ b/micro_manager/adaptivity/global_adaptivity.py @@ -94,9 +94,15 @@ def compute_adaptivity( is_sim_active : numpy array 1D array having state (active or inactive) of each micro simulation """ + for name in data_for_adaptivity.keys(): + if name not in self._adaptivity_data_names: + raise ValueError( + "Data for adaptivity must be one of the following: {}".format( + self._adaptivity_data_names.keys())) + # Gather adaptivity data from all ranks global_data_for_adaptivity = dict() - for name in self._adaptivity_data_names.keys(): + for name in data_for_adaptivity.keys(): data_as_list = self._comm.allgather(data_for_adaptivity[name]) global_data_for_adaptivity[name] = np.concatenate((data_as_list[:]), axis=0) @@ -106,14 +112,9 @@ def compute_adaptivity( is_sim_active, sim_is_associated_to = self._update_inactive_sims( similarity_dists, is_sim_active, sim_is_associated_to_nm1, micro_sims) - - print("sim_is_associated_to: {}".format(sim_is_associated_to)) - sim_is_associated_to = self._associate_inactive_to_active( similarity_dists, is_sim_active, sim_is_associated_to) - print("sim_is_associated_to: {}".format(sim_is_associated_to)) - self._logger.info( "{} active simulations, {} inactive simulations".format( np.count_nonzero( diff --git a/micro_manager/adaptivity/local_adaptivity.py b/micro_manager/adaptivity/local_adaptivity.py index cd465a0b..3fc45c2a 100644 --- a/micro_manager/adaptivity/local_adaptivity.py +++ b/micro_manager/adaptivity/local_adaptivity.py @@ -28,7 +28,7 @@ def compute_adaptivity( similarity_dists_nm1: np.ndarray, is_sim_active_nm1: np.ndarray, sim_is_associated_to_nm1: np.ndarray, - data_for_adaptivity: dict): + data_for_adaptivity: dict) -> tuple: """ Compute adaptivity locally (within a rank). @@ -55,6 +55,12 @@ def compute_adaptivity( is_sim_active : numpy array 1D array, True is sim is active, False if sim is inactive. """ + for name in data_for_adaptivity.keys(): + if name not in self._adaptivity_data_names: + raise ValueError( + "Data for adaptivity must be one of the following: {}".format( + self._adaptivity_data_names.keys())) + similarity_dists = self._get_similarity_dists(dt, similarity_dists_nm1, data_for_adaptivity) # Operation done globally if global adaptivity is chosen diff --git a/tests/unit/test_adaptivity_parallel.py b/tests/unit/test_adaptivity_parallel.py index 2f1b2a4e..189c45cf 100644 --- a/tests/unit/test_adaptivity_parallel.py +++ b/tests/unit/test_adaptivity_parallel.py @@ -105,7 +105,7 @@ def test_update_all_active_sims_global_adaptivity(self): rank=self._rank, comm=self._comm) - adaptivity_controller._adaptivity_data_names = {"data1": "scalar", "data2": "scalar"} + adaptivity_controller._adaptivity_data_names = {"data1": "scalar", "data2": "scalar", "data3": "vector"} class MicroSimulation(): def __init__(self, global_id) -> None: