Skip to content

Commit b2ea0e7

Browse files
committed
added snapshot functionality note
1 parent 92d36b3 commit b2ea0e7

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

models/config.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,45 @@
1515
1616
# Or modify existing
1717
cfg = Config(**{**asdict(PHASE1_CONFIG), 'n_replicates': 30})
18+
19+
20+
21+
NOTE: Saving snapshots of the grid can be implemented with the following logic:
22+
23+
final_grid: cluster analysis verfication for every n_stps.
24+
25+
For Phase 3, save fro all grif sizes
26+
27+
Add to config:
28+
save_final_grid: bool = False
29+
save_grid_timeseries: bool = False # Very costly, use sparingly
30+
grid_timeseries_subsample: int = N # Save every N steps
31+
snapshot_sample_rate: float = 0.0X # Only X% of runs save snapshots
32+
33+
For run_single_simulation():
34+
# After cluster analysis
35+
if cfg.save_final_grid:
36+
# Only save for a sample of runs
37+
if np.random.random() < cfg.snapshot_sample_rate:
38+
result["final_grid"] = model.grid.tolist() # JSON-serializable
39+
40+
# For grid timeseries (use very sparingly):
41+
if cfg.save_grid_timeseries:
42+
grid_snapshots = []
43+
44+
# Inside measurement loop:
45+
if cfg.save_grid_timeseries and step % cfg.grid_timeseries_subsample == 0:
46+
grid_snapshots.append(model.grid.copy())
47+
48+
# After loop:
49+
if cfg.save_grid_timeseries and grid_snapshots:
50+
# Save separately to avoid bloating JSONL
51+
snapshot_path = output_dir / f"snapshots_{seed}.npz"
52+
np.savez_compressed(snapshot_path, grids=np.array(grid_snapshots))
53+
result["snapshot_file"] = str(snapshot_path)
54+
55+
56+
OR create separate snapshot runs using some sort of SNAPSHOT_CONFIG.
1857
"""
1958

2059
from dataclasses import dataclass, field, asdict

0 commit comments

Comments
 (0)