"""Substrate stacks other than the training stack (Si, eps_r 11.45, 350 um): the physics prior is solved at the requested (eps_r, thickness) and the recipe's corrections are applied unchanged (the calibrated route, agents/v4stack; author decision 2026-11-03). No rescaling. Tested on the 15 held-out DoE designs: Si at 10-1000 um and eps_r 3.8-24 at 350 um (paper model); other combinations are untested and warned. geomgnn.api.substrate_route is the same rule for the GNN models.""" from __future__ import annotations import math EPS_TRAIN, T_TRAIN = 11.45, 350.0 TESTED_THICKNESS_UM = (10.0, 1000.0) TESTED_EPS_R = (3.8, 24.0) ROUTE = "calibrated: physics prior solved at the requested stack, corrections and features at the training stack" CAVEAT = ("calibrated substrate route: the physics prior is solved at your stack and this recipe's corrections (fit on Si, eps_r 11.45, " "350 um only) are applied unchanged. Scored with the paper model (not this recipe) on 15 held-out DoE designs: 0.21-1.02 % " "(MAE 0.07-0.33 fF, RMSE 0.09-0.45 fF) on every tested stack, against 0.23 % (0.080 / 0.111 fF) on the training stack") PHYSICS_CAVEAT = "physics prior alone (no fitted parameter), solved at your stack" def on_training_stack(eps_r: float, thickness_um: float) -> bool: return abs(float(eps_r) - EPS_TRAIN) <= 1e-9 and abs(float(thickness_um) - T_TRAIN) <= 1e-9 def tested_stack(eps_r: float, thickness_um: float) -> bool: e, t = float(eps_r), float(thickness_um) si = abs(e - EPS_TRAIN) <= 1e-9 and TESTED_THICKNESS_UM[0] <= t <= TESTED_THICKNESS_UM[1] return si or (abs(t - T_TRAIN) <= 1e-9 and TESTED_EPS_R[0] <= e <= TESTED_EPS_R[1]) def route(eps_r: float, thickness_um: float, physics_only: bool = False) -> tuple[dict, list]: """(substrate record, warnings) for a recipe that solves its prior at (eps_r, thickness_um).""" e, t = float(eps_r), float(thickness_um) if not (math.isfinite(e) and e >= 1.0): raise ValueError(f"substrate eps_r must be a finite number >= 1 (got {eps_r!r})") if not (math.isfinite(t) and t > 0): raise ValueError(f"substrate thickness must be a finite number > 0 um (got {thickness_um!r})") train = {"eps_r": EPS_TRAIN, "thickness_um": T_TRAIN} rec = {"eps_r": e, "thickness_um": t, "training_stack": train, "embedding_stack": dict(train), "prior_solved_at": {"eps_r": e, "thickness_um": t}, "eps_rescale_factor": None, "tested": True} if on_training_stack(e, t): rec["route"] = "training stack" return rec, [] rec.update(route=ROUTE, tested=tested_stack(e, t), caveat=PHYSICS_CAVEAT if physics_only else CAVEAT) w = [] if not rec["tested"]: w.append(f"substrate eps_r {e:g}, {t:g} um is outside the tested range of the calibrated route (Si eps_r 11.45 at " f"{TESTED_THICKNESS_UM[0]:g}-{TESTED_THICKNESS_UM[1]:g} um, or eps_r {TESTED_EPS_R[0]:g}-{TESTED_EPS_R[1]:g} at " f"{T_TRAIN:g} um): untested, its error is unknown") return rec, w def line(res: dict) -> str: """One Markdown line of a result's substrate route for the Space reports.""" sub = res.get("substrate_route") or {} head = f"**Substrate** {res.get('substrate')} (eps_r {res['eps_r']:g}), {res['thickness_um']:g} µm: " if sub.get("route", "training stack") == "training stack": return head + "the training stack" return head + sub["route"] + ("" if sub.get("tested") else " (UNTESTED combination)") + f". {sub.get('caveat', '')}"