From 9688dc4650dc6ed004803107713d56bbdde8cb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Mon, 11 May 2026 13:24:44 +0200 Subject: [PATCH 1/3] Fix the adaptivity data check --- micro_manager/micro_manager.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/micro_manager/micro_manager.py b/micro_manager/micro_manager.py index 64239a35..d14d0ccb 100644 --- a/micro_manager/micro_manager.py +++ b/micro_manager/micro_manager.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python3micro_manager """ Micro Manager is a tool to initialize and adaptively control micro simulations and couple them via preCICE to a macro simulation. This files the class MicroManager which has the following callable public methods: @@ -742,6 +742,18 @@ def initialize(self) -> None: self._micro_sims[i].initialize() else: # Case where the initialize() method returns data if self._is_adaptivity_on: + # Check for missing data + expected, provided = set(self._data_for_adaptivity.keys()), set(initial_micro_output.keys()) + if missing := expected - provided : + raise Exception( + "The initialize() method needs to return data which is required for the adaptivity calculation. " + f'Of the expected data {", ".join(expected)}, the following is missing: {", ".join(missing)}' + ) + elif extra := provided - expected : + self._logger.log_warning_rank_zero( + f'The initialize() method of the Micro simulation returns extra initial data which isn\'t used by the adaptivity: {", ".join(extra)}' + ) + for name in initial_micro_output.keys(): initial_micro_data[name] = [0] * self._local_number_of_sims # Save initial data from first micro simulation as we anyway have it @@ -753,10 +765,6 @@ def initialize(self) -> None: self._data_for_adaptivity[name][ first_id ] = initial_micro_output[name] - else: - raise Exception( - "The initialize() method needs to return data which is required for the adaptivity calculation." - ) # Gather initial data from the rest of the micro simulations if sim_requires_init_data: From 106186fb3de86a55c3f5ea47ca832832de80eab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Mon, 11 May 2026 14:29:12 +0200 Subject: [PATCH 2/3] Add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc5540f4..9c7b7fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Micro Manager changelog +## latest + +- Allow `initialize()` to return data that is not used by the adaptivity [#261](https://github.com/precice/micro-manager/pull/261) + ## v0.9.0 - Refactored `DomainDecomposer` class and added a new variant of non-uniform decomposition [#243](https://github.com/precice/micro-manager/pull/243) From 2002949f6e1d76defb82a94ef04c1767ff79b4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Mon, 11 May 2026 14:31:33 +0200 Subject: [PATCH 3/3] Format --- micro_manager/micro_manager.py | 48 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/micro_manager/micro_manager.py b/micro_manager/micro_manager.py index d14d0ccb..bbe74d7b 100644 --- a/micro_manager/micro_manager.py +++ b/micro_manager/micro_manager.py @@ -743,16 +743,18 @@ def initialize(self) -> None: else: # Case where the initialize() method returns data if self._is_adaptivity_on: # Check for missing data - expected, provided = set(self._data_for_adaptivity.keys()), set(initial_micro_output.keys()) - if missing := expected - provided : + expected, provided = set(self._data_for_adaptivity.keys()), set( + initial_micro_output.keys() + ) + if missing := expected - provided: raise Exception( - "The initialize() method needs to return data which is required for the adaptivity calculation. " - f'Of the expected data {", ".join(expected)}, the following is missing: {", ".join(missing)}' - ) - elif extra := provided - expected : + "The initialize() method needs to return data which is required for the adaptivity calculation. " + f'Of the expected data {", ".join(expected)}, the following is missing: {", ".join(missing)}' + ) + elif extra := provided - expected: self._logger.log_warning_rank_zero( - f'The initialize() method of the Micro simulation returns extra initial data which isn\'t used by the adaptivity: {", ".join(extra)}' - ) + f'The initialize() method of the Micro simulation returns extra initial data which isn\'t used by the adaptivity: {", ".join(extra)}' + ) for name in initial_micro_output.keys(): initial_micro_data[name] = [0] * self._local_number_of_sims @@ -762,9 +764,9 @@ def initialize(self) -> None: # Save initial data from first micro simulation as we anyway have it for name in initial_micro_output.keys(): if name in self._data_for_adaptivity: - self._data_for_adaptivity[name][ - first_id - ] = initial_micro_output[name] + self._data_for_adaptivity[name][first_id] = ( + initial_micro_output[name] + ) # Gather initial data from the rest of the micro simulations if sim_requires_init_data: @@ -773,17 +775,17 @@ def initialize(self) -> None: initial_macro_data[i] ) for name in self._adaptivity_micro_data_names: - self._data_for_adaptivity[name][ - i - ] = initial_micro_output[name] + self._data_for_adaptivity[name][i] = ( + initial_micro_output[name] + ) initial_micro_data[name][i] = initial_micro_output[name] else: for i in micro_sims_to_init: initial_micro_output = self._micro_sims[i].initialize() for name in self._adaptivity_micro_data_names: - self._data_for_adaptivity[name][ - i - ] = initial_micro_output[name] + self._data_for_adaptivity[name][i] = ( + initial_micro_output[name] + ) initial_micro_data[name][i] = initial_micro_output[name] else: # If adaptivity is off, the returned initial data from the initialize() method will be ignored self._logger.log_warning_rank_zero( @@ -1053,9 +1055,9 @@ def _solve_micro_simulations_with_adaptivity( # Mark the micro sim as active for export micro_sims_output[lid]["Active-State"] = 1 gid = self._global_ids_of_local_sims[lid] - micro_sims_output[lid][ - "Active-Steps" - ] = self._micro_sims_active_steps[gid] + micro_sims_output[lid]["Active-Steps"] = ( + self._micro_sims_active_steps[gid] + ) # If simulation crashes, log the error and keep the output constant at the previous iteration's output except Exception as error_message: @@ -1109,9 +1111,9 @@ def _solve_micro_simulations_with_adaptivity( for inactive_lid in inactive_sim_lids: micro_sims_output[inactive_lid]["Active-State"] = 0 gid = self._global_ids_of_local_sims[inactive_lid] - micro_sims_output[inactive_lid][ - "Active-Steps" - ] = self._micro_sims_active_steps[gid] + micro_sims_output[inactive_lid]["Active-Steps"] = ( + self._micro_sims_active_steps[gid] + ) # Collect micro sim output for adaptivity calculation for i in range(self._local_number_of_sims):