Skip to content

Commit

Permalink
Merge branch 'develop' into load_balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Feb 3, 2025
2 parents 0442b9b + 99c3f2b commit e0edd16
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-adaptivity-tests-parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
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
python3 unit_cube.py 2
adaptivity_unit_tests_parallel:
name: Adaptivity unit tests in parallel
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-adaptivity-tests-serial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ jobs:
working-directory: micro-manager/tests/integration/test_unit_cube
run: |
micro-manager-precice micro-manager-config-local-adaptivity.json &
python3 unit_cube.py
python3 unit_cube.py 2
- name: Run integration test with global adaptivity
timeout-minutes: 3
working-directory: micro-manager/tests/integration/test_unit_cube
run: |
micro-manager-precice micro-manager-config-global-adaptivity.json &
python3 unit_cube.py
python3 unit_cube.py 2
adaptivity_unit_tests_serial:
name: Run adaptivity unit tests in serial
Expand Down
44 changes: 0 additions & 44 deletions .github/workflows/run-domain-decomposition-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,6 @@ on:
branches:
- "*"
jobs:
domain_decomposition_integration_tests:
name: Run domain decomposition integration tests
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 (2 processes)
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-parallel-1.json &
python3 unit_cube.py
- name: Run integration test (6 processes)
timeout-minutes: 3
working-directory: micro-manager/tests/integration/test_unit_cube
run: |
mpiexec -n 6 --oversubscribe --allow-run-as-root micro-manager-precice micro-manager-config-parallel-2.json &
python3 unit_cube.py
domain_decomposition_unit_tests:
name: Run domain decomposition unit tests
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## latest

- Fix bug in the domain decomposition which was returning incorrect bounding box limits for the decomposition of `[2, 2, 1]` and similar https://github.com/precice/micro-manager/pull/146
- Fix bug in calling of the adaptivity computation for explicit coupling scenarios https://github.com/precice/micro-manager/pull/145
- 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
Expand Down
57 changes: 23 additions & 34 deletions micro_manager/domain_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@


class DomainDecomposer:
def __init__(self, dims, rank, size) -> None:
def __init__(self, rank, size) -> None:
"""
Class constructor.
Parameters
----------
dims : int
Dimensions of the problem.
rank : int
MPI rank.
size : int
Total number of MPI processes.
"""
self._rank = rank
self._size = size
self._dims = dims

