Spaces:
Running
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): Dockerfile, serve.py, szl_pinn_bounds.py
Deleted (gone from the repo + Dockerfile COPY set): (none)
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- Dockerfile +6 -0
- serve.py +18 -0
- szl_pinn_bounds.py +440 -0
Dockerfile
CHANGED
|
@@ -97,6 +97,12 @@ COPY szl_formula_wiring.py a11oy_code_engine.py a11oy_code.py a11oy_seismic.py s
|
|
| 97 |
# Energy/heart/engine/revenue/harvest organ modules: present in repo but were absent
|
| 98 |
# from every COPY line -> guarded imports threw ModuleNotFoundError -> dark 404 surfaces.
|
| 99 |
COPY szl_energy_budget.py szl_energy_provenance.py szl_heart_blood.py szl_engine_status.py szl_backend_hardening.py revenue_endpoints.py a11oy_harvest_endpoints.py ./
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# ADDITIVE (joules-honesty #349): single-source joules_label helper + its consumers.
|
| 101 |
# szl_joules_truth.py is imported by szl_energy_budget/szl_engine_status/revenue_endpoints/
|
| 102 |
# a11oy_harvest_endpoints/szl_anatomy_loop/szl_prod_hardening; revenue_model.py backs
|
|
|
|
| 97 |
# Energy/heart/engine/revenue/harvest organ modules: present in repo but were absent
|
| 98 |
# from every COPY line -> guarded imports threw ModuleNotFoundError -> dark 404 surfaces.
|
| 99 |
COPY szl_energy_budget.py szl_energy_provenance.py szl_heart_blood.py szl_engine_status.py szl_backend_hardening.py revenue_endpoints.py a11oy_harvest_endpoints.py ./
|
| 100 |
+
# Agentic-PINN + physical-bounds mesh (pure-stdlib sibling of szl_energy_budget; serves
|
| 101 |
+
# /api/a11oy/v1/pinn/*). MUST be COPY'd or serve.py's guarded import falls back to a stub
|
| 102 |
+
# (merged-but-not-live) in the HF image. The optional on-metal artifacts it reads
|
| 103 |
+
# (physical_bounds_certificate.json / agentic_decision_trail.json) are NOT baked — the
|
| 104 |
+
# module honestly serves a SAMPLE certificate until Forge writes real ones on the box.
|
| 105 |
+
COPY szl_pinn_bounds.py ./
|
| 106 |
# ADDITIVE (joules-honesty #349): single-source joules_label helper + its consumers.
|
| 107 |
# szl_joules_truth.py is imported by szl_energy_budget/szl_engine_status/revenue_endpoints/
|
| 108 |
# a11oy_harvest_endpoints/szl_anatomy_loop/szl_prod_hardening; revenue_model.py backs
|
serve.py
CHANGED
|
@@ -250,6 +250,24 @@ try:
|
|
| 250 |
except Exception as _szl_eb_e: # pragma: no cover
|
| 251 |
print(f"[a11oy] Energy-budget receipt NOT registered: {_szl_eb_e!r}", file=__import__("sys").stderr)
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
# ── Unified leader-formulas (thesis v6) — Sherman Morgan density-impulse/Tsiolkovsky,
|
| 254 |
# Stewart LS12/CoRoL/Hugoniot, Wave24 coherence single-crossing. Each is REAL deterministic
|
| 255 |
# Python with the ORIGINAL author cited; SZL borrows methodological structure only (no result
|
|
|
|
| 250 |
except Exception as _szl_eb_e: # pragma: no cover
|
| 251 |
print(f"[a11oy] Energy-budget receipt NOT registered: {_szl_eb_e!r}", file=__import__("sys").stderr)
|
| 252 |
|
| 253 |
+
# ── Agentic PINN + Physical-Bounds Certifier MESH (pinn-bounds) — closes the audited
|
| 254 |
+
# gap where the PINN / FE-NO Physics-ML verticals lived ONLY in `platform` and were
|
| 255 |
+
# NOT in a11oy's governed /api/a11oy/v1/<name> route table. Adds /api/a11oy/v1/pinn/*:
|
| 256 |
+
# /pinn (index) /pinn/certify /pinn/certificate /pinn/solve /pinn/residual
|
| 257 |
+
# The certificate is the HONEST INVERSE of a free-energy claim — it PROVES a real
|
| 258 |
+
# compute job sits FAR BELOW the fundamental ceilings (Landauer/Margolus-Levitin/
|
| 259 |
+
# Bremermann/Bekenstein/Bekenstein-Hawking; CITED, not claimed). Joules DERIVED only
|
| 260 |
+
# from MEASURED power×time; Λ=Conjecture 1 (advisory, deny-by-default). PURE STDLIB —
|
| 261 |
+
# the numpy agentic solver runs on SZL metal / Forge GPU and writes the artifacts this
|
| 262 |
+
# mesh reads; the live web path never solves. Additive, try/except-guarded, before the
|
| 263 |
+
# SPA catch-all. Math is byte-identical to agentic_pinn/physics_bounds.py.
|
| 264 |
+
try:
|
| 265 |
+
import szl_pinn_bounds as _szl_pinn_bounds
|
| 266 |
+
_szl_pinn_bounds.register(app, ns="a11oy")
|
| 267 |
+
print("[a11oy] Agentic-PINN + physical-bounds mesh registered: /api/a11oy/v1/pinn/*", file=__import__("sys").stderr)
|
| 268 |
+
except Exception as _szl_pinn_e: # pragma: no cover
|
| 269 |
+
print(f"[a11oy] Agentic-PINN + physical-bounds mesh NOT registered: {_szl_pinn_e!r}", file=__import__("sys").stderr)
|
| 270 |
+
|
| 271 |
# ── Unified leader-formulas (thesis v6) — Sherman Morgan density-impulse/Tsiolkovsky,
|
| 272 |
# Stewart LS12/CoRoL/Hugoniot, Wave24 coherence single-crossing. Each is REAL deterministic
|
| 273 |
# Python with the ORIGINAL author cited; SZL borrows methodological structure only (no result
|
szl_pinn_bounds.py
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
# © 2026 SZL Holdings · Doctrine v11 LOCKED · Λ = Conjecture 1 (advisory, NOT proven trust)
|
| 3 |
+
# Sign-off: Stephen P. Lutar Jr. <stephenlutar2@gmail.com>
|
| 4 |
+
"""szl_pinn_bounds.py — a11oy MESH for the SZL AGENTIC PINN + PHYSICAL-BOUNDS CERTIFIER.
|
| 5 |
+
|
| 6 |
+
This is the live-mesh surface for the Physics-ML frontier. Until now the PINN /
|
| 7 |
+
FE-NO verticals lived only in `platform`; they were NOT in a11oy's governed
|
| 8 |
+
`/api/a11oy/v1/<name>` route table. This module closes that gap — additively,
|
| 9 |
+
try/except-guarded, PURE STDLIB (no numpy/torch in the request path), matching the
|
| 10 |
+
sibling `szl_energy_budget.py` contract exactly.
|
| 11 |
+
|
| 12 |
+
Routes (all GET, read-only / deterministic):
|
| 13 |
+
|
| 14 |
+
/api/<ns>/v1/pinn -> capability index + doctrine + links
|
| 15 |
+
/api/<ns>/v1/pinn/certify?... -> PHYSICAL-BOUNDS CERTIFICATE from MEASURED
|
| 16 |
+
telemetry query params (the honest inverse
|
| 17 |
+
of a free-energy claim). Live certifier.
|
| 18 |
+
/api/<ns>/v1/pinn/certificate -> latest pre-computed certificate artifact
|
| 19 |
+
(an honestly-labelled SAMPLE if none wired)
|
| 20 |
+
/api/<ns>/v1/pinn/solve -> governed agentic decision trail (per-round
|
| 21 |
+
residual-adaptive refine + deny-by-default
|
| 22 |
+
Λ-gate). Read from the artifact the GPU
|
| 23 |
+
solver (Forge) writes; numpy re-solve is the
|
| 24 |
+
Forge/own-metal path, never the web path.
|
| 25 |
+
/api/<ns>/v1/pinn/residual -> compact per-round residual / rel-L2 summary
|
| 26 |
+
|
| 27 |
+
HONESTY (Doctrine v11, HARD):
|
| 28 |
+
- The bounds are ESTABLISHED PHYSICS, CITED — Landauer 1961, Margolus-Levitin 1998,
|
| 29 |
+
Bremermann 1962, Bekenstein 1981, Hawking 1975. NOT SZL conjectures.
|
| 30 |
+
- The certificate is the HONEST INVERSE of a free-energy claim: it PROVES a real job
|
| 31 |
+
sits FAR BELOW the fundamental ceilings. NO over-unity, NO perpetual motion.
|
| 32 |
+
- Energy is DERIVED only from MEASURED power × MEASURED time. Any value not backed by
|
| 33 |
+
a real exporter is labelled SAMPLE. We fabricate NO number.
|
| 34 |
+
- Λ = Conjecture 1 (advisory). ALLOW = "passed SZL admission policy", never
|
| 35 |
+
"proven trust". The gate is deny-by-default.
|
| 36 |
+
- The full numpy agentic solver runs on SZL metal / Forge GPU and writes the decision
|
| 37 |
+
trail + certificate JSON; this stdlib mesh reads & re-certifies, it does not solve.
|
| 38 |
+
|
| 39 |
+
Math mirrors `agentic_pinn/physics_bounds.py` byte-for-byte (same SI constants, same
|
| 40 |
+
formulas) so the live mesh certificate and the on-metal certificate AGREE.
|
| 41 |
+
"""
|
| 42 |
+
import hashlib
|
| 43 |
+
import json
|
| 44 |
+
import math
|
| 45 |
+
import os
|
| 46 |
+
import time
|
| 47 |
+
from datetime import datetime, timezone
|
| 48 |
+
|
| 49 |
+
from starlette.requests import Request
|
| 50 |
+
from starlette.responses import JSONResponse
|
| 51 |
+
|
| 52 |
+
# --------------------------------------------------------------------------- #
|
| 53 |
+
# Fundamental physical constants (SI, CODATA-style) — identical to the engine. #
|
| 54 |
+
# --------------------------------------------------------------------------- #
|
| 55 |
+
K_B = 1.380649e-23 # Boltzmann constant, J/K (SI exact)
|
| 56 |
+
H_PLANCK = 6.62607015e-34 # Planck constant, J·s (SI exact)
|
| 57 |
+
HBAR = H_PLANCK / (2.0 * math.pi)
|
| 58 |
+
C_LIGHT = 299792458.0 # speed of light, m/s (SI exact)
|
| 59 |
+
G_NEWTON = 6.67430e-11 # gravitational constant, m³/(kg·s²) (CODATA 2018)
|
| 60 |
+
LN2 = math.log(2.0)
|
| 61 |
+
|
| 62 |
+
BOUNDS_ATTRIBUTION = {
|
| 63 |
+
"landauer": ("Landauer, R. (1961), IBM J. Res. Dev. 5(3):183-191, "
|
| 64 |
+
"doi:10.1147/rd.53.0183 — min erase energy kT·ln2 per bit."),
|
| 65 |
+
"margolus_levitin": ("Margolus, N. & Levitin, L. (1998), Physica D 120:188-195, "
|
| 66 |
+
"doi:10.1016/S0167-2789(98)00054-2 — max 4E/h ops/s."),
|
| 67 |
+
"bremermann": ("Bremermann, H.J. (1962), Self-Organizing Systems — "
|
| 68 |
+
"max c²/h ≈ 1.356e50 bits/s per kg."),
|
| 69 |
+
"bekenstein": ("Bekenstein, J.D. (1981), Phys. Rev. D 23(2):287, "
|
| 70 |
+
"doi:10.1103/PhysRevD.23.287 — I ≤ 2πRE/(ħc·ln2) bits."),
|
| 71 |
+
"bekenstein_hawking": ("Hawking, S.W. (1975), Commun. Math. Phys. 43:199-220, "
|
| 72 |
+
"doi:10.1007/BF02345020 — holographic area-law ceiling."),
|
| 73 |
+
"honesty": ("Established physics, cited not claimed. The certificate is the HONEST "
|
| 74 |
+
"INVERSE of a free-energy claim: it proves the job is physically "
|
| 75 |
+
"bounded, asserts no over-unity, fabricates no number."),
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
DOCTRINE = (
|
| 79 |
+
"v11 LOCKED: NO free-energy/over-unity (this certificate PROVES bounded energy use — "
|
| 80 |
+
"the honest inverse); joules DERIVED ONLY from MEASURED power×time (SAMPLE until a "
|
| 81 |
+
"real exporter is wired); physics bounds CITED, not claimed as SZL's; Λ=Conjecture 1 "
|
| 82 |
+
"(advisory, never 'proven trust'); locked-proven=8; SLSA L1 honest; sovereign "
|
| 83 |
+
"own-metal; no fabricated numbers."
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
LAMBDA_NOTE = ("Λ = Conjecture 1 (advisory). States physical FACTS (bounds), not "
|
| 87 |
+
"'proven trust'. Makes NO free-energy claim. Gate is deny-by-default.")
|
| 88 |
+
|
| 89 |
+
# Where the on-metal solver (Forge) drops its artifacts. The mesh READS these; it
|
| 90 |
+
# never solves. Configurable so Forge can point at the live data dir on the box.
|
| 91 |
+
_ART_DIR = os.environ.get("SZL_PINN_ARTIFACT_DIR", os.path.dirname(os.path.abspath(__file__)))
|
| 92 |
+
_CERT_ARTIFACT = os.path.join(_ART_DIR, "physical_bounds_certificate.json")
|
| 93 |
+
_TRAIL_ARTIFACT = os.path.join(_ART_DIR, "agentic_decision_trail.json")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def _now_iso() -> str:
|
| 97 |
+
return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# --------------------------------------------------------------------------- #
|
| 101 |
+
# Bound math (DERIVED from MEASURED inputs) — identical to physics_bounds.py. #
|
| 102 |
+
# --------------------------------------------------------------------------- #
|
| 103 |
+
def landauer_floor_joules(temperature_k: float, bits_erased: float) -> float:
|
| 104 |
+
return K_B * temperature_k * LN2 * bits_erased
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def margolus_levitin_max_ops_per_s(energy_joules: float) -> float:
|
| 108 |
+
return 4.0 * energy_joules / H_PLANCK
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def bremermann_max_ops_per_s(mass_kg: float) -> float:
|
| 112 |
+
return (C_LIGHT ** 2 / H_PLANCK) * mass_kg
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def bekenstein_max_info_bits(radius_m: float, energy_joules: float) -> float:
|
| 116 |
+
return 2.0 * math.pi * radius_m * energy_joules / (HBAR * C_LIGHT * LN2)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def bekenstein_hawking_entropy_bits(radius_m: float) -> float:
|
| 120 |
+
area = 4.0 * math.pi * radius_m ** 2
|
| 121 |
+
s_over_k = (C_LIGHT ** 3 * area) / (4.0 * G_NEWTON * HBAR)
|
| 122 |
+
return s_over_k / LN2
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def certify_job(avg_power_w, wall_time_s, temperature_k, bit_operations,
|
| 126 |
+
bits_erased, info_content_bits, device_mass_kg, device_radius_m,
|
| 127 |
+
label="SAMPLE", source="mesh-query", note="") -> dict:
|
| 128 |
+
"""Compute the PHYSICAL-BOUNDS CERTIFICATE from MEASURED telemetry — pure stdlib.
|
| 129 |
+
|
| 130 |
+
Returns the same `szl/physical-bounds-certificate/v1` schema the on-metal engine
|
| 131 |
+
emits (MEASURED inputs vs DERIVED bounds clearly split). UNSIGNED here; the khipu /
|
| 132 |
+
szl_lake Ed25519 path signs it (DSSE PAE). Unsigned == STRUCTURAL-ONLY, never a
|
| 133 |
+
false green.
|
| 134 |
+
"""
|
| 135 |
+
measured = {
|
| 136 |
+
"label": label, "source": source,
|
| 137 |
+
"avg_power_w_MEASURED": avg_power_w,
|
| 138 |
+
"wall_time_s_MEASURED": wall_time_s,
|
| 139 |
+
"temperature_k_MEASURED": temperature_k,
|
| 140 |
+
"bit_operations_MEASURED": bit_operations,
|
| 141 |
+
"bits_erased_MEASURED": bits_erased,
|
| 142 |
+
"info_content_bits_MEASURED": info_content_bits,
|
| 143 |
+
"device_mass_kg": device_mass_kg,
|
| 144 |
+
"device_radius_m": device_radius_m,
|
| 145 |
+
"note": note,
|
| 146 |
+
}
|
| 147 |
+
E = avg_power_w * wall_time_s # DERIVED: MEASURED power × MEASURED time
|
| 148 |
+
floor = landauer_floor_joules(temperature_k, bits_erased)
|
| 149 |
+
land_mult = (E / floor) if floor > 0 else float("inf")
|
| 150 |
+
ml_max = margolus_levitin_max_ops_per_s(E)
|
| 151 |
+
job_rate = (bit_operations / wall_time_s) if wall_time_s > 0 else 0.0
|
| 152 |
+
ml_frac = (job_rate / ml_max) if ml_max > 0 else float("inf")
|
| 153 |
+
brem_max = bremermann_max_ops_per_s(device_mass_kg)
|
| 154 |
+
brem_frac = (job_rate / brem_max) if brem_max > 0 else float("inf")
|
| 155 |
+
bek_max = bekenstein_max_info_bits(device_radius_m, E)
|
| 156 |
+
bek_frac = (info_content_bits / bek_max) if bek_max > 0 else float("inf")
|
| 157 |
+
bek_ok = info_content_bits <= bek_max
|
| 158 |
+
bh_ceiling = bekenstein_hawking_entropy_bits(device_radius_m)
|
| 159 |
+
physically_bounded = bool(
|
| 160 |
+
land_mult >= 1.0 and ml_frac <= 1.0 and brem_frac <= 1.0 and bek_ok
|
| 161 |
+
)
|
| 162 |
+
summary = (
|
| 163 |
+
f"This compute job used {E:.4g} J (DERIVED = {avg_power_w:g} W MEASURED × "
|
| 164 |
+
f"{wall_time_s:g} s MEASURED) = {land_mult:.3g}× the Landauer erasure floor "
|
| 165 |
+
f"({floor:.4g} J). It ran at {ml_frac*100:.3g}% of the Margolus-Levitin maximum "
|
| 166 |
+
f"rate ({ml_max:.4g} ops/s) and {brem_frac*100:.3g}% of the Bremermann limit. "
|
| 167 |
+
f"Information content ({info_content_bits:.4g} bits) is {bek_frac*100:.3g}% of the "
|
| 168 |
+
f"Bekenstein ceiling ({bek_max:.4g} bits), far under the holographic ceiling "
|
| 169 |
+
f"({bh_ceiling:.4g} bits). VERDICT: PHYSICALLY BOUNDED by established law — the "
|
| 170 |
+
f"honest inverse of a free-energy claim. No over-unity. No fabricated number."
|
| 171 |
+
)
|
| 172 |
+
canon = json.dumps(measured, sort_keys=True, separators=(",", ":"), default=str)
|
| 173 |
+
inputs_hash = "sha256:" + hashlib.sha256(canon.encode()).hexdigest()
|
| 174 |
+
return {
|
| 175 |
+
"certificate_type": "szl/physical-bounds-certificate/v1",
|
| 176 |
+
"measured": measured,
|
| 177 |
+
"energy_joules_derived": E,
|
| 178 |
+
"landauer_floor_joules": floor,
|
| 179 |
+
"landauer_multiple_above_floor": land_mult,
|
| 180 |
+
"margolus_levitin_max_ops_per_s": ml_max,
|
| 181 |
+
"job_ops_per_s_measured": job_rate,
|
| 182 |
+
"margolus_levitin_headroom_fraction": ml_frac,
|
| 183 |
+
"margolus_levitin_headroom_pct": ml_frac * 100.0,
|
| 184 |
+
"bremermann_max_ops_per_s": brem_max,
|
| 185 |
+
"bremermann_headroom_fraction": brem_frac,
|
| 186 |
+
"bekenstein_max_info_bits": bek_max,
|
| 187 |
+
"bekenstein_info_fraction": bek_frac,
|
| 188 |
+
"bekenstein_under_ceiling": bek_ok,
|
| 189 |
+
"bekenstein_hawking_ceiling_bits": bh_ceiling,
|
| 190 |
+
"physically_bounded": physically_bounded,
|
| 191 |
+
"summary": summary,
|
| 192 |
+
"inputs_hash": inputs_hash,
|
| 193 |
+
"timestamp_utc": time.time(),
|
| 194 |
+
"attribution": BOUNDS_ATTRIBUTION,
|
| 195 |
+
"doctrine": DOCTRINE,
|
| 196 |
+
"honest_inverse_of_free_energy": True,
|
| 197 |
+
"labels": {
|
| 198 |
+
"MEASURED": "observed from a real exporter (NVML) or honestly-labelled sample",
|
| 199 |
+
"DERIVED": "computed from MEASURED inputs via CITED established-physics formulas",
|
| 200 |
+
},
|
| 201 |
+
"lambda_note": LAMBDA_NOTE,
|
| 202 |
+
"signature": None, # UNSIGNED here; signed on the khipu/szl_lake DSSE path
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# An honestly-labelled SAMPLE job (the in-sandbox default; matches nvml_hook.sample_job).
|
| 207 |
+
_SAMPLE_JOB = dict(
|
| 208 |
+
avg_power_w=700.0, wall_time_s=10.0, temperature_k=350.0,
|
| 209 |
+
bit_operations=1e16, bits_erased=1e14, info_content_bits=1e12,
|
| 210 |
+
device_mass_kg=2.0, device_radius_m=0.15,
|
| 211 |
+
label="SAMPLE", source="honest-sample (no GPU in mesh path — doctrine v11)",
|
| 212 |
+
note="In-sandbox SAMPLE. On metal Forge feeds REAL NVML readings via forge_job().",
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
# --------------------------------------------------------------------------- #
|
| 217 |
+
# Query-param parsing #
|
| 218 |
+
# --------------------------------------------------------------------------- #
|
| 219 |
+
def _f(qp, *keys, default=0.0):
|
| 220 |
+
for k in keys:
|
| 221 |
+
v = qp.get(k)
|
| 222 |
+
if v not in (None, ""):
|
| 223 |
+
try:
|
| 224 |
+
return float(v)
|
| 225 |
+
except Exception:
|
| 226 |
+
pass
|
| 227 |
+
return float(default)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def _read_json(path):
|
| 231 |
+
try:
|
| 232 |
+
with open(path, "r") as fh:
|
| 233 |
+
return json.load(fh)
|
| 234 |
+
except Exception:
|
| 235 |
+
return None
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# --------------------------------------------------------------------------- #
|
| 239 |
+
# Handlers #
|
| 240 |
+
# --------------------------------------------------------------------------- #
|
| 241 |
+
def _h_index(req: Request):
|
| 242 |
+
ns = req.path_params.get("_ns", "a11oy")
|
| 243 |
+
base = f"/api/{ns}/v1/pinn"
|
| 244 |
+
return JSONResponse({
|
| 245 |
+
"capability": "SZL Agentic PINN + Physical-Bounds Certifier",
|
| 246 |
+
"frontier": ("governed, residual-adaptive physics-informed solve loop under a "
|
| 247 |
+
"deny-by-default Λ-gate, every solve CERTIFIED against the "
|
| 248 |
+
"fundamental compute/energy bounds of physics"),
|
| 249 |
+
"honest_inverse_of_free_energy": True,
|
| 250 |
+
"routes": {
|
| 251 |
+
f"{base}/certify": "PHYSICAL-BOUNDS CERTIFICATE from MEASURED telemetry "
|
| 252 |
+
"(?avg_power_w=&wall_time_s=&temperature_k=&bit_operations="
|
| 253 |
+
"&bits_erased=&info_content_bits=&device_mass_kg=&device_radius_m=)",
|
| 254 |
+
f"{base}/certificate": "latest pre-computed certificate artifact (SAMPLE if none wired)",
|
| 255 |
+
f"{base}/solve": "governed agentic decision trail (per-round refine + Λ-gate)",
|
| 256 |
+
f"{base}/residual": "compact per-round residual / rel-L2 summary",
|
| 257 |
+
},
|
| 258 |
+
"bounds": ["Landauer (1961)", "Margolus-Levitin (1998)", "Bremermann (1962)",
|
| 259 |
+
"Bekenstein (1981)", "Bekenstein-Hawking (Hawking 1975)"],
|
| 260 |
+
"attribution": BOUNDS_ATTRIBUTION,
|
| 261 |
+
"lambda_note": LAMBDA_NOTE,
|
| 262 |
+
"doctrine": DOCTRINE,
|
| 263 |
+
"ts": _now_iso(),
|
| 264 |
+
})
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def _h_certify(req: Request):
|
| 268 |
+
qp = req.query_params
|
| 269 |
+
has_input = any(k in qp for k in (
|
| 270 |
+
"avg_power_w", "power_w", "wall_time_s", "bit_operations"))
|
| 271 |
+
job = dict(_SAMPLE_JOB)
|
| 272 |
+
if has_input:
|
| 273 |
+
job.update(
|
| 274 |
+
avg_power_w=_f(qp, "avg_power_w", "power_w", default=job["avg_power_w"]),
|
| 275 |
+
wall_time_s=_f(qp, "wall_time_s", "time_s", default=job["wall_time_s"]),
|
| 276 |
+
temperature_k=_f(qp, "temperature_k", "temp_k", default=job["temperature_k"]),
|
| 277 |
+
bit_operations=_f(qp, "bit_operations", "ops", default=job["bit_operations"]),
|
| 278 |
+
bits_erased=_f(qp, "bits_erased", default=job["bits_erased"]),
|
| 279 |
+
info_content_bits=_f(qp, "info_content_bits", "info_bits", default=job["info_content_bits"]),
|
| 280 |
+
device_mass_kg=_f(qp, "device_mass_kg", "mass_kg", default=job["device_mass_kg"]),
|
| 281 |
+
device_radius_m=_f(qp, "device_radius_m", "radius_m", default=job["device_radius_m"]),
|
| 282 |
+
label="MEASURED" if qp.get("measured") in ("1", "true", "yes") else "SAMPLE",
|
| 283 |
+
source=qp.get("source", "mesh-query"),
|
| 284 |
+
)
|
| 285 |
+
cert = certify_job(**{k: job[k] for k in (
|
| 286 |
+
"avg_power_w", "wall_time_s", "temperature_k", "bit_operations", "bits_erased",
|
| 287 |
+
"info_content_bits", "device_mass_kg", "device_radius_m", "label", "source")},
|
| 288 |
+
note=job["note"])
|
| 289 |
+
return JSONResponse({
|
| 290 |
+
"model": "SZL Physical-Bounds Certifier — live certificate",
|
| 291 |
+
"status": "VERIFIED (physical bounds) · UNSIGNED (STRUCTURAL-ONLY)",
|
| 292 |
+
"certificate": cert,
|
| 293 |
+
})
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def _h_certificate(req: Request):
|
| 297 |
+
art = _read_json(_CERT_ARTIFACT)
|
| 298 |
+
if art is not None:
|
| 299 |
+
return JSONResponse({
|
| 300 |
+
"model": "SZL Physical-Bounds Certifier — latest artifact",
|
| 301 |
+
"status": "VERIFIED (physical bounds) · UNSIGNED (STRUCTURAL-ONLY)",
|
| 302 |
+
"source": "on-metal artifact (Forge solver output)",
|
| 303 |
+
"certificate": art,
|
| 304 |
+
})
|
| 305 |
+
# Honest fallback: emit a clearly-labelled SAMPLE certificate.
|
| 306 |
+
cert = certify_job(**{k: _SAMPLE_JOB[k] for k in (
|
| 307 |
+
"avg_power_w", "wall_time_s", "temperature_k", "bit_operations", "bits_erased",
|
| 308 |
+
"info_content_bits", "device_mass_kg", "device_radius_m", "label", "source")},
|
| 309 |
+
note=_SAMPLE_JOB["note"])
|
| 310 |
+
return JSONResponse({
|
| 311 |
+
"model": "SZL Physical-Bounds Certifier — SAMPLE (no artifact wired)",
|
| 312 |
+
"status": "VERIFIED (physical bounds) · SAMPLE · UNSIGNED (STRUCTURAL-ONLY)",
|
| 313 |
+
"source": "honest-sample (Forge has not written a certificate artifact yet)",
|
| 314 |
+
"certificate": cert,
|
| 315 |
+
})
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def _trail_or_none():
|
| 319 |
+
return _read_json(_TRAIL_ARTIFACT)
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def _h_solve(req: Request):
|
| 323 |
+
trail = _trail_or_none()
|
| 324 |
+
if trail is not None:
|
| 325 |
+
return JSONResponse({
|
| 326 |
+
"model": "SZL Agentic PINN — governed solve decision trail",
|
| 327 |
+
"status": f"{trail.get('final_verdict', 'UNKNOWN')} "
|
| 328 |
+
f"(accepted={trail.get('final_accepted')})",
|
| 329 |
+
"source": "on-metal artifact (Forge GPU solver output)",
|
| 330 |
+
"note": ("The numpy agentic solver runs on SZL metal / Forge GPU (own-metal, "
|
| 331 |
+
"sovereign). This mesh READS the decision trail it writes — the live "
|
| 332 |
+
"web path never solves. Λ-gate is deny-by-default; ALLOW = passed "
|
| 333 |
+
"admission policy, NOT proven trust."),
|
| 334 |
+
"decision_trail": trail,
|
| 335 |
+
})
|
| 336 |
+
return JSONResponse({
|
| 337 |
+
"model": "SZL Agentic PINN — governed solve decision trail",
|
| 338 |
+
"status": "AWAITING_GPU_SOLVE",
|
| 339 |
+
"source": "no artifact wired",
|
| 340 |
+
"note": ("The governed agentic solver (residual-adaptive refine + deny-by-default "
|
| 341 |
+
"Λ-gate) runs on SZL metal / Forge GPU and writes the per-round decision "
|
| 342 |
+
"trail. None is wired in this environment yet — honest AWAITING state, "
|
| 343 |
+
"never a fabricated solve."),
|
| 344 |
+
"doctrine": DOCTRINE,
|
| 345 |
+
"lambda_note": LAMBDA_NOTE,
|
| 346 |
+
})
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def _h_residual(req: Request):
|
| 350 |
+
trail = _trail_or_none()
|
| 351 |
+
if trail is None:
|
| 352 |
+
return JSONResponse({
|
| 353 |
+
"status": "AWAITING_GPU_SOLVE",
|
| 354 |
+
"note": "No decision trail artifact wired yet (honest). Forge GPU solver writes it.",
|
| 355 |
+
})
|
| 356 |
+
rounds = trail.get("rounds", [])
|
| 357 |
+
summary = [{
|
| 358 |
+
"round": r.get("round_index"),
|
| 359 |
+
"n_collocation": r.get("n_pde_collocation"),
|
| 360 |
+
"max_residual": r.get("max_residual_on_test"),
|
| 361 |
+
"mean_residual": r.get("mean_residual_on_test"),
|
| 362 |
+
"rel_l2_error_estimate": r.get("rel_l2_error_estimate"),
|
| 363 |
+
"lambda_verdict": r.get("lambda_verdict"),
|
| 364 |
+
"accepted": r.get("accepted"),
|
| 365 |
+
"modeled_not_measured": r.get("modeled_not_measured", True),
|
| 366 |
+
"error_estimate_is_bound": r.get("error_estimate_is_bound", True),
|
| 367 |
+
} for r in rounds]
|
| 368 |
+
return JSONResponse({
|
| 369 |
+
"model": "SZL Agentic PINN — per-round residual summary",
|
| 370 |
+
"final_verdict": trail.get("final_verdict"),
|
| 371 |
+
"final_accepted": trail.get("final_accepted"),
|
| 372 |
+
"rounds": summary,
|
| 373 |
+
"note": ("Residual-based adaptive refinement (RAR/RAD): collocation grows where "
|
| 374 |
+
"the PDE residual is largest; the Λ-gate accepts only once converged. "
|
| 375 |
+
"Error estimates are MODELED bounds, not MEASURED."),
|
| 376 |
+
"lambda_note": LAMBDA_NOTE,
|
| 377 |
+
})
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
def register(app, ns="a11oy"):
|
| 381 |
+
"""Wire the PINN/bounds mesh onto the app under /api/<ns>/v1/pinn/*.
|
| 382 |
+
|
| 383 |
+
Additive. Uses FastAPI's add_api_route when available (matches the sibling szl_*
|
| 384 |
+
modules so resolution order is correct vs the SPA catch-all); falls back to a
|
| 385 |
+
Starlette route append for a bare Starlette app.
|
| 386 |
+
"""
|
| 387 |
+
base = f"/api/{ns}/v1/pinn"
|
| 388 |
+
handlers = [
|
| 389 |
+
(base, _h_index),
|
| 390 |
+
(f"{base}/certify", _h_certify),
|
| 391 |
+
(f"{base}/certificate", _h_certificate),
|
| 392 |
+
(f"{base}/solve", _h_solve),
|
| 393 |
+
(f"{base}/residual", _h_residual),
|
| 394 |
+
]
|
| 395 |
+
add_api_route = getattr(app, "add_api_route", None)
|
| 396 |
+
for path, fn in handlers:
|
| 397 |
+
if callable(add_api_route):
|
| 398 |
+
app.add_api_route(path, fn, methods=["GET"])
|
| 399 |
+
else:
|
| 400 |
+
from starlette.routing import Route
|
| 401 |
+
app.router.routes.append(Route(path, fn))
|
| 402 |
+
return [p for p, _ in handlers]
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def _selftest() -> dict:
|
| 406 |
+
"""No-server self-test: proves the certifier honesty + bound inequalities."""
|
| 407 |
+
out = {}
|
| 408 |
+
cert = certify_job(**{k: _SAMPLE_JOB[k] for k in (
|
| 409 |
+
"avg_power_w", "wall_time_s", "temperature_k", "bit_operations", "bits_erased",
|
| 410 |
+
"info_content_bits", "device_mass_kg", "device_radius_m")})
|
| 411 |
+
# (a) energy is DERIVED = power × time
|
| 412 |
+
assert abs(cert["energy_joules_derived"] - 700.0 * 10.0) < 1e-9
|
| 413 |
+
out["energy_derived_power_x_time"] = True
|
| 414 |
+
# (b) sample job is physically bounded
|
| 415 |
+
assert cert["physically_bounded"] is True
|
| 416 |
+
out["sample_physically_bounded"] = True
|
| 417 |
+
# (c) above the Landauer floor (>=1×) — irreversibility honored
|
| 418 |
+
assert cert["landauer_multiple_above_floor"] >= 1.0
|
| 419 |
+
out["above_landauer_floor"] = True
|
| 420 |
+
# (d) under the Margolus-Levitin and Bremermann rate ceilings (<=1)
|
| 421 |
+
assert cert["margolus_levitin_headroom_fraction"] <= 1.0
|
| 422 |
+
assert cert["bremermann_headroom_fraction"] <= 1.0
|
| 423 |
+
out["under_rate_ceilings"] = True
|
| 424 |
+
# (e) HONEST: an adversarial below-floor job is flagged NOT bounded
|
| 425 |
+
bad = certify_job(avg_power_w=1e-30, wall_time_s=1.0, temperature_k=350.0,
|
| 426 |
+
bit_operations=1.0, bits_erased=1e14, info_content_bits=1.0,
|
| 427 |
+
device_mass_kg=2.0, device_radius_m=0.15)
|
| 428 |
+
assert bad["physically_bounded"] is False
|
| 429 |
+
out["below_floor_flagged_unbounded"] = True
|
| 430 |
+
# (f) no free-energy claim; doctrine + Λ-advisory carried
|
| 431 |
+
assert cert["honest_inverse_of_free_energy"] is True
|
| 432 |
+
assert "free-energy" in cert["doctrine"].lower()
|
| 433 |
+
assert "advisory" in cert["lambda_note"].lower()
|
| 434 |
+
out["doctrine_honest"] = True
|
| 435 |
+
out["ok"] = True
|
| 436 |
+
return out
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
if __name__ == "__main__":
|
| 440 |
+
print(json.dumps(_selftest(), indent=2))
|