darkcommon.py — src/32-dark

The script src/32-dark/darkcommon.py of the validation package of the paper 32-dark, rendered with an anchor per line. ▶ run the predicates on Google Colab.

32-dark ledgersrc/32-dark/darkcommon.py · 22.1 KBdarkcommon.pyColab
1"""2darkcommon.py — shared registry for the 32-dark validation package3===================================================================4"The Dark Sector over Finite Relational Substrate" (Akhtman, Geifman & Voether, 2026), validation package of the FRC5corpus (finite-ring-space/src/32-dark). The paper's twelve validation scripts and the figure script are kept as6written — four print a verdict (flux_exact, born_exact, deep_regime_fp, rar_scatter), the rest print their values —7and run here through one registry: a *family* is one script (identified as dark.<stem>, e.g. dark.interpolation), run8in its own namespace inside out/ (its figures and deep.json land there, the paper's two figures in figures/; every saved figure gets a PNG sibling, shown inline in the notebook), its9printed verdict lines captured; its micro-checks are those lines together with the registry's predicates (PRED10below), which read the script's namespace and output and decide the manuscript's stated values explicitly — the11exact Gauss law and the amplitude identity recomputed, the slopes 1.03/1.11 and the exact slope 1, the discriminant120.051 at x = 5.2 and the two pinning checks, the first-passage reduction with rel.err/s → 1/6, the SPARC scatter130.038 dex and the bound δα ≲ 3.5°, the prediction numerals. An exception, a nonzero exit or a failed predicate14fails the family. Each family names the row(s) of the paper's predicate ledger it witnesses (LEDGER; rows cited as1532:XN), and the ledger's source column cites the family ids in return. rar_shape.py, the named test of row B8 owed16by the paper's Appendix A, is added here (the binned relation from data/RAR.mrt).1718Kinds, recorded per family: EXACT — exact rationals, Z[i], or 60-digit identities, no tolerance in the verdict;19SIM — a seeded stochastic simulation (the noisy link, the killed walk), verdict by stated tolerance; CHART — a20continuum reading or a comparison with data (the interpolation, the RAR/BTFR, the SPARC scatter, the predictions,21the cluster law's illustration), tagged [approx] in the paper, verdict by stated tolerance.2223Master-ledger rows of the corpus sourced from this paper: 00:L1 (the floor a0 = cH0/2pi and the RAR's barrier identification,2432:B8, C2, C4-C6), 00:L7 (the running floor a0(z), 32:P1), 00:Z7 (the running's normalisation, 32:Y2 and the predictions),2500:D3 (distance is decoherence, 32:B1), 00:N1 (the exclusion predictions, 32:P6), 00:N2 (parameter-freeness, 32:C2).26"""27import io, json, os, re, sys, time, traceback, math28from fractions import Fraction as Fr2930RESULTS = []31MICRO = []                    # (family, label, ok)32HERE = os.path.dirname(os.path.abspath(__file__))3334# family -> paper rows witnessed35LEDGER = {36    "dark.flux_exact":          "32:C1, 32:X1",37    "dark.born_exact":          "32:C3, 32:C7",38    "dark.firstpassage_finite": "32:B8, 32:C7",39    "dark.meridian_walk":       "32:B8, 32:C6, 32:C7",40    "dark.deep_regime":         "32:C4",41    "dark.deep_regime_fp":      "32:C4",42    "dark.interpolation":       "32:B8, 32:C6, 32:X4",43    "dark.rar_shape":           "32:B8, 32:C2, 32:C6",44    "dark.deep_mond":           "32:C2, 32:C4, 32:C5, 32:X2, 32:X3",45    "dark.rar_scatter":         "32:C8, 32:P2, 32:X5, 32:Y1, 32:Y2",46    "dark.cluster_coherent":    "32:C10, 32:X7, 32:X8, 32:Y1",47    "dark.predictions":         "32:P1, 32:P2, 32:P3, 32:P4",48    "dark.make_figures":        "32:V2",49}5051KIND = {f: "CHART" for f in LEDGER}52for f in ("dark.flux_exact", "dark.born_exact", "dark.firstpassage_finite"):53    KIND[f] = "EXACT"54for f in ("dark.deep_regime", "dark.meridian_walk"):55    KIND[f] = "SIM"5657LABELS = {58    "dark.flux_exact": "the discrete Gauss law of the synchronisation flux in exact rationals on the 5³ box: a unit point source gives unit flux through both enclosing surfaces, a source-free noise field gives zero, their superposition gives one — Newton's law as the high-acceleration reading",59    "dark.born_exact": "amplitude = √count, exact in Z[i]: n aligned unit phasors have |Σ|² = n² (coherent, amplitude n) and the mean of |Σ|² over all sign patterns is n (incoherent, amplitude √n) for n up to 10 — the cross-term cancellation that forces the deep-regime square root",60    "dark.firstpassage_finite": "the finite-cycle first-passage law at 60 digits: the single-step identity f(e^(−s)) = e^(−arccosh e^s); the reduction arccosh(e^s) = √(2s)(1 + s/6 + …) with rel.err/s → 1/6, carrier-exact to ~10⁻⁶¹ at s ~ Ω^(−1/2); the wrap correction of the killed walk on Z_N against the infinite line, O(e^(−(N−a) arccosh e^s))",61    "dark.meridian_walk": "the meridian killed walk: the exact rational discriminant 1 − z² of the first-passage quadratic; the simulated escape probability against e^(−a√(2s)) (seeded); the assembled resolved fraction 1 − e^(−√x) with deep slope 1/2 (the RAR fit form); the mechanism figure",62    "dark.deep_regime": "the noisy Kuramoto (Adler) link dφ = (T − sin φ)dt + √(2D) dW, seeded: the mean response is Newtonian at every noise level (deep slopes 1.03 at D = 0.3 and 1.11 at D = 0.6, the boost constant to rising) — the √ law is registration, not force modification; deep.json and the figure",63    "dark.deep_regime_fp": "the stationary Fokker–Planck solution of the same link: the small-tilt log-slope exactly 1 at D = 0.3 and 0.6 (within 2 × 10⁻³), the boost constant to rising; no √ regime in the mean force",64    "dark.interpolation": "the interpolation from the rotation angle: deep slope 1/2 and Newtonian slope 1; the discriminant against the simple rational form, maximum 0.051 in g_obs/g_b at x = 5.2; the two pinning checks of B8 (a barrier κx^β gives deep slope 1 − β; the knee at 1/κ²); the chart angle sin²α = e^(−√x); the figure",65    "dark.rar_shape": "the named test of B8 against the binned radial acceleration relation (data/RAR.mrt, 0.2-dex bins, the bin scatter as uncertainty): the exponential form's free a₀ within 10 % of the RAR fit 1.20 × 10⁻¹⁰ and below the simple form in χ²; in the band 2 < x < 10 the departure from the exponential form is within the bin scatter in every bin and the rational form has the larger χ²; the floor cH₀/2π 5–25 % below the free fit (the paper's 13 %) [approx]",66    "dark.deep_mond": "the two-chart Gauss law: a₀ = cH₀/2π = 1.042 × 10⁻¹⁰ at H₀ = 67.4; the RAR deep-regime slope 1/2 and the BTFR slope 1/4 (v⁴ = GMa₀, 5 × 10¹⁰ M⊙ → 162 km/s); the exponential-disk rotation curve flattening at the registered speed; the figure [approx]",67    "dark.rar_scatter": "the SPARC residual test at fixed a₀ = cH₀/2π: intrinsic scatter 0.038 dex overall, 0.04 at the knee, rising to ≈ 0.13 at x ≈ 0.02; the two-variable law bounding δα ≲ 3.5° (σ_v/v = 0.1–0.2 excluded, Y2); no correlation of the within-galaxy scatter with 1/V_flat over 116 disks (ρ = −0.02); a gas–disk–bulge amplitude sum would boost the RAR by 0.14 dex (Y1's within-galaxy constraint); ν(0.1) = 3.69 [approx, data]",68    "dark.cluster_coherent": "the coherence-matrix amplitude law: N_eff = (Σ√g)²/Σg equals N for equal components and is suppressed by a dominant BCG (4:1:1 → 2.67); the core boost √N_eff with N_core = 6 (2.45) decaying to 1 by ~Mpc in the illustrative radial profile — the Bullet selection (C → 0) and the core addition (C → 1) in one law, the factor-two closure a conjecture (Y1) [illustrative]",69    "dark.predictions": "the falsifiable predictions computed: a₀(z) = cH(z)/2π with v_flat ∝ E(z)^(1/4) (+7 %, +15 %, +31 % at z = 0.5, 1, 2); the two-variable scatter law σ(x, σ_v/v) (0.27 dex at x = 0.01, σ_v/v = 0.1); the wide-binary velocity enhancement with the Galactic external field 1.8a₀ (√ν − 1 = 12–16 % at 10–40 kAU, the paper's 10–30 %); the pressure-supported coherence offset √w (−0.05 to −0.15 dex for σ_v/v = 0.5–1) [approx]",70    "dark.make_figures": "the paper's two figures regenerated (fig_rar.pdf: the RAR with the rational alternative and the exponential-disk rotation curve; fig_mechanism.pdf: the first-passage collapse and the chart angle), written to figures/",71}7273def script_of(fam):74    return fam.split(".")[1]            # dark.<stem> runs <stem>.py7576_CUR = [None]7778def chk(label, ok):79    """A labelled micro-check, recorded under the running family."""80    ok = bool(ok)81    MICRO.append((_CUR[0], str(label), ok))82    print(("PASS " if ok else "FAIL ") + str(label))8384class _Exit(Exception):85    def __init__(self, code): self.code = code8687def _out(name):88    """A file the script wrote into out/ (the scripts run with out/ as the working directory)."""89    return os.path.exists(os.path.join(HERE, "out", name))9091def _show_pngs(pngs):92    """Inside a notebook, display the PNG copies of the figures a script saved; a no-op under plain python."""93    try:94        from IPython.display import display, Image95        get_ipython()                                     # NameError outside IPython96    except Exception:97        return98    for p in pngs:99        display(Image(filename=p))100101102103# ----------------------------------------------------------------------------------------------------------------104# the registry's predicates: fam -> function(ns, out) making chk calls on the script's namespace / printed output105# ----------------------------------------------------------------------------------------------------------------106def _pred_flux(ns, out):107    flux, Us, Un, Usn = ns["flux"], ns["Us"], ns["Un"], ns["Usn"]108    chk("unit point source: flux = 1 exactly through the R = 0 and R = 1 surfaces", flux(Us, 0) == Fr(1) and flux(Us, 1) == Fr(1))109    chk("source-free noise field: flux = 0 exactly", flux(Un, 1) == Fr(0))110    chk("source + noise: flux = 1 exactly (superposition)", flux(Usn, 1) == Fr(1))111112def _pred_born(ns, out):113    add, norm2, units, msq = ns["add"], ns["norm2"], ns["units"], ns["mean_sq_pm"]114    ok = True115    for n in range(1, 11):116        s = (0, 0)117        for _ in range(n): s = add(s, units[0])118        ok &= norm2(s) == n * n119    chk("coherent stack: |Σ|² = n² exactly for n = 1 … 10", ok)120    chk("incoherent ensemble: ⟨|Σ|²⟩ = n exactly over all sign patterns for n = 1 … 10", all(msq(n) == Fr(n) for n in range(1, 11)))121122def _pred_fp(ns, out):123    mp = ns["mp"]124    z = mp.e ** (-mp.mpf("0.1")); f = (1 - mp.sqrt(1 - z ** 2)) / z; g = mp.e ** (-mp.acosh(mp.e ** mp.mpf("0.1")))125    chk("f(e^(−s)) = e^(−arccosh e^s) at s = 0.1 to 50 digits", abs(f - g) < mp.mpf("1e-50"))126    s = mp.mpf("1e-4"); rel = (mp.acosh(mp.e ** s) - mp.sqrt(2 * s)) / mp.sqrt(2 * s)127    chk(f"rel.err/s = {mp.nstr(rel / s, 6)} → 1/6 at s = 10⁻⁴", abs(rel / s - mp.mpf(1) / 6) < mp.mpf("1e-4"))128    ec = ns["escape_cycle"](200, 8, mp.e ** (-mp.mpf("0.02"))); el = ns["escape_line"](8, mp.e ** (-mp.mpf("0.02")))129    chk(f"finite cycle N = 200, a = 8, s = 0.02: |cycle − line| = {mp.nstr(abs(ec - el), 3)} < 10⁻¹⁵ (the wrap correction)", abs(ec - el) < mp.mpf("1e-15"))130131def _pred_walk(ns, out):132    z = Fr(3, 5); f = (1 - Fr(4, 5)) / z                      # 1 − z² = 16/25 a rational square: f1 = 1/3 exactly133    chk("the first-passage quadratic (z/2)f² − f + z/2 = 0 holds exactly at z = 3/5 with f = (1 − √(1 − z²))/z = 1/3", z / 2 * f * f - f + z / 2 == 0 and f == Fr(1, 3))134    P = ns["escape_prob"](5, 0.02, seed=5 * 100 + 20); u = 5 * math.sqrt(0.04)135    chk(f"seeded walk a = 5, q = 0.02: P_escape = {P:.3f} against e^(−a√(2q)) = {math.exp(-u):.3f} within 0.03", abs(P - math.exp(-u)) < 0.03)136    chk(f"deep slope of g_obs = g_b/(1 − e^(−√x)) below x = 10⁻² is {ns['sl']:.3f} (→ 1/2)", abs(ns["sl"] - 0.5) < 0.03)137    chk("the figure written (cons3_firstpassage.pdf, .png)", _out("cons3_firstpassage.pdf") and _out("cons3_firstpassage.png"))138139def _pred_deep(ns, out):140    o = ns["out"]141    chk(f"D = 0.3: deep slope {o[0.3]['slope']:.3f} (the paper's 1.03)", abs(o[0.3]["slope"] - 1.03) < 0.02)142    chk(f"D = 0.6: deep slope {o[0.6]['slope']:.3f} (the paper's 1.11)", abs(o[0.6]["slope"] - 1.11) < 0.02)143    chk("the boost g_eff/g_N is constant to rising at both D (no √ regime)", all(all(b2 >= b1 - 0.05 for b1, b2 in zip(o[D]["boost"], o[D]["boost"][1:])) for D in (0.3, 0.6)))144    chk("deep.json and the figure written (cons1_deepregime.pdf, .png)", _out("deep.json") and _out("cons1_deepregime.pdf") and _out("cons1_deepregime.png"))145146def _pred_deep_fp(ns, out):147    chk("the script's verdict: mean response Newtonian (slope 1 within 2 × 10⁻³) at D = 0.3 and 0.6, boost constant to rising", ns["ok"])148    m = re.findall(r"log-slope d ln g_eff/d ln g_N = ([0-9.]+)", out)149    chk(f"the two slopes {m} within 2 × 10⁻³ of 1", len(m) == 2 and all(abs(float(v) - 1) < 2e-3 for v in m))150151def _pred_interp(ns, out):152    chk(f"deep slope {ns['sl_deep']:.3f} → 1/2 and Newtonian slope {ns['sl_newt']:.3f} → 1", abs(ns["sl_deep"] - 0.5) < 0.02 and abs(ns["sl_newt"] - 1.0) < 0.02)153    d, x, i = ns["d"], ns["x"], ns["i"]154    chk(f"the discriminant ν_simple − ν_frc peaks at {d[i]:.4f} at x = {x[i]:.2f} (the paper's 0.051 at 5.2)", abs(d[i] - 0.051) < 0.002 and abs(x[i] - 5.2) < 0.2)155    np = ns["np"]; xd = ns["xd"]; nu_gen = ns["nu_gen"]156    chk("pinning check 1: a barrier κx^β gives deep slope 1 − β for β = 0.4, 0.5, 0.6", all(abs(np.polyfit(np.log(xd), np.log(xd * nu_gen(xd, 1.0, b)), 1)[0] - (1 - b)) < 0.02 for b in (0.4, 0.5, 0.6)))157    knees = re.findall(r"knee \(nu = nu_frc\(1\)\) at x = ([0-9.]+)\s+vs 1/kappa\^2 = ([0-9.]+)", out)158    chk(f"pinning check 2: the knee sits at 1/κ² for κ = 1, 0.93, 1.1 ({len(knees)} cases)", len(knees) == 3 and all(abs(float(a) - float(b)) < 0.01 for a, b in knees))159    chk("the figure written (cons3_interpolation.pdf, .png)", _out("cons3_interpolation.pdf") and _out("cons3_interpolation.png"))160161def _pred_rar_shape(ns, out):162    chk(f"the script's own tally: {ns['fails']} failed checks", ns["fails"] == 0)163    chk(f"the exponential form's free a₀ = {ns['a_e']:.3e}; floor/fit = {ns['a0_floor'] / ns['a_e']:.3f}", 0.8 < ns["a0_floor"] / ns["a_e"] < 0.95)164165def _pred_deep_mond(ns, out):166    chk(f"a₀ = cH₀/2π = {ns['a0']:.4e} at H₀ = 67.4 (1.042 × 10⁻¹⁰)", abs(ns["a0"] - 1.042e-10) < 2e-13)167    chk(f"RAR deep-regime slope {ns['slope']:.3f} → 1/2", abs(ns["slope"] - 0.5) < 0.02)168    chk(f"BTFR slope {ns['bt']:.3f} → 1/4", abs(ns["bt"] - 0.25) < 1e-3)169    v = (ns["G"] * 5e10 * ns["Msun"] * ns["a0"]) ** 0.25 / 1000170    chk(f"v_flat(5 × 10¹⁰ M⊙) = {v:.0f} km/s (the paper's 162)", abs(v - 162) < 3)171    chk("the exponential-disk curve: the registered speed flattens (scipy present)", ns["have_disk"] and abs(ns["vo"][-50:].std()) < 0.05 * ns["vo"][-50:].mean())172    chk("the figure written (cons2_rar_btfr.pdf, .png)", _out("cons2_rar_btfr.pdf") and _out("cons2_rar_btfr.png"))173174def _pred_cluster(ns, out):175    np = ns["np"]176    Neff = lambda g: np.sum(np.sqrt(g)) ** 2 / np.sum(g)          # the script's law (its own Neff name is rebound to a float by part 2)177    chk("N_eff = (Σ√g)²/Σg = N for equal components (4 → 4, 6 → 6)", abs(Neff([1, 1, 1, 1]) - 4) < 1e-12 and abs(Neff([1] * 6) - 6) < 1e-12)178    chk(f"a dominant BCG suppresses N_eff (4:1:1 → {Neff([4, 1, 1]):.3f} < 3)", Neff([4, 1, 1]) < 3)179    m = re.findall(r"BCG-dominated 4:1:1\s+([0-9.]+)", out)180    chk(f"the script's printed value {m} equals the law's {Neff([4, 1, 1]):.3f}", len(m) == 1 and abs(float(m[0]) - Neff([4, 1, 1])) < 1e-3)181    chk(f"the core boost √N_core = {math.sqrt(ns['Ncore']):.3f} for N_core = 6, decaying to 1 by ~Mpc in the illustration", abs(math.sqrt(ns["Ncore"]) - 2.449) < 0.01)182183def _pred_rar_scatter(ns, out):184    chk(f"the script's own tally: {ns['fails']} failed checks", ns["fails"] == 0)185    chk(f"[approx] intrinsic scatter at fixed a₀ = {ns['intr']:.3f} dex (the paper's 0.038)", abs(ns["intr"] - 0.038) < 0.003)186    b = ns["binned"]187    chk(f"[approx] the knee bins 0.3 < x < 3: {b[(-0.5, 0)]:.3f}, {b[(0, 0.5)]:.3f} dex (0.04); the deep bin x < 0.03: {b[(-2, -1.5)]:.3f} dex (0.13)", abs(b[(-0.5, 0)] - 0.04) < 0.01 and abs(b[(0, 0.5)] - 0.04) < 0.01 and abs(b[(-2, -1.5)] - 0.13) < 0.02)188    chk(f"[approx] the bound δα ≲ {ns['da_knee']:.1f}° (3.5°)", abs(ns["da_knee"] - 3.5) < 0.5)189    chk(f"[approx] Spearman ρ(intrinsic, 1/V_flat) = {ns['rho']:+.3f} over {len(ns['res'])} disks (−0.02, n = 116)", abs(ns["rho"] + 0.02) < 0.05 and len(ns["res"]) == 116)190    chk(f"[approx] the gas–disk–bulge amplitude sum would boost the RAR by {ns['np'].median(ns['boost']):.3f} dex (0.14)", abs(ns["np"].median(ns["boost"]) - 0.14) < 0.01)191192def _pred_predictions(ns, out):193    Ez, sig, nu, a0, G, Msun, AU = ns["Ez"], ns["sig"], ns["nu"], ns["a0"], ns["G"], ns["Msun"], ns["AU"]194    chk("[approx] v_flat(z)/v₀ = E(z)^(1/4): +7 %, +15 %, +31 % at z = 0.5, 1, 2", abs(Ez(0.5) ** 0.25 - 1.07) < 0.01 and abs(Ez(1.0) ** 0.25 - 1.15) < 0.01 and abs(Ez(2.0) ** 0.25 - 1.31) < 0.01)195    chk(f"[approx] the scatter law at x = 0.01, σ_v/v = 0.1: {sig(0.01, 0.1):.3f} dex (0.27)", abs(sig(0.01, 0.1) - 0.27) < 0.02)196    gext = 1.8 * a0197    nus = [float(nu((G * 1.5 * Msun / (s * 1000 * AU) ** 2 + gext) / a0)) for s in (10, 20, 40)]198    chk(f"[approx] wide binaries with the Galactic field 1.8a₀: ν = {[round(v, 3) for v in nus]} at 10, 20, 40 kAU, a velocity enhancement √ν − 1 of {[round(100 * (v ** 0.5 - 1)) for v in nus]} % (the paper's 10–30 %)", all(0.10 < v ** 0.5 - 1 < 0.30 for v in nus))199    off = [math.log10(math.sqrt(1 / (1 + r * r))) for r in (0.5, 1.0)]200    chk(f"[approx] the coherence offset for σ_v/v = 0.5, 1: {[round(o, 3) for o in off]} dex (−0.05 to −0.15)", -0.16 < off[1] < off[0] < -0.04)201202def _pred_figures(ns, out):203    chk("fig_rar.pdf (and .png) regenerated in figures/", all(os.path.exists(os.path.join(HERE, "figures", "fig_rar" + e)) for e in (".pdf", ".png")))204    chk("fig_mechanism.pdf (and .png) regenerated in figures/", all(os.path.exists(os.path.join(HERE, "figures", "fig_mechanism" + e)) for e in (".pdf", ".png")))205206PRED = {207    "dark.flux_exact": _pred_flux, "dark.born_exact": _pred_born, "dark.firstpassage_finite": _pred_fp,208    "dark.meridian_walk": _pred_walk, "dark.deep_regime": _pred_deep, "dark.deep_regime_fp": _pred_deep_fp,209    "dark.interpolation": _pred_interp, "dark.rar_shape": _pred_rar_shape, "dark.deep_mond": _pred_deep_mond,210    "dark.cluster_coherent": _pred_cluster, "dark.rar_scatter": _pred_rar_scatter, "dark.predictions": _pred_predictions,211    "dark.make_figures": _pred_figures,212}213214def run_block(fam):215    """Run one script of the suite under the registry, apply the registry's predicates, record the family verdict."""216    stem = script_of(fam)217    path = os.path.join(HERE, stem + ".py")218    src = io.open(path, encoding="utf-8").read()219    src = src.replace("raise SystemExit(", "raise __exit__(").replace("sys.exit(", "__exit__(")220    verdicts, lines = [], []221    def _print(*args, **kw):222        s = " ".join(str(a) for a in args)223        kw.pop("file", None); print(s, **kw)224        for line in s.split("\n"):225            lines.append(line)226            t = line.strip()227            m = re.match(r"^ALL PASS: (True|False)", t)228            if m:229                verdicts.append(m.group(1) == "True")230            elif re.match(r"^(\[?(PASS|FAIL|OK|XX)\]?(?![A-Za-z])|\[EXACT\])", t):     # a script's per-check verdict line231                verdicts.append(t[:6].find("PASS") >= 0 or t[:4].find("OK") >= 0 or t.startswith("[EXACT]"))232    def _exit(code=0):233        raise _Exit(code)234    g = {"__name__": "__main__", "__file__": path, "print": _print, "__exit__": _exit}235    pngs = []                                            # every figure a script saves gets a PNG sibling (shown inline in the notebook)236    import matplotlib; matplotlib.use("Agg")237    from matplotlib.figure import Figure238    _savefig = Figure.savefig239    def _savefig_png(fig, fname, *a, **kw):240        _savefig(fig, fname, *a, **kw)241        if isinstance(fname, (str, os.PathLike)):242            png = os.path.splitext(os.fspath(fname))[0] + ".png"243            _savefig(fig, png, dpi=130, bbox_inches="tight"); pngs.append(os.path.abspath(png))244    Figure.savefig = _savefig_png245    _CUR[0] = fam246    n0 = len(MICRO)247    t0 = time.time(); code = 0; err = None248    OUT = os.path.join(HERE, "out"); os.makedirs(OUT, exist_ok=True); os.makedirs(os.path.join(HERE, "figures"), exist_ok=True)249    old = os.getcwd(); os.chdir(OUT); sys.path.insert(0, HERE)      # the scripts write cons*.pdf, deep.json here and ../figures/ = figures/250    try:251        exec(compile(src, path, "exec"), g)252    except _Exit as e:253        code = e.code if isinstance(e.code, int) else (0 if e.code in (None, 0) else 1)254    except Exception:255        err = traceback.format_exc().strip().splitlines()[-1]256        print("    EXCEPTION: " + err)257    finally:258        os.chdir(old)259        Figure.savefig = _savefig260        import matplotlib.pyplot as plt; plt.close("all")261    _show_pngs(pngs)262    for i, v in enumerate(verdicts):                     # the script's own printed verdict lines263        MICRO.append((fam, f"verdict line {i + 1}", v))264    if err is None and fam in PRED:                      # the registry's predicates on the namespace and output265        try:266            PRED[fam](g, "\n".join(lines))267        except Exception:268            err = "predicate: " + traceback.format_exc().strip().splitlines()[-1]269            print("    EXCEPTION: " + err)270    _CUR[0] = None271    micro = [ok for f, _, ok in MICRO[n0:]]272    ok = err is None and code == 0 and all(micro) and len(micro) > 0273    detail = f"{len(micro)} checks, {time.time() - t0:.1f} s" + (f"; {err}" if err else "") + (f"; exit {code}" if code else "")274    check(fam, ok, detail=detail, kind=KIND.get(fam, "EXACT"))275    return ok276277def check(pid, ok, detail="", kind="EXACT", label=None):278    ok = bool(ok)279    rows = LEDGER.get(pid, "")280    label = label or LABELS.get(pid, pid)281    RESULTS.append({"id": pid, "rows": rows, "script": script_of(pid), "label": label, "ok": ok, "detail": detail, "kind": kind})282    print(f"  [{'PASS' if ok else 'FAIL'}] {pid:22s} {kind:6s} [{rows}] {label[:90]}" + (f"  --  {detail}" if detail else ""))283    return ok284285def summary(write=True):286    n_ok = sum(r["ok"] for r in RESULTS)287    print(f"\nSUMMARY: {n_ok}/{len(RESULTS)} checks passed ({len(MICRO)} micro-checks)" + ("" if n_ok == len(RESULTS) else "  <-- FAILURES"))288    if write:289        with open(os.path.join(HERE, "results.json"), "w") as f:290            json.dump(RESULTS, f, indent=1, ensure_ascii=False)291    return n_ok == len(RESULTS)292