test: normalize NumPy scalars in space-time receipts

This commit is contained in:
Codex
2026-10-18 08:55:41 -07:00
parent b983c1d095
commit 3496a1e3c1
2 changed files with 44 additions and 1 deletions
@@ -229,6 +229,15 @@ def advance(spec, plan, state, mode="spacetime", mutation=None):
negative_boundary_count=negative_boundary, nonfinite_boundary_count=nonfinite_boundary)
def write_receipt(path, result):
"""Normalize NumPy scalars at the JSON boundary; reject other unknown types."""
def scalar(value):
if isinstance(value, np.generic):
return value.item()
raise TypeError(f"Object of type {type(value).__name__} is not JSON serializable")
path.write_text(json.dumps(result, indent=2, allow_nan=False, default=scalar)+"\n")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--n64", action="store_true", help="explicitly run the frozen 1024-interval experiment")
@@ -267,7 +276,7 @@ def main():
limits=dict(seconds=args.max_seconds,rss_mib=args.max_rss_mib),runs=[],completed=False)
def save():
result["resources"] = dict(seconds=time.monotonic()-started,peak_rss_mib=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024)
args.output.write_text(json.dumps(result,indent=2,allow_nan=False)+"\n")
write_receipt(args.output, result)
save()
try:
for mode in ("constant_ivp", "spacetime"):