def decompose_macro_domain(self, macro_bounds: list, ranks_per_axis: list) -> list:
"""
Expand All @@ -48,42 +45,34 @@ def decompose_macro_domain(self, macro_bounds: list, ranks_per_axis: list) -> li
np.prod(ranks_per_axis) == self._size
), "Total number of processors provided in the Micro Manager configuration and in the MPI execution command do not match."

dims = len(ranks_per_axis)

if dims == 3:
for z in range(ranks_per_axis[2]):
for y in range(ranks_per_axis[1]):
for x in range(ranks_per_axis[0]):
n = (
x
+ y * ranks_per_axis[0]
+ z * ranks_per_axis[0] * ranks_per_axis[1]
)
if n == self._rank:
rank_in_axis = [x, y, z]
elif dims == 2:
for y in range(ranks_per_axis[1]):
for x in range(ranks_per_axis[0]):
n = x + y * ranks_per_axis[0]
if n == self._rank:
rank_in_axis = [x, y]

dx = []
for d in range(self._dims):
for d in range(dims):
dx.append(
abs(macro_bounds[d * 2 + 1] - macro_bounds[d * 2]) / ranks_per_axis[d]
)

rank_in_axis: list[int] = [0] * self._dims
if ranks_per_axis[0] == 1: # if serial in x axis
rank_in_axis[0] = 0
else:
rank_in_axis[0] = self._rank % ranks_per_axis[0] # x axis

if self._dims == 2:
if ranks_per_axis[1] == 1: # if serial in y axis
rank_in_axis[1] = 0
else:
rank_in_axis[1] = int(self._rank / ranks_per_axis[0]) # y axis
elif self._dims == 3:
if ranks_per_axis[2] == 1: # if serial in z axis
rank_in_axis[2] = 0
else:
rank_in_axis[2] = int(
self._rank / (ranks_per_axis[0] * ranks_per_axis[1])
) # z axis

if ranks_per_axis[1] == 1: # if serial in y axis
rank_in_axis[1] = 0
else:
rank_in_axis[1] = (
self._rank - ranks_per_axis[0] * ranks_per_axis[1] * rank_in_axis[2]
) % ranks_per_axis[
2
] # y axis

mesh_bounds = []
for d in range(self._dims):
for d in range(dims):
if rank_in_axis[d] > 0:
mesh_bounds.append(macro_bounds[d * 2] + rank_in_axis[d] * dx[d])
mesh_bounds.append(macro_bounds[d * 2] + (rank_in_axis[d] + 1) * dx[d])
Expand Down
50 changes: 25 additions & 25 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def solve(self) -> None:
)

adaptivity_cpu_time = 0.0
first_iteration = True

while self._participant.is_coupling_ongoing():

Expand All @@ -184,30 +185,29 @@ def solve(self) -> None:
sim_states_cp[i] = self._micro_sims[i].get_state()
t_checkpoint = t
n_checkpoint = n
first_iteration = True

if self._is_adaptivity_on:
if not self._adaptivity_in_every_implicit_step:
start_time = time.process_time()
self._adaptivity_controller.compute_adaptivity(
dt,
self._micro_sims,
self._data_for_adaptivity,
)
if self._is_adaptivity_on:
if self._adaptivity_in_every_implicit_step or first_iteration:
start_time = time.process_time()
self._adaptivity_controller.compute_adaptivity(
dt,
self._micro_sims,
self._data_for_adaptivity,
)

end_time = time.process_time()
end_time = time.process_time()

adaptivity_cpu_time = end_time - start_time
adaptivity_cpu_time = end_time - start_time

# Only checkpoint the adaptivity configuration if adaptivity is computed
# once in every time window
self._adaptivity_controller.write_checkpoint()
# Only checkpoint the adaptivity configuration if adaptivity is computed
# once in every time window
self._adaptivity_controller.write_checkpoint()

active_sim_ids = (
self._adaptivity_controller.get_active_sim_ids()
)
active_sim_ids = self._adaptivity_controller.get_active_sim_ids()

for active_id in active_sim_ids:
self._micro_sims_active_steps[active_id] += 1
for active_id in active_sim_ids:
self._micro_sims_active_steps[active_id] += 1

if self._is_adaptivity_with_load_balancing:
if n % self._load_balancing_n == 0:
Expand Down Expand Up @@ -258,6 +258,7 @@ def solve(self) -> None:
self._micro_sims[i].set_state(sim_states_cp[i])
n = n_checkpoint
t = t_checkpoint
first_iteration = False

# If adaptivity is computed only once per time window, the states of sims need to be reset too
if self._is_adaptivity_on:
Expand Down Expand Up @@ -296,9 +297,13 @@ def initialize(self) -> None:
assert len(self._macro_bounds) / 2 == self._participant.get_mesh_dimensions(
self._macro_mesh_name
), "Provided macro mesh bounds are of incorrect dimension"

if self._is_parallel:
assert len(self._ranks_per_axis) == self._participant.get_mesh_dimensions(
self._macro_mesh_name
), "Provided ranks combination is of incorrect dimension"

domain_decomposer = DomainDecomposer(
self._participant.get_mesh_dimensions(self._macro_mesh_name),
self._rank,
self._size,
)
Expand Down Expand Up @@ -498,12 +503,7 @@ def initialize(self) -> None:

if is_initial_data_required and not is_initial_data_available:
raise Exception(
"The initialize() method of the Micro simulation requires initial data, but no initial data has been provided."
)

if not is_initial_data_required and is_initial_data_available:
warn(
"The initialize() method is only allowed to return data which is required for the adaptivity calculation."
"The initialize() method of the Micro simulation requires initial data, but no initial macro data has been provided."
)

# Get initial data from micro simulations if initialize() method exists
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/test_unit_cube/clean-test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
rm -fv *-events-summary.json
rm -fv *-events.json
rm -fv *.log
rm -r -fv precice-run/
rm -r -fv precice-profiling/
rm -rfv precice-run/ precice-profiling/
rm -fv *.vtk
rm -fv *.out
rm -fv *.err
rm -fv output/*.vtu
rm -fv output/*.pvtu
rm -r -fv __pycache__
rm -rfv __pycache__ output/ .venv/ adaptivity_output/
rm -fv *.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"coupling_params": {
"precice_config_file_name": "precice-config.xml",
"macro_mesh_name": "macro-cube-mesh",
"read_data_names": ["macro-scalar-data", "macro-vector-data"],
"write_data_names": ["micro-scalar-data", "micro-vector-data"]
"write_data_names": ["micro-data-1", "micro-data-2"],
"read_data_names": ["macro-data-1"]
},
"simulation_params": {
"micro_dt": 1.0,
Expand All @@ -14,11 +14,11 @@
"adaptivity": "True",
"adaptivity_settings": {
"type": "global",
"data": ["macro-scalar-data", "micro-vector-data"],
"history_param": 0.5,
"data": ["micro-data-1", "micro-data-2"],
"history_param": 1.0,
"coarsening_constant": 0.3,
"refining_constant": 0.4,
"every_implicit_iteration": "True",
"every_implicit_iteration": "False",
"output_cpu_time": "True"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"coupling_params": {
"precice_config_file_name": "precice-config.xml",
"macro_mesh_name": "macro-cube-mesh",
"read_data_names": ["macro-scalar-data", "macro-vector-data"],
"write_data_names": ["micro-scalar-data", "micro-vector-data"]
"write_data_names": ["micro-data-1", "micro-data-2"],
"read_data_names": ["macro-data-1"]
},
"simulation_params": {
"micro_dt": 1.0,
"macro_domain_bounds": [0, 1, 0, 1, 0, 1],
"adaptivity": "True",
"adaptivity_settings": {
"type": "global",
"data": ["macro-scalar-data", "macro-vector-data"],
"data": ["micro-data-1", "micro-data-2"],
"history_param": 0.5,
"coarsening_constant": 0.3,
"refining_constant": 0.4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"coupling_params": {
"precice_config_file_name": "precice-config.xml",
"macro_mesh_name": "macro-cube-mesh",
"read_data_names": ["macro-scalar-data", "macro-vector-data"],
"write_data_names": ["micro-scalar-data", "micro-vector-data"]
"write_data_names": ["micro-data-1", "micro-data-2"],
"read_data_names": ["macro-data-1"]
},
"simulation_params": {
"micro_dt": 1.0,
"macro_domain_bounds": [0, 1, 0, 1, 0, 1],
"adaptivity": "True",
"adaptivity_settings": {
"type": "local",
"data": ["macro-scalar-data", "macro-vector-data"],
"data": ["micro-data-1", "micro-data-2"],
"history_param": 0.5,
"coarsening_constant": 0.3,
"refining_constant": 0.4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"coupling_params": {
"precice_config_file_name": "precice-config.xml",
"macro_mesh_name": "macro-cube-mesh",
"read_data_names": ["macro-scalar-data", "macro-vector-data"],
"write_data_names": ["micro-scalar-data", "micro-vector-data"]
"write_data_names": ["micro-data-1", "micro-data-2"],
"read_data_names": ["macro-data-1"]
},
"simulation_params": {
"micro_dt": 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"coupling_params": {
"precice_config_file_name": "precice-config.xml",
"macro_mesh_name": "macro-cube-mesh",
"read_data_names": ["macro-scalar-data", "macro-vector-data"],
"write_data_names": ["micro-scalar-data", "micro-vector-data"]
"write_data_names": ["micro-data-1", "micro-data-2"],
"read_data_names": ["macro-data-1"]
},
"simulation_params": {
"micro_dt": 1.0,
Expand Down
Loading

0 comments on commit e0edd16

Please sign in to comment.