Skip to content

Commit

Permalink
Fix bug in handling of vector data (#143)
Browse files Browse the repository at this point in the history
* Fix bug where the Micro Manager cannot handle vector data provided by a micro simulation object

* Fix YAML syntax error in workflow file

* Fix parallel integration test

* Add debug print statement to see the problem in the GitHub Action log

* More debugging statement to see what it going on in the GitHub Action

* Add correct check for micro_sim_output to ensure that the crash handling unit test passes

* Add Changelog entry
  • Loading branch information
IshaanDesai authored Jan 27, 2025
1 parent a436880 commit c2eefed
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 41 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/run-adaptivity-tests-parallel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Test adaptivity functionality in parallel
on:
push:
branches:
- main
- develop
pull_request:
branches:
- "*"
jobs:
adaptivity_integration_test_parallel:
name: Adaptivity integration test in parallel
runs-on: ubuntu-latest
container: precice/precice:nightly
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: micro-manager

- name: Install sudo for MPI
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install sudo
- name: Use mpi4py
uses: mpi4py/setup-mpi@v1

- name: Install dependencies
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install python3-dev python3-pip git python-is-python3 pkg-config
pip3 install --upgrade pip
- name: Install Micro Manager
working-directory: micro-manager
run: pip3 install .

- name: Run integration test with global adaptivity in parallel
timeout-minutes: 3
working-directory: micro-manager/tests/integration/test_unit_cube
run: |
mpiexec -n 2 --allow-run-as-root micro-manager-precice micro-manager-config-global-adaptivity-parallel.json &
python3 unit_cube.py
adaptivity_unit_tests_parallel:
name: Adaptivity unit tests in parallel
runs-on: ubuntu-latest
container: precice/precice:nightly
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
path: micro-manager

- name: Install sudo for MPI
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install sudo
- name: Use mpi4py
uses: mpi4py/setup-mpi@v1

- name: Install Dependencies
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install python3-dev python3-pip git python-is-python3 pkg-config
pip3 install --upgrade pip
- name: Install Micro Manager
working-directory: micro-manager
run: pip3 install --user .

- name: Run parallel unit tests
working-directory: micro-manager/tests/unit
run: mpiexec -n 2 --allow-run-as-root python3 -m unittest test_adaptivity_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test adaptivity functionality
name: Test adaptivity functionality in serial
on:
push:
branches:
Expand All @@ -9,7 +9,7 @@ on:
- "*"
jobs:
adaptivity_integration_tests:
name: Run adaptivity integration tests
name: Adaptivity integration tests in serial
runs-on: ubuntu-latest
container: precice/precice:nightly
steps:
Expand Down Expand Up @@ -67,37 +67,3 @@ jobs:
- name: Run unit tests
working-directory: micro-manager/tests/unit
run: python3 -m unittest test_adaptivity_serial.py

adaptivity_unit_tests_parallel:
name: Run adaptivity unit tests in parallel
runs-on: ubuntu-latest
container: precice/precice:nightly
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
path: micro-manager

- name: Install sudo for MPI
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install sudo
- name: Use mpi4py
uses: mpi4py/setup-mpi@v1

- name: Install Dependencies
working-directory: micro-manager
run: |
apt-get -qq update
apt-get -qq install python3-dev python3-pip git python-is-python3 pkg-config
pip3 install --upgrade pip
- name: Install Micro Manager
working-directory: micro-manager
run: pip3 install --user .

- name: Run unit tests
working-directory: micro-manager/tests/unit
run: mpiexec -n 2 --allow-run-as-root python3 -m unittest test_adaptivity_parallel.py
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## latest

- Fix bug in handling of vector data returned by the MicroSimulation `solve()` method, for scenarios with adaptivity https://github.com/precice/micro-manager/pull/143
- Remove the `scalar` and `vector` keyword values from data names in configuration https://github.com/precice/micro-manager/pull/142
- Set default logger to stdout and add output directory setting option for file loggers https://github.com/precice/micro-manager/pull/139
- Remove the `adaptivity_data` data structure and handle all adaptivity data internally https://github.com/precice/micro-manager/pull/137
Expand Down
2 changes: 1 addition & 1 deletion micro_manager/adaptivity/adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _get_similarity_dists(

data_diff = np.zeros_like(_similarity_dists)
for name in data.keys():
data_vals = data[name]
data_vals = np.array(data[name])
if data_vals.ndim == 1:
# If the adaptivity data is a scalar for each simulation,
# expand the dimension to make it a 2D array to unify the calculation.
Expand Down
8 changes: 4 additions & 4 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, config_file: str) -> None:
self._is_adaptivity_on = self._config.turn_on_adaptivity()

if self._is_adaptivity_on:
self._data_for_adaptivity: Dict[str, np.ndarray] = dict()
self._data_for_adaptivity: Dict[str, list] = dict()

self._adaptivity_data_names = self._config.get_data_for_adaptivity()

Expand Down Expand Up @@ -357,7 +357,7 @@ def initialize(self) -> None:

if self._is_adaptivity_on:
for name in self._adaptivity_data_names:
self._data_for_adaptivity[name] = np.zeros((self._local_number_of_sims))
self._data_for_adaptivity[name] = [0] * self._local_number_of_sims

# Create lists of local and global IDs
sim_id = np.sum(nms_all_ranks[: self._rank])
Expand Down Expand Up @@ -725,7 +725,7 @@ def _solve_micro_simulations_with_adaptivity(
active_sim_ids = self._adaptivity_controller.get_active_sim_ids()
inactive_sim_ids = self._adaptivity_controller.get_inactive_sim_ids()

micro_sims_output = [None] * self._local_number_of_sims
micro_sims_output = [0] * self._local_number_of_sims

# Solve all active micro simulations
for active_id in active_sim_ids:
Expand Down Expand Up @@ -776,7 +776,7 @@ def _solve_micro_simulations_with_adaptivity(
# Interpolate result for crashed simulation
unset_sims = []
for active_id in active_sim_ids:
if micro_sims_output[active_id] is None:
if micro_sims_output[active_id] == 0:
unset_sims.append(active_id)

# Iterate over all crashed simulations to interpolate output
Expand Down

0 comments on commit c2eefed

Please sign in to comment.