update at 2026-10-12 16:25:51

This commit is contained in:
douboer
2026-10-12 16:25:51 +08:00
parent db63516781
commit a484c7914f
67 changed files with 30357 additions and 193 deletions

View File

@@ -15,9 +15,20 @@ import json
import os
import subprocess
import numpy as np
from .. import ALGO_VERSION
def _json_default(o):
"""ndarray → list;标量 → 原生 float。"""
if isinstance(o, np.ndarray):
return o.tolist()
if isinstance(o, np.generic):
return o.item()
raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable")
def git_hash():
try:
h = subprocess.run(["git", "rev-parse", "--short", "HEAD"],
@@ -82,7 +93,7 @@ def save_run(runs_dir, name, records, figures=None, notes="", seed=None, extra_m
with open(os.path.join(run_dir, "meta.json"), "w") as f:
json.dump(meta, f, ensure_ascii=False, indent=2)
with open(os.path.join(run_dir, "results.json"), "w") as f:
json.dump(results, f, ensure_ascii=False, indent=2, default=float)
json.dump(results, f, ensure_ascii=False, indent=2, default=_json_default)
for fname, fig in (figures or []):
fig.savefig(os.path.join(run_dir, "figures", f"{fname}.svg"))