Skip to content

Commit

Permalink
Add a separate logger for adaptivity
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Nov 12, 2024
1 parent 10f434b commit 60d8607
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
12 changes: 0 additions & 12 deletions micro_manager/adaptivity/global_adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ def compute_adaptivity(
similarity_dists, is_sim_active, sim_is_associated_to
)

# self._logger.info(
# "{} active simulations, {} inactive simulations".format(
# np.count_nonzero(
# is_sim_active[self._global_ids[0] : self._global_ids[-1] + 1]
# ),
# np.count_nonzero(
# is_sim_active[self._global_ids[0] : self._global_ids[-1] + 1]
# == False
# ),
# )
# )

return similarity_dists, is_sim_active, sim_is_associated_to

def communicate_micro_output(
Expand Down
7 changes: 0 additions & 7 deletions micro_manager/adaptivity/local_adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ def compute_adaptivity(
similarity_dists, is_sim_active, sim_is_associated_to
)

# self._logger.info(
# "{} active simulations, {} inactive simulations".format(
# np.count_nonzero(is_sim_active),
# np.count_nonzero(is_sim_active == False),
# )
# )

return similarity_dists, is_sim_active, sim_is_associated_to

def _update_inactive_sims(
Expand Down
25 changes: 25 additions & 0 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def __init__(self, config_file: str) -> None:
self._is_adaptivity_on = self._config.turn_on_adaptivity()

if self._is_adaptivity_on:
self._adaptivity_logger = Logger(
"Adaptivity", "micro-manager-adaptivity.log", self._rank
)

self._adaptivity_logger.log_info_one_rank(
"Time,Avg Active Sims,Avg Inactive Sims"
)

self._number_of_sims_for_adaptivity = 0

self._data_for_adaptivity: Dict[str, np.ndarray] = dict()
Expand Down Expand Up @@ -298,6 +306,23 @@ def solve(self) -> None:
for sim in self._micro_sims:
sim.output()

if self._is_adaptivity_on:
local_active_sims = np.where(is_sim_active)[0]
global_active_sims = self._comm.gather(local_active_sims)

local_inactive_sims = np.where(is_sim_active == False)[0]
global_inactive_sims = self._comm.gather(
local_inactive_sims
)

self._adaptivity_logger.log_info_one_rank(
"{},{},{}".format(
t,
np.mean(global_active_sims),
np.mean(global_inactive_sims),
)
)

self._participant.finalize()

def initialize(self) -> None:
Expand Down

0 comments on commit 60d8607

Please sign in to comment.