diff --git a/CHANGELOG.md b/CHANGELOG.md index 53ede1235..72ce154ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/2.0.0/), ### Added +- Add overriding option N_active, from [@ilhamv] + ### Changed - Show previously published documentation versions in the documentation version switcher, from [@ilhamv] diff --git a/mcdc/config.py b/mcdc/config.py index ec42c2db7..d841ea567 100644 --- a/mcdc/config.py +++ b/mcdc/config.py @@ -36,6 +36,7 @@ def _build_parser() -> argparse.ArgumentParser: # Simulation-setting overrides parser.add_argument("--N_particle", type=int, help="Number of particles") parser.add_argument("--N_batch", type=int, help="Number of batches") + parser.add_argument("--N_active", type=int, help="Number of active cycles") parser.add_argument("--output", type=str, help="Output file name") parser.add_argument("--progress_bar", default=True, action="store_true") parser.add_argument("--no-progress_bar", dest="progress_bar", action="store_false") @@ -133,6 +134,9 @@ def set_setting(name, value): # These command-line options directly replace public Simulation settings. set_setting("N_particle", args.N_particle) set_setting("N_batch", args.N_batch) + if args.N_active is not None: + set_setting("N_active", args.N_active) + set_setting("N_cycle", settings.N_inactive + settings.N_active) set_setting("output_name", args.output) set_setting("use_progress_bar", args.progress_bar) diff --git a/test/unit/test_config.py b/test/unit/test_config.py index 74636bdd6..547499d75 100644 --- a/test/unit/test_config.py +++ b/test/unit/test_config.py @@ -10,6 +10,12 @@ from mcdc.config import _build_parser, override_settings +def test_parser_accepts_active_cycle_override(): + args = _build_parser().parse_args(["--N_active", "25"]) + + assert args.N_active == 25 + + class SingleRankCommunicator: def __init__(self, size=1): self.size = size @@ -105,6 +111,7 @@ def test_compilation_applies_command_line_overrides(monkeypatch): monkeypatch.setattr(config, "target", "cpu") monkeypatch.setattr(config.args, "N_particle", 100) monkeypatch.setattr(config.args, "N_batch", None) + monkeypatch.setattr(config.args, "N_active", None) monkeypatch.setattr(config.args, "output", None) monkeypatch.setattr( config.args, "progress_bar", simulation.settings.use_progress_bar @@ -114,3 +121,21 @@ def test_compilation_applies_command_line_overrides(monkeypatch): assert simulation.settings.N_particle == 100 assert not override_settings(simulation) + + +def test_active_cycle_override_updates_total_cycles(monkeypatch): + simulation = mcdc.Simulation() + simulation.settings.set_eigenmode(N_inactive=5, N_active=10) + + monkeypatch.setattr(config, "target", "cpu") + monkeypatch.setattr(config.args, "N_particle", None) + monkeypatch.setattr(config.args, "N_batch", None) + monkeypatch.setattr(config.args, "N_active", 25) + monkeypatch.setattr(config.args, "output", None) + monkeypatch.setattr( + config.args, "progress_bar", simulation.settings.use_progress_bar + ) + + assert override_settings(simulation) + assert simulation.settings.N_active == 25 + assert simulation.settings.N_cycle == 30