Skip to content

Commit

Permalink
Fix tests and add CHANGELOG entry
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Nov 7, 2024
1 parent 5fcf75b commit 10f434b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
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

- Improve logging by wrapping Python logger in a class https://github.com/precice/micro-manager/pull/133
- Add information about adaptivity tuning parameters https://github.com/precice/micro-manager/pull/131
- Put computation of counting active steps inside the adaptivity variant `if` condition https://github.com/precice/micro-manager/pull/130

Expand Down
4 changes: 2 additions & 2 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def _solve_micro_simulations(self, micro_sims_input: list, dt: float) -> list:
self._mesh_vertex_coords[count], micro_sims_input[count]
)
)
self._logger.error(error_message)
self._logger.log_error_any_rank(error_message)
self._has_sim_crashed[count] = True

# If interpolate is off, terminate after crash
Expand Down Expand Up @@ -782,7 +782,7 @@ def _solve_micro_simulations_with_adaptivity(
self._mesh_vertex_coords[active_id]
)
)
self._logger.error(error_message)
self._logger.log_error_any_rank(error_message)
self._has_sim_crashed[active_id] = True

# If interpolate is off, terminate after crash
Expand Down
6 changes: 4 additions & 2 deletions micro_manager/tools/logging_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(self, name, log_file, rank=0, level=logging.INFO):
handler.setLevel(level)

formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
"["
+ str(self._rank)
+ "] %(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)

Expand Down Expand Up @@ -81,4 +83,4 @@ def log_error_any_rank(self, message):
message : string
Message to log.
"""
self._logger.error("[" + str(self._rank) + "] " + message)
self._logger.error(message)
6 changes: 3 additions & 3 deletions tests/unit/test_adaptivity_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_update_inactive_sims_global_adaptivity(self):
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = GlobalAdaptivityCalculator(
configurator, MagicMock(), 5, global_ids, rank=self._rank, comm=self._comm
configurator, 5, global_ids, rank=self._rank, comm=self._comm
)

# Force the activation of sim #0 and #4
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_update_all_active_sims_global_adaptivity(self):
configurator.get_adaptivity_coarsening_const = MagicMock(return_value=0.2)
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L2rel")
adaptivity_controller = GlobalAdaptivityCalculator(
configurator, MagicMock(), 5, global_ids, rank=self._rank, comm=self._comm
configurator, 5, global_ids, rank=self._rank, comm=self._comm
)

adaptivity_controller._adaptivity_data_names = {
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_communicate_micro_output(self):
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = GlobalAdaptivityCalculator(
configurator, MagicMock(), 5, global_ids, rank=self._rank, comm=self._comm
configurator, 5, global_ids, rank=self._rank, comm=self._comm
)

adaptivity_controller.communicate_micro_output(
Expand Down
13 changes: 5 additions & 8 deletions tests/unit/test_adaptivity_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_get_similarity_dists(self):
"""
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = AdaptivityCalculator(configurator, logger=MagicMock())
adaptivity_controller = AdaptivityCalculator(configurator)
adaptivity_controller._hist_param = 0.5
adaptivity_controller._adaptivity_data_names = [
"micro-scalar-data",
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_update_active_sims(self):
"""
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = AdaptivityCalculator(configurator, logger=MagicMock())
adaptivity_controller = AdaptivityCalculator(configurator)
adaptivity_controller._refine_const = self._refine_const
adaptivity_controller._coarse_const = self._coarse_const
adaptivity_controller._adaptivity_data_names = [
Expand All @@ -127,8 +127,7 @@ def test_adaptivity_norms(self):
"""
Test functionality for calculating similarity criteria between pairs of simulations using different norms in class AdaptivityCalculator.
"""
logger = MagicMock()
calc = AdaptivityCalculator(Config(logger, "micro-manager-config.json"), logger)
calc = AdaptivityCalculator(Config("micro-manager-config.json"))

fake_data = np.array([[1], [2], [3]])
self.assertTrue(
Expand Down Expand Up @@ -209,7 +208,7 @@ def test_associate_active_to_inactive(self):
"""
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = AdaptivityCalculator(configurator, logger=MagicMock())
adaptivity_controller = AdaptivityCalculator(configurator)
adaptivity_controller._refine_const = self._refine_const
adaptivity_controller._coarse_const = self._coarse_const
adaptivity_controller._adaptivity_data_names = [
Expand All @@ -236,9 +235,7 @@ def test_update_inactive_sims_local_adaptivity(self):
"""
configurator = MagicMock()
configurator.get_adaptivity_similarity_measure = MagicMock(return_value="L1")
adaptivity_controller = LocalAdaptivityCalculator(
configurator, logger=MagicMock()
)
adaptivity_controller = LocalAdaptivityCalculator(configurator)
adaptivity_controller._refine_const = self._refine_const
adaptivity_controller._coarse_const = self._coarse_const
adaptivity_controller._adaptivity_data_names = [
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_config(self):
"""
Test if the functions in the Config class work.
"""
config = micro_manager.Config(MagicMock(), "micro-manager-config.json")
config = micro_manager.Config("micro-manager-config.json")
config.read_json_micro_manager()
self.assertEqual(config._config_file_name.split("/")[-1], "dummy-config.xml")
self.assertEqual(config._micro_file_name, "test_micro_manager")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_snapshot_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_config(self):
"""
Test if the functions in the SnapshotConfig class work.
"""
config = Config(MagicMock(), "snapshot-config.json")
config = Config("snapshot-config.json")
config.read_json_snapshot()

self.assertEqual(
Expand Down

0 comments on commit 10f434b

Please sign in to comment.