Skip to content

Commit 9d893e0

Browse files
authored
Add copy to sim_config in psimulate (#278)
* add copies, make job specific non-overwriting * rever job specific change * fully revert * formatting * add unit test * format * add docstring and comment Ensure that the branch_configuration remains unchanged during simulation configuration. * format * add changelog
1 parent d722f59 commit 9d893e0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**2.1.23 - 10/27/25**
2+
3+
- Bugfix: Deep copy branch_configuration when making sim_config property
4+
15
**2.1.22 - 10/22/25**
26

37
- Bugfix: Move model spec missing error to only raise for run command

src/vivarium_cluster_tools/psimulate/jobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from collections import defaultdict
9+
from copy import deepcopy
910
from pathlib import Path
1011
from typing import Any, NamedTuple
1112

@@ -48,7 +49,7 @@ def job_specific(self) -> dict[str, Any]:
4849
@property
4950
def sim_config(self) -> dict[str, Any]:
5051
"""Parameters for the simulation configuration."""
51-
config = defaultdict(dict, self.branch_configuration)
52+
config = defaultdict(dict, deepcopy(self.branch_configuration))
5253
config["randomness"]["random_seed"] = self.random_seed
5354
config["input_data"]["input_draw_number"] = self.input_draw
5455
return dict(config)

tests/psimulate/test_jobs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from copy import deepcopy
2+
3+
from vivarium_cluster_tools.psimulate.jobs import JobParameters
4+
5+
6+
def test_branch_config_immutable() -> None:
7+
"Test that the branch_configuration doesn't get mutated in place."
8+
original_branch_config = {"foo": "bar", "input_data": {"spam": "eggs"}}
9+
params = JobParameters(
10+
model_specification="model_spec.yaml",
11+
branch_configuration=deepcopy(original_branch_config),
12+
input_draw=0,
13+
random_seed=1,
14+
results_path="results",
15+
backup_configuration={},
16+
extras={},
17+
)
18+
params.sim_config # This was previously causing branch_config to change
19+
assert params.branch_configuration == original_branch_config

0 commit comments

Comments
 (0)