Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions mcdc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Loading