polycode-sim/experiments.py
tegwick a8e4f03172
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 2s
Complete POLYCODE-WP-0002 simulator v0.1 scaffold
2026-07-08 15:21:15 +02:00

47 lines
No EOL
1.3 KiB
Python

#!/usr/bin/env python3
"""Tiny parameter sweep for PolyCode Simulator v0.1."""
from __future__ import annotations
import json
from copy import deepcopy
from datetime import UTC, datetime
from pathlib import Path
from simulator import load_params, run_simulation
def sweep(thresholds: list[float] | None = None) -> list[dict]:
thresholds = thresholds or [300.0, 400.0, 500.0]
rows: list[dict] = []
base = load_params()
for threshold in thresholds:
params = deepcopy(base)
params["funding_threshold"] = threshold
summary = run_simulation(params)
rows.append(
{
"funding_threshold": threshold,
"acceptance_rate": summary.acceptance_rate,
"accepted": summary.accepted,
"rejected": summary.rejected,
"total_funded": summary.total_funded,
}
)
return rows
def main() -> None:
rows = sweep()
out_dir = Path("runs")
out_dir.mkdir(exist_ok=True)
stamp = datetime.now(UTC).strftime("%Y%m%dT%H%M%SZ")
path = out_dir / f"sweep-{stamp}.json"
path.write_text(json.dumps({"sweep": rows}, indent=2), encoding="utf-8")
print("Sweep results:")
for row in rows:
print(row)
print(f"output: {path}")
if __name__ == "__main__":
main()