Skip to content

Commit d6ef7c4

Browse files
authored
Merge pull request #177 from precice/micro-manager-v0.7.0
Release v0.7.0
2 parents fc2a345 + 958a5f6 commit d6ef7c4

29 files changed

+1232
-885
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
# Check for updates to GitHub Actions every week
12+
interval: "weekly"

.github/workflows/pythonpublish.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Upload Python Package
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build:
10+
name: Build package
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.x'
17+
- run: pip install --upgrade build
18+
- name: Build package
19+
run: pyproject-build
20+
- uses: actions/upload-artifact@v4
21+
with:
22+
name: dist
23+
path: dist
24+
overwrite: true
25+
if-no-files-found: error
26+
retention-days: 1
27+
28+
publish:
29+
name: Upload release to PyPI
30+
needs: build
31+
runs-on: ubuntu-latest
32+
permissions:
33+
id-token: write
34+
steps:
35+
- name: Download package
36+
uses: actions/download-artifact@v4
37+
with:
38+
name: dist
39+
path: dist
40+
- name: Publish package distributions to PyPI
41+
uses: pypa/gh-action-pypi-publish@release/v1

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Micro Manager changelog
22

3+
## v0.7.0
4+
5+
- Share similarity distance matrix between ranks on a compute node https://github.com/precice/micro-manager/pull/176
6+
- Use booleans instead of strings `"True"` and `"False"` in the configuration https://github.com/precice/micro-manager/pull/175
7+
- Renaming and using a newer workflow for publishing according to the trusted publishing in PyPI https://github.com/precice/micro-manager/pull/173
8+
- Add config options for adaptivity metrics and memory usage output to allow for different levels https://github.com/precice/micro-manager/pull/172
9+
- Fix bug in adaptivity computation when an active simulation with associations is deactivated https://github.com/precice/micro-manager/pull/171
10+
- Properly handle micro simulation initialization for lazy initialization https://github.com/precice/micro-manager/pull/169
11+
- Delete the simulation object when the simulation is deactivated https://github.com/precice/micro-manager/pull/167
12+
- Remove float32 data type restriction for adaptivity data [commit](https://github.com/precice/micro-manager/commit/bfa44ff4d3432c6ac0f3b1311274308d2ec9c2a4)
13+
- Trigger adaptivity when all the adaptivity data is the same https://github.com/precice/micro-manager/pull/170
14+
- Add configuration option to control frequency of adaptivity computation https://github.com/precice/micro-manager/pull/168
15+
- Remove checkpointing of adaptivity and fix output of memory usage https://github.com/precice/micro-manager/pull/166
16+
- Performance improvements: restricting data types, in-place modifications https://github.com/precice/micro-manager/pull/162
17+
- Handle adaptivity case when deactivation and activation happens in the same time window https://github.com/precice/micro-manager/pull/165
18+
- Add command line input argument to set log file https://github.com/precice/micro-manager/pull/163
19+
- Fix adaptivity metrics logging and add logging documentation https://github.com/precice/micro-manager/pull/160
20+
- Checkpoint lazily created simulation only if a checkpoint is necessary https://github.com/precice/micro-manager/pull/161
21+
322
## v0.6.0
423

524
- Add functionality for lazy creation and initialization of micro simulations https://github.com/precice/micro-manager/pull/117

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
</a>
66

77
<a style="text-decoration: none" href="https://pypi.org/project/micro-manager-precice/" target="_blank">
8-
<img src="https://github.com/precice/micro-manager/actions/workflows/pythonpublish.yml/badge.svg" alt="Upload Python Package">
8+
<img src="https://github.com/precice/micro-manager/actions/workflows/release.yml/badge.svg" alt="Upload Python Package">
99
</a>
1010

11-
[![DOI](https://joss.theoj.org/papers/10.21105/joss.05842/status.svg)](https://doi.org/10.21105/joss.05842)
12-
13-
A tool to facilitate solving two-scale (macro-micro) coupled problems using the coupling library [preCICE](https://precice.org/).
11+
A tool to create and manage a large number of (micro) simulations and couple them to a (macro) simulation using the coupling library [preCICE](https://precice.org/).
1412

1513
The main documentation is rendered on the [preCICE website](https://precice.org/tooling-micro-manager-overview.html).
1614

docs/configuration.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ summary: Provide a JSON file to configure the Micro Manager.
77

88
{% note %} In the preCICE XML configuration the Micro Manager is a participant with the name `Micro-Manager`. {% endnote %}
99

10-
The Micro Manager is configured with a JSON file. An example configuration file is
10+
The Micro Manager is configured with a JSON file. An example configuration file looks like
1111

1212
```json
1313
{
@@ -23,16 +23,23 @@ The Micro Manager is configured with a JSON file. An example configuration file
2323
"micro_dt": 1.0
2424
},
2525
"diagnostics": {
26-
"output_micro_sim_solve_time": "True"
26+
"output_micro_sim_solve_time": true
2727
}
2828
}
2929
```
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.
33+
## Micro Manager Configuration
3434

35-
There are three main sections in the configuration file, the `coupling_params`, the `simulation_params` and the optional `diagnostics`.
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).
41+
42+
Apart from the base settings, there are three main sections in the configuration file, [coupling parameters](#coupling-parameters), [simulation parameters](#simulation-parameters), and [diagnostics](#diagnostics).
3643

3744
## Coupling Parameters
3845

@@ -55,9 +62,9 @@ Adaptivity parameters | See section on [adaptivity](#adaptivity). By default, ad
5562
## Diagnostics
5663

5764
Parameter | Description
58-
--- | ---
65+
--- | ---H
5966
`data_from_micro_sims` | A Python dictionary with the names of the data from the micro simulation to be written to VTK files as keys and `"scalar"` or `"vector"` as values.
60-
`output_micro_sim_solve_time` | If `True`, the Micro Manager writes the wall clock time of the `solve()` function of each micro simulation.
67+
`output_micro_sim_solve_time` | If `true`, the Micro Manager writes the wall clock time of the `solve()` function of each micro simulation.
6168
`micro_output_n`| Frequency of calling the optional output functionality of the micro simulation in terms of number of time steps. If not given, `micro_sim.output()` is called every time step.
6269

6370
### Adding diagnostics in the preCICE XML configuration
@@ -109,18 +116,21 @@ The Micro Manager can adaptively control micro simulations. The adaptivity strat
109116

110117
All the adaptivity parameters are chosen from the second publication.
111118

112-
To turn on adaptivity, set `"adaptivity": True` in `simulation_params`. Then under `adaptivity_settings` set the following variables:
119+
To turn on adaptivity, set `"adaptivity": true` in `simulation_params`. Then under `adaptivity_settings` set the following variables:
113120

114121
Parameter | Description
115122
--- | ---
116123
`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.
117124
`data` | List of names of data which are to be used to calculate if micro-simulations are similar or not. For example `["temperature", "porosity"]`.
125+
`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.
127+
`output_n` | Frequency of output of adaptivity metrics (integer which is number of time windows).
118128
`history_param` | History parameter $$ \Lambda $$, set as $$ \Lambda >= 0 $$.
119129
`coarsening_constant` | Coarsening constant $$ C_c $$, set as $$ 0 =< C_c < 1 $$.
120130
`refining_constant` | Refining constant $$ C_r $$, set as $$ 0 =< C_r < 1 $$.
121-
`every_implicit_iteration` | If True, adaptivity is calculated in every implicit iteration. <br> If False, adaptivity is calculated once at the start of the time window and then reused in every implicit time iteration.
122-
`similarity_measure`| Similarity measure to be used for adaptivity. Can be either `L1`, `L2`, `L1rel` or `L2rel`. By default, `L1` is used. The `rel` variants calculate the respective relative norms. This parameter is *optional*.
123-
`lazy_initialization` | Set to `True` to lazily create and initialize micro simulations. If selected, micro simulation objects are created only when the micro simulation is activated for the first time. Default: `False`.
131+
`every_implicit_iteration` | If `true`, adaptivity is calculated in every implicit iteration. <br> If False, adaptivity is calculated once at the start of the time window and then reused in every implicit time iteration. Default `false`.
132+
`similarity_measure`| Similarity measure to be used for adaptivity. Can be either `L1`, `L2`, `L1rel` or `L2rel`. By default, `L1` is used. The `rel` variants calculate the respective relative norms. This parameter is *optional*. Default `L1`.
133+
`lazy_initialization` | Set to `true` to lazily create and initialize micro simulations. If selected, micro simulation objects are created only when the micro simulation is activated for the first time. Default: `false`.
124134

125135
The primary tuning parameters for adaptivity are the history parameter $$ \Lambda $$, the coarsening constant $$ C_c $$, and the refining constant $$ C_r $$. Their effects can be interpreted as:
126136

@@ -133,15 +143,15 @@ Example of adaptivity configuration is
133143
```json
134144
"simulation_params": {
135145
"macro_domain_bounds": [0, 1, 0, 1, 0, 1],
136-
"adaptivity": "True",
146+
"adaptivity": true,
137147
"adaptivity_settings" {
138148
"type": "local",
139149
"data": ["temperature", "porosity"],
140150
"history_param": 0.5,
141151
"coarsening_constant": 0.3,
142152
"refining_constant": 0.4,
143-
"every_implicit_iteration": "True",
144-
"lazy_initialization": "True"
153+
"every_implicit_iteration": true,
154+
"lazy_initialization": true
145155
}
146156
}
147157
```
@@ -175,9 +185,9 @@ The Micro Manager uses the output functionality of preCICE, hence these data set
175185
## Interpolate a crashed micro simulation
176186

177187
If the optional dependency `sklearn` is installed, the Micro Manager will derive the output of a crashed micro simulation by interpolating outputs from similar simulations. To enable this, set
178-
`"interpolate_crash": "True"` in the `simulation_params` section of the configuration file.
188+
`"interpolate_crash": true` in the `simulation_params` section of the configuration file.
179189

180-
For more details on the interpolation see the [crash handling documentation](tooling-micro-manager-running.html/#what-happens-when-a-micro-simulation-crashes).
190+
For more details on the interpolation see the [crash handling documentation](tooling-micro-manager-running.html#what-happens-when-a-micro-simulation-crashes).
181191

182192
## Next step
183193

docs/installation.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ summary: Install the Micro Manager by running `pip install --user micro-manager-
77

88
## Get the latest Micro Manager release
99

10-
The Micro Manager can be installed using `pip`. Make sure [preCICE](installation-overview.html) is installed before installing the Micro Manager. The Micro Manager is compatible with preCICE version [2.3.0](https://github.com/precice/precice/releases/tag/v2.3.0) and higher.
10+
### Option 1: Install using pip
1111

12-
### Option 1: Install from PyPI
13-
14-
The Micro Manager package has the name [micro-manager-precice](https://pypi.org/project/micro-manager-precice/) on PyPI. To install `micro-manager-precice`, run
12+
The Micro Manager package on PyPI is [micro-manager-precice](https://pypi.org/project/micro-manager-precice/). To install, run
1513

1614
```bash
17-
pip install --user micro-manager-precice
15+
pip install micro-manager-precice
1816
```
1917

20-
Unless already installed, the dependencies will be installed by `pip` during the installation procedure. To enable [crash handling by interpolation](tooling-micro-manager-running.html/#what-happens-when-a-micro-simulation-crashes), the optional dependency `sklearn` is required. To install `micro-manager-precice` with `sklearn`, run
18+
To enable [crash handling by interpolation](tooling-micro-manager-running.html/#what-happens-when-a-micro-simulation-crashes), the optional dependency sklearn is required. To install with sklearn, run
2119

2220
```bash
23-
pip install --user micro-manager-precice[sklearn]
21+
pip install micro-manager-precice[sklearn]
2422
```
2523

26-
preCICE itself needs to be installed separately. If you encounter problems in the direct installation, see the [dependencies section](#required-dependencies) and [optional dependency section](#optional-dependencies) below.
24+
To use the Micro Manager for [snapshot computation](tooling-micro-manager-snapshot-configuration.html), the optional dependency h5py is required. To install with h5py, run
25+
26+
```bash
27+
pip install micro-manager-precice[snapshot]
28+
```
2729

2830
### Option 2: Install manually
2931

@@ -32,10 +34,10 @@ preCICE itself needs to be installed separately. If you encounter problems in th
3234
Ensure that the following dependencies are installed:
3335

3436
* Python 3
35-
* [preCICE](installation-overview.html) [v2.3.0](https://github.com/precice/precice/releases/tag/v2.3.0) or higher
3637
* [pyprecice: Python language bindings for preCICE](installation-bindings-python.html)
3738
* [numpy](https://numpy.org/install/)
3839
* [mpi4py](https://mpi4py.readthedocs.io/en/stable/install.html)
40+
* [psutil](https://psutil.readthedocs.io/en/latest/)
3941

4042
#### Optional dependencies
4143

@@ -53,7 +55,7 @@ git clone https://github.com/precice/micro-manager.git
5355
To install using `pip`, go to the directory `micro-manager/` and run
5456

5557
```bash
56-
pip install --user .
58+
pip install .
5759
```
5860

5961
Adding optional dependencies works as above by adding them after the dot, e.g. `.[sklearn]`.

docs/logging.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Logging in the Micro Manager
3+
permalink: tooling-micro-manager-logging.html
4+
keywords: tooling, macro-micro, two-scale
5+
summary: The Micro Manager logs relevant information and adaptivity metrics.
6+
---
7+
8+
The Micro Manager uses the Python [logging](https://docs.python.org/3/library/logging.html) functionality. The format is:
9+
10+
```bash
11+
(<rank>) <date and time> <part/functionality of Micro Manager> <log level> <message>
12+
```
13+
14+
For example
15+
16+
```bash
17+
(0) 04/17/2025 02:54:02 PM - micro_manager.micro_manager - INFO - Time window 1 converged.
18+
```
19+
20+
The information (`INFO` level) message `Time window 1 converged.` from the file `micro_manager/micro_manager.py` is logged by rank `0` at `02:54:02 PM` on `04/17/2025`.
21+
22+
## Parsing log output
23+
24+
By default, the Micro Manager parses the log output to the terminal (`sys.out`). A log file, for example `micro-manager.log`, can be passed as a command line input in the following way
25+
26+
```bash
27+
micro-manager-precice micro-manager-precice.json micro-manager.log
28+
```
29+
30+
## Logging adaptivity metrics
31+
32+
If the Micro Manager is run with adaptivity, rank-wise and global metrics are written to CSV files. By default, the files are created in the working directory. To create the files in a specific folder, provide the folder path via the configuration parameter `output_dir`. More information is in the [configuration section](tooling-micro-manager-configuration.html).
33+
34+
The following global metrics are logged to the file `adaptivity-metrics-global.csv`:
35+
36+
- Time window at which the metrics are logged
37+
- Average number of active simulations
38+
- Average number of inactive simulations
39+
- Maximum number of active simulations
40+
- Maximum number of inactive simulations
41+
42+
The CSV file heading is `n,avg active,avg inactive,max active,max inactive`.
43+
44+
The following local metrics are logged to the file `adaptivity-metrics-`rank`.csv`:
45+
46+
for local adaptivity:
47+
48+
- Time window at which the metrics are logged
49+
- Number of active simulations
50+
- Number of inactive simulations
51+
52+
The CSV file heading is `n,n active,n inactive`.
53+
54+
for global adaptivity:
55+
56+
- Time window at which the metrics are logged
57+
- Number of active simulations
58+
- Number of inactive simulations
59+
- Ranks to which inactive simulations on this rank are associated
60+
61+
The CSV file heading is `n,n active,n inactive,assoc ranks`.
62+
63+
To set the output interval of adaptivity metrics, set `output_n` in the [adaptivity configuration](tooling-micro-manager-configuration.html#adaptivity).

docs/micro-simulation-convert-to-library.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ The `solve()` function should have the following signature:
9797
This will create a shared library `micro_dummy.so` which can be directly imported in Python.
9898
For more information on compiling C++ libraries, see the [pybind11 documentation](https://pybind11.readthedocs.io/en/stable/compiling.html).
9999

100+
There are more examples which demonstrate how a micro simulation written in C++ is converted to a Python-importable class
101+
102+
1. [DuMuX-based micro simulation](https://github.com/precice/tutorials/blob/v202404.0/two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp) in the two-scale heat conduction tutorial.
103+
2. [pyFANS](https://github.com/DataAnalyticsEngineering/FANS/tree/develop/pyfans).
104+
100105
## Initializing micro simulations
101106

102107
Micro simulations can be initialized before the actual coupling starts. To initialize a micro simulation, define an `initialize()` function in the code. The Micro Manager calls the initialize function for every micro simulation. If the macro simulation writes initial data to preCICE, the Micro Manager attempts to pass it to the micro simulation. If the `initialize()` function does not have input parameters, the initial data will not be passed. The `initialize()` function can return data to the Micro Manager. This data is only relevant to compute the adaptivity before the coupling starts. Therefore, if the `initialize()` functions returns data, it must be the data expected by the adaptivity.

0 commit comments

Comments
 (0)