Skip to content

Commit 1f70cef

Browse files
authored
Add config options for adaptivity metrics and memory usage output to allow for different levels (#172)
* Add a config option for adaptivity output type of either local, global, or all * Modify memory usage output configuration to have levels and also an output frequency * Add CHANGELOG entry * Change wording in documentation
1 parent 01daef4 commit 1f70cef

File tree

7 files changed

+223
-80
lines changed

7 files changed

+223
-80
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## latest
44

5+
- Add config options for adaptivity metrics and memory usage output to allow for different levels https://github.com/precice/micro-manager/pull/172
56
- Fix bug in adaptivity computation when an active simulation with associations is deactivated https://github.com/precice/micro-manager/pull/171
67
- Properly handle micro simulation initialization for lazy initialization https://github.com/precice/micro-manager/pull/169
78
- Delete the simulation object when the simulation is deactivated https://github.com/precice/micro-manager/pull/167

docs/configuration.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ The Micro Manager is configured with a JSON file. An example configuration file
3030

3131
This example configuration file is in [`examples/micro-manager-config.json`](https://github.com/precice/micro-manager/tree/develop/examples/micro-manager-config.json).
3232

33-
The path to the file containing the Python importable micro simulation class is specified in the `micro_file_name` parameter. If the file is not in the working directory, give the relative path from the directory where the Micro Manager is executed.
33+
## Micro Manager Configuration
3434

35-
Set the output [log](tooling-micro-manager-logging.html) directory using the parameter `output_dir`.
36-
37-
To output the runtime memory usage, set `output_memory_usage` to `True`. This will output a CSV file with the peak memory usage (RSS) in every time window, in MBs.
35+
Parameter | Description
36+
--- | ---
37+
`micro_file_name` | Path to the file containing the Python importable micro simulation class. If the file is not in the working directory, give the relative path from the directory where the Micro Manager is executed.
38+
`output_directory` | Path to output directory for logging and performance metrics. Directory is created if not existing already.
39+
`memory_usage_output_type` | Set to either `local`, `global`, or `all`. `local` outputs rank-wise peak memory usage. `global` outputs global averaged peak memory usage. `all` outputs both local and global levels. All output is to a CSV file with the peak memory usage (RSS) in every time window, in MBs.
40+
`memory_usage_output_n` | Frequency of output of memory usage (integer which is number of time windows).
3841

39-
There are three main sections in the configuration file, the `coupling_params`, the `simulation_params` and the optional `diagnostics`.
42+
Apart from the base settings, there are three main sections in the configuration file, the `coupling_params`, the `simulation_params` and the optional `diagnostics`.
4043

4144
## Coupling Parameters
4245

@@ -120,6 +123,7 @@ Parameter | Description
120123
`type` | Set to either `local` or `global`. The type of adaptivity matters when the Micro Manager is run in parallel. `local` means comparing micro simulations within a local partitioned domain for similarity. `global` means comparing micro simulations from all partitions, so over the entire domain.
121124
`data` | List of names of data which are to be used to calculate if micro-simulations are similar or not. For example `["temperature", "porosity"]`.
122125
`adaptivity_every_n_time_windows` | Frequency of adaptivity computation (integer which is number of time windows).
126+
`output_type` | Set to either `local`, `global`, or `all`. `local` outputs rank-wise adaptivity metrics. `global` outputs global averaged metrics. `all` outputs both local and global metrics.
123127
`output_n` | Frequency of output of adaptivity metrics (integer which is number of time windows).
124128
`history_param` | History parameter $$ \Lambda $$, set as $$ \Lambda >= 0 $$.
125129
`coarsening_constant` | Coarsening constant $$ C_c $$, set as $$ 0 =< C_c < 1 $$.

micro_manager/adaptivity/adaptivity.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, configurator, rank, nsims) -> None:
3131
self._hist_param = configurator.get_adaptivity_hist_param()
3232
self._adaptivity_data_names = configurator.get_data_for_adaptivity()
3333
self._adaptivity_type = configurator.get_adaptivity_type()
34+
self._adaptivity_output_type = configurator.get_adaptivity_output_type()
3435

3536
self._micro_problem = getattr(
3637
importlib.import_module(
@@ -74,7 +75,10 @@ def __init__(self, configurator, rank, nsims) -> None:
7475
else:
7576
metrics_output_dir = "adaptivity-metrics"
7677

77-
if self._rank == 0:
78+
if self._rank == 0 and (
79+
self._adaptivity_output_type == "global"
80+
or self._adaptivity_output_type == "all"
81+
):
7882
self._global_metrics_logger = Logger(
7983
"global-metrics-logger",
8084
metrics_output_dir + "-global.csv",
@@ -86,12 +90,16 @@ def __init__(self, configurator, rank, nsims) -> None:
8690
"n,avg active,avg inactive,max active,max inactive"
8791
)
8892

89-
self._metrics_logger = Logger(
90-
"metrics-logger",
91-
metrics_output_dir + "-" + str(rank) + ".csv",
92-
rank,
93-
csv_logger=True,
94-
)
93+
if (
94+
self._adaptivity_output_type == "local"
95+
or self._adaptivity_output_type == "all"
96+
):
97+
self._metrics_logger = Logger(
98+
"metrics-logger",
99+
metrics_output_dir + "-" + str(rank) + ".csv",
100+
rank,
101+
csv_logger=True,
102+
)
95103

96104
def _update_similarity_dists(self, dt: float, data: dict) -> None:
97105
"""

micro_manager/adaptivity/global_adaptivity.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def __init__(
6565

6666
self._precice_participant = participant
6767

68-
self._metrics_logger.log_info("n,n active,n inactive,assoc ranks")
68+
if (
69+
self._adaptivity_output_type == "all"
70+
or self._adaptivity_output_type == "local"
71+
):
72+
self._metrics_logger.log_info("n,n active,n inactive,assoc ranks")
6973

7074
def compute_adaptivity(
7175
self,
@@ -168,7 +172,7 @@ def log_metrics(self, n: int) -> None:
168172
"""
169173
Log the following metrics:
170174
171-
Metrics on this rank:
175+
Local metrics:
172176
- Time window at which the metrics are logged
173177
- Number of active simulations
174178
- Number of inactive simulations
@@ -194,39 +198,51 @@ def log_metrics(self, n: int) -> None:
194198
else:
195199
inactive_sims_on_this_rank += 1
196200

197-
ranks_of_sims = self._get_ranks_of_sims()
201+
if (
202+
self._adaptivity_output_type == "all"
203+
or self._adaptivity_output_type == "local"
204+
):
205+
ranks_of_sims = self._get_ranks_of_sims()
206+
207+
assoc_ranks = [] # Ranks to which inactive sims on this rank are associated
208+
for global_id in self._global_ids:
209+
if not self._is_sim_active[global_id]:
210+
assoc_rank = int(
211+
ranks_of_sims[self._sim_is_associated_to[global_id]]
212+
)
213+
if not assoc_rank in assoc_ranks:
214+
assoc_ranks.append(assoc_rank)
198215

199-
assoc_ranks = [] # Ranks to which inactive sims on this rank are associated
200-
for global_id in self._global_ids:
201-
if not self._is_sim_active[global_id]:
202-
assoc_rank = int(ranks_of_sims[self._sim_is_associated_to[global_id]])
203-
if not assoc_rank in assoc_ranks:
204-
assoc_ranks.append(assoc_rank)
205-
206-
self._metrics_logger.log_info(
207-
"{},{},{},{}".format(
208-
n,
209-
active_sims_on_this_rank,
210-
inactive_sims_on_this_rank,
211-
assoc_ranks,
216+
self._metrics_logger.log_info(
217+
"{},{},{},{}".format(
218+
n,
219+
active_sims_on_this_rank,
220+
inactive_sims_on_this_rank,
221+
assoc_ranks,
222+
)
212223
)
213-
)
214224

215-
active_sims_rankwise = self._comm.gather(active_sims_on_this_rank, root=0)
216-
inactive_sims_rankwise = self._comm.gather(inactive_sims_on_this_rank, root=0)
225+
if (
226+
self._adaptivity_output_type == "all"
227+
or self._adaptivity_output_type == "global"
228+
):
229+
active_sims_rankwise = self._comm.gather(active_sims_on_this_rank, root=0)
230+
inactive_sims_rankwise = self._comm.gather(
231+
inactive_sims_on_this_rank, root=0
232+
)
217233

218-
if self._rank == 0:
219-
size = self._comm.Get_size()
234+
if self._rank == 0:
235+
size = self._comm.Get_size()
220236

221-
self._global_metrics_logger.log_info(
222-
"{},{},{},{},{}".format(
223-
n,
224-
sum(active_sims_rankwise) / size,
225-
sum(inactive_sims_rankwise) / size,
226-
max(active_sims_rankwise),
227-
max(inactive_sims_rankwise),
237+
self._global_metrics_logger.log_info(
238+
"{},{},{},{},{}".format(
239+
n,
240+
sum(active_sims_rankwise) / size,
241+
sum(inactive_sims_rankwise) / size,
242+
max(active_sims_rankwise),
243+
max(inactive_sims_rankwise),
244+
)
228245
)
229-
)
230246

231247
def _communicate_micro_output(
232248
self,

micro_manager/adaptivity/local_adaptivity.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def __init__(self, configurator, num_sims, participant, rank, comm) -> None:
3232
super().__init__(configurator, rank, num_sims)
3333
self._comm = comm
3434

35-
self._metrics_logger.log_info("n,n active,n inactive")
35+
if (
36+
self._adaptivity_output_type == "all"
37+
or self._adaptivity_output_type == "local"
38+
):
39+
self._metrics_logger.log_info("n,n active,n inactive")
3640

3741
self._precice_participant = participant
3842

@@ -129,7 +133,7 @@ def log_metrics(self, n: int) -> None:
129133
"""
130134
Log the following metrics:
131135
132-
Metrics on this rank:
136+
Local metrics:
133137
- Time window at which the metrics are logged
134138
- Number of active simulations
135139
- Number of inactive simulations
@@ -153,29 +157,39 @@ def log_metrics(self, n: int) -> None:
153157
else:
154158
inactive_sims_on_this_rank += 1
155159

156-
self._metrics_logger.log_info(
157-
"{},{},{}".format(
158-
n,
159-
active_sims_on_this_rank,
160-
inactive_sims_on_this_rank,
160+
if (
161+
self._adaptivity_output_type == "all"
162+
or self._adaptivity_output_type == "local"
163+
):
164+
self._metrics_logger.log_info(
165+
"{},{},{}".format(
166+
n,
167+
active_sims_on_this_rank,
168+
inactive_sims_on_this_rank,
169+
)
161170
)
162-
)
163171

164-
active_sims_rankwise = self._comm.gather(active_sims_on_this_rank, root=0)
165-
inactive_sims_rankwise = self._comm.gather(inactive_sims_on_this_rank, root=0)
172+
if (
173+
self._adaptivity_output_type == "global"
174+
or self._adaptivity_output_type == "all"
175+
):
176+
active_sims_rankwise = self._comm.gather(active_sims_on_this_rank, root=0)
177+
inactive_sims_rankwise = self._comm.gather(
178+
inactive_sims_on_this_rank, root=0
179+
)
166180

167-
if self._rank == 0:
168-
size = self._comm.Get_size()
181+
if self._rank == 0:
182+
size = self._comm.Get_size()
169183

170-
self._global_metrics_logger.log_info_rank_zero(
171-
"{},{},{},{},{}".format(
172-
n,
173-
sum(active_sims_rankwise) / size,
174-
sum(inactive_sims_rankwise) / size,
175-
max(active_sims_rankwise),
176-
max(inactive_sims_rankwise),
184+
self._global_metrics_logger.log_info_rank_zero(
185+
"{},{},{},{},{}".format(
186+
n,
187+
sum(active_sims_rankwise) / size,
188+
sum(inactive_sims_rankwise) / size,
189+
max(active_sims_rankwise),
190+
max(inactive_sims_rankwise),
191+
)
177192
)
178-
)
179193

180194
def _update_inactive_sims(self, micro_sims: list) -> None:
181195
"""

0 commit comments

Comments
 (0)