Skip to content

Commit

Permalink
Allow more flexibility in sending data to adaptivity
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Feb 9, 2024
1 parent 60755e6 commit fa2c122
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion micro_manager/adaptivity/adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions micro_manager/adaptivity/global_adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion micro_manager/adaptivity/local_adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_adaptivity_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fa2c122

Please sign in to comment.