v4 flagship Space (3 tiers) from registry v2 (earlier contents: 906bc45ae05c)
Browse files- .dockerignore +1 -0
- Dockerfile +2 -2
- app.py +35 -2
- geomgnn/SOURCES.json +9 -6
- geomgnn/_tlsq/embed/proxy.py +102 -3
- geomgnn/app_flagship.py +101 -19
- geomgnn/bundle.py +33 -0
- geomgnn/fastprior_pkg.py +9 -3
- geomgnn/paper.py +72 -2
- geomgnn/respcache.py +29 -0
- models/accurate/acc_v2m_sf_s0.pt +2 -2
- models/accurate/acc_v2m_sf_s1.pt +2 -2
- models/accurate/acc_v2m_sf_s2.pt +2 -2
- models/accurate/info.json +6 -0
- models/balanced/bal_v2m_sf_s0.pt +2 -2
- models/balanced/bal_v2m_sf_s1.pt +2 -2
- models/balanced/bal_v2m_sf_s2.pt +2 -2
- models/balanced/info.json +6 -0
- models/fast/acc_v1_s0.pt +2 -2
- models/fast/acc_v1_s1.pt +2 -2
- models/fast/acc_v1_s2.pt +2 -2
- models/fast/info.json +8 -0
- registry.yaml +6 -6
- requirements.txt +10 -12
- warm.py +16 -4
.dockerignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
numba_cache
|
| 2 |
__pycache__
|
|
|
|
|
|
| 1 |
numba_cache
|
| 2 |
__pycache__
|
| 3 |
+
bake
|
Dockerfile
CHANGED
|
@@ -3,10 +3,10 @@ FROM python:3.12-slim
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
USER user
|
| 5 |
ENV SYSTEM=spaces HOME=/home/user PATH=/home/user/.local/bin:$PATH NUMBA_CPU_NAME=generic NUMBA_CACHE_DIR=/home/user/app/numba_cache \
|
| 6 |
-
GRADIO_SERVER_NAME=0.0.0.0 PORT=7860 PYTHONUNBUFFERED=1
|
| 7 |
WORKDIR /home/user/app
|
| 8 |
COPY --chown=user requirements.txt .
|
| 9 |
-
RUN pip install --no-cache-dir --user -r requirements.txt "gradio==6.29.1"
|
| 10 |
COPY --chown=user . .
|
| 11 |
# OAuth Spaces (hf_oauth): Gradio builds real login routes only when SYSTEM=spaces (set above: HF does not set it in Docker
|
| 12 |
# Spaces, but it does pass SPACE_ID and the OAUTH_* variables at run time). At build time those are absent, so warm.py gets
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
USER user
|
| 5 |
ENV SYSTEM=spaces HOME=/home/user PATH=/home/user/.local/bin:$PATH NUMBA_CPU_NAME=generic NUMBA_CACHE_DIR=/home/user/app/numba_cache \
|
| 6 |
+
GRADIO_SERVER_NAME=0.0.0.0 PORT=7860 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=2 OPENBLAS_NUM_THREADS=2 MKL_NUM_THREADS=2
|
| 7 |
WORKDIR /home/user/app
|
| 8 |
COPY --chown=user requirements.txt .
|
| 9 |
+
RUN pip install --no-cache-dir --user -r requirements.txt "gradio==6.29.1" && pip freeze > IMAGE_FREEZE.txt
|
| 10 |
COPY --chown=user . .
|
| 11 |
# OAuth Spaces (hf_oauth): Gradio builds real login routes only when SYSTEM=spaces (set above: HF does not set it in Docker
|
| 12 |
# Spaces, but it does pass SPACE_ID and the OAUTH_* variables at run time). At build time those are absent, so warm.py gets
|
app.py
CHANGED
|
@@ -5,6 +5,8 @@ Balanced, Fast) retrained on all on-stack data, through geomgnn.flagship. Names,
|
|
| 5 |
import os
|
| 6 |
import platform
|
| 7 |
import sys
|
|
|
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
|
| 10 |
if platform.machine() in ("x86_64", "AMD64"): # OpenBLAS SkylakeX Cholesky kernel segfaulted on a v3 MoM system (LIMITS.md)
|
|
@@ -17,6 +19,7 @@ os.environ.setdefault("TLSQ_RESPONSE_CACHE", "64")
|
|
| 17 |
os.environ.setdefault("TLSQ_RESPONSE_CACHE_MB", "1024")
|
| 18 |
os.environ.setdefault("TLSQ_EMBED_CACHE", os.path.join(os.environ.get("TMPDIR", "/tmp"), "tlsq_embed_cache"))
|
| 19 |
os.environ.setdefault("TLSQ_EMBED_CACHE_MB", "1024")
|
|
|
|
| 20 |
os.environ.pop("TLSQ_GNN_PRIOR_MODE", None) # every tier names its own solver mode (registry flagship_hub.prior_stacks)
|
| 21 |
|
| 22 |
HERE = Path(__file__).resolve().parent
|
|
@@ -35,6 +38,7 @@ from tlsq_infer.registry import load_registry # noqa: E402
|
|
| 35 |
|
| 36 |
os.environ.setdefault("TLSQ_NUM_THREADS", str(set_num_threads()))
|
| 37 |
|
|
|
|
| 38 |
from geomgnn.app_flagship import build_app # noqa: E402
|
| 39 |
|
| 40 |
reg = load_registry()
|
|
@@ -49,12 +53,41 @@ if not ex.exists(): # repository checkout: the bundle's examples (sync.py --fla
|
|
| 49 |
f = HERE.parents[2] / "data_local" / "release_core" / "gds" / "ref" / "grid" / src
|
| 50 |
if f.exists():
|
| 51 |
shutil.copy(f, ex / name)
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
FS.preload(reg, example=ex / "interdigital.gds")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
demo = build_app(reg["flagship_hub"]["title"], examples_dir=ex)
|
| 57 |
demo.queue(default_concurrency_limit=int(os.environ.get("TLSQ_CONCURRENCY", 1)), max_size=32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
demo.launch(server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"), server_port=int(os.environ.get("PORT", 7860)))
|
|
|
|
| 5 |
import os
|
| 6 |
import platform
|
| 7 |
import sys
|
| 8 |
+
import threading
|
| 9 |
+
import traceback
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
if platform.machine() in ("x86_64", "AMD64"): # OpenBLAS SkylakeX Cholesky kernel segfaulted on a v3 MoM system (LIMITS.md)
|
|
|
|
| 19 |
os.environ.setdefault("TLSQ_RESPONSE_CACHE_MB", "1024")
|
| 20 |
os.environ.setdefault("TLSQ_EMBED_CACHE", os.path.join(os.environ.get("TMPDIR", "/tmp"), "tlsq_embed_cache"))
|
| 21 |
os.environ.setdefault("TLSQ_EMBED_CACHE_MB", "1024")
|
| 22 |
+
os.environ.setdefault("TLSQ_PRIOR_LEVEL_CACHE_MB", "256") # solved prior levels (Accurate and Balanced share 1.5) and meshes (substrate changes)
|
| 23 |
os.environ.pop("TLSQ_GNN_PRIOR_MODE", None) # every tier names its own solver mode (registry flagship_hub.prior_stacks)
|
| 24 |
|
| 25 |
HERE = Path(__file__).resolve().parent
|
|
|
|
| 38 |
|
| 39 |
os.environ.setdefault("TLSQ_NUM_THREADS", str(set_num_threads()))
|
| 40 |
|
| 41 |
+
from geomgnn import app_flagship as G # noqa: E402
|
| 42 |
from geomgnn.app_flagship import build_app # noqa: E402
|
| 43 |
|
| 44 |
reg = load_registry()
|
|
|
|
| 53 |
f = HERE.parents[2] / "data_local" / "release_core" / "gds" / "ref" / "grid" / src
|
| 54 |
if f.exists():
|
| 55 |
shutil.copy(f, ex / name)
|
| 56 |
+
BAKE = Path(os.environ.get("TLSQ_RESPONSE_BAKE", HERE / "bake" / "respcache.pkl")) # the examples' results, baked at image build
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def preload():
|
| 60 |
+
"""Load every tier (SHA checks) + numba warmup + one small prediction; then the baked example results, if they verify here."""
|
| 61 |
+
from geomgnn import flagship as FS
|
| 62 |
+
from geomgnn import paper as PA
|
| 63 |
|
| 64 |
FS.preload(reg, example=ex / "interdigital.gds")
|
| 65 |
+
if BAKE.exists() and int(os.environ.get("TLSQ_RESPONSE_CACHE", "0")) > 0:
|
| 66 |
+
PA.STARTUP["bake"] = G.load_bake(BAKE, ex)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _preload_background():
|
| 70 |
+
try:
|
| 71 |
+
preload()
|
| 72 |
+
except BaseException: # noqa: BLE001 (a Space that cannot load its models must not serve)
|
| 73 |
+
traceback.print_exc()
|
| 74 |
+
os._exit(1)
|
| 75 |
+
G.READY.set()
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def bake():
|
| 79 |
+
"""Image build (warm.py, after the import's preload): every example x tier into the response cache, pickled to BAKE."""
|
| 80 |
+
return G.bake(ex, BAKE)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
demo = build_app(reg["flagship_hub"]["title"], examples_dir=ex)
|
| 84 |
demo.queue(default_concurrency_limit=int(os.environ.get("TLSQ_CONCURRENCY", 1)), max_size=32)
|
| 85 |
+
if os.environ.get("TLSQ_PRELOAD", "1") != "0":
|
| 86 |
+
if __name__ == "__main__": # the server: the page is up while the tiers load; predictions wait for them (G.READY)
|
| 87 |
+
G.READY.clear()
|
| 88 |
+
threading.Thread(target=_preload_background, name="preload", daemon=True).start()
|
| 89 |
+
else: # imported (warm.py, tests): load before returning
|
| 90 |
+
preload()
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
demo.launch(server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"), server_port=int(os.environ.get("PORT", 7860)))
|
geomgnn/SOURCES.json
CHANGED
|
@@ -21,10 +21,13 @@
|
|
| 21 |
"rewrites": []
|
| 22 |
},
|
| 23 |
"_tlsq/embed/proxy.py": {
|
| 24 |
-
"source": "/Users/shanto/
|
| 25 |
-
"source_sha256": "
|
| 26 |
-
"sha256": "
|
| 27 |
-
"rewrites": []
|
|
|
|
|
|
|
|
|
|
| 28 |
},
|
| 29 |
"_tlsq/embed/fastprior.py": {
|
| 30 |
"source": "/Users/shanto/Documents/ChatGPT/transfer_learning/geomfast_stage/vendor/tlsq/embed/fastprior.py",
|
|
@@ -162,8 +165,8 @@
|
|
| 162 |
},
|
| 163 |
"fastprior_pkg.py": {
|
| 164 |
"source": "/Users/shanto/LFL/tl_squadds/scripts/fastprior_pkg/fastprior_pkg.py",
|
| 165 |
-
"source_sha256": "
|
| 166 |
-
"sha256": "
|
| 167 |
"rewrites": [],
|
| 168 |
"note": "gated fast-solve package (agents/fastprior_pkg/RESULTS.md), verbatim; bound with bind('geomgnn'); vendored 2026-10-17"
|
| 169 |
},
|
|
|
|
| 21 |
"rewrites": []
|
| 22 |
},
|
| 23 |
"_tlsq/embed/proxy.py": {
|
| 24 |
+
"source": "/Users/shanto/LFL/tl_squadds/src/tlsq/embed/proxy.py",
|
| 25 |
+
"source_sha256": "f87a0f1614ca93b73aac0747d0acdafbd9b8c243f69c68c98d8919e158a57b28",
|
| 26 |
+
"sha256": "f87a0f1614ca93b73aac0747d0acdafbd9b8c243f69c68c98d8919e158a57b28",
|
| 27 |
+
"rewrites": [],
|
| 28 |
+
"note": "phase B speed-up (2026-11-15): the training-source copy src/tlsq/embed/proxy.py (byte-identical); row-blocked image table, bounded image-table cache, compiled bitwise interpolation (np.interp fallback); every prior bit-identical to the frozen stage file",
|
| 29 |
+
"frozen_stage_source": "/Users/shanto/Documents/ChatGPT/transfer_learning/geomfast_stage/vendor/tlsq/embed/proxy.py",
|
| 30 |
+
"frozen_stage_sha256": "78d8dffd2fac75632a91ebee151247afe4157716ffb11e624e6b2932c618c86e"
|
| 31 |
},
|
| 32 |
"_tlsq/embed/fastprior.py": {
|
| 33 |
"source": "/Users/shanto/Documents/ChatGPT/transfer_learning/geomfast_stage/vendor/tlsq/embed/fastprior.py",
|
|
|
|
| 165 |
},
|
| 166 |
"fastprior_pkg.py": {
|
| 167 |
"source": "/Users/shanto/LFL/tl_squadds/scripts/fastprior_pkg/fastprior_pkg.py",
|
| 168 |
+
"source_sha256": "4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a",
|
| 169 |
+
"sha256": "4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a",
|
| 170 |
"rewrites": [],
|
| 171 |
"note": "gated fast-solve package (agents/fastprior_pkg/RESULTS.md), verbatim; bound with bind('geomgnn'); vendored 2026-10-17"
|
| 172 |
},
|
geomgnn/_tlsq/embed/proxy.py
CHANGED
|
@@ -17,6 +17,7 @@ from __future__ import annotations
|
|
| 17 |
import os
|
| 18 |
import queue
|
| 19 |
import threading
|
|
|
|
| 20 |
from concurrent.futures import ThreadPoolExecutor
|
| 21 |
from functools import partial
|
| 22 |
|
|
@@ -440,8 +441,97 @@ def _near_pairs(c, hm):
|
|
| 440 |
|
| 441 |
|
| 442 |
SUBSTRATE = {"model": "slab_open", "t_um": 350.0} # MoM Green's function (PRIOR_SCHEME.md 14.6): "slab_open" (default since 2026-10-10: 350 um substrate, vacuum below), "halfspace" (released models' priors), "slab_pec"
|
| 443 |
-
_IMG_CACHE:
|
| 444 |
_IMG_GRID: dict = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
|
| 446 |
|
| 447 |
class substrate:
|
|
@@ -474,7 +564,9 @@ def _image_correction(d, eps_r: float, exact: bool = False):
|
|
| 474 |
if m == "halfspace":
|
| 475 |
return None
|
| 476 |
key = (m, float(SUBSTRATE["t_um"]), float(eps_r))
|
| 477 |
-
if key
|
|
|
|
|
|
|
| 478 |
K, t = (eps_r - 1) / (eps_r + 1), float(SUBSTRATE["t_um"])
|
| 479 |
n = np.arange(1, 400)
|
| 480 |
nmax = int(np.argmax(K ** (2 * n) < 1e-4)) + 1
|
|
@@ -486,13 +578,20 @@ def _image_correction(d, eps_r: float, exact: bool = False):
|
|
| 486 |
w, D = np.r_[w, total - w.sum()], np.r_[2 * n * t, 2 * (nmax + 1) * t]
|
| 487 |
du = t / 1000
|
| 488 |
u = np.arange(0.0, 1e5 + 2 * du, du)
|
| 489 |
-
T =
|
|
|
|
|
|
|
|
|
|
| 490 |
_IMG_CACHE[key] = (du, T, w, D)
|
|
|
|
| 491 |
du, T = _IMG_CACHE[key][:2]
|
| 492 |
if exact:
|
| 493 |
w, D = _IMG_CACHE[key][2:]
|
| 494 |
d2 = np.asarray(d, float) ** 2
|
| 495 |
return sum(wn / np.sqrt(d2 + Dn * Dn) for wn, Dn in zip(w, D))
|
|
|
|
|
|
|
|
|
|
| 496 |
if key not in _IMG_GRID:
|
| 497 |
_IMG_GRID[key] = du * np.arange(len(T))
|
| 498 |
return np.interp(d, _IMG_GRID[key], T)
|
|
|
|
| 17 |
import os
|
| 18 |
import queue
|
| 19 |
import threading
|
| 20 |
+
from collections import OrderedDict
|
| 21 |
from concurrent.futures import ThreadPoolExecutor
|
| 22 |
from functools import partial
|
| 23 |
|
|
|
|
| 441 |
|
| 442 |
|
| 443 |
SUBSTRATE = {"model": "slab_open", "t_um": 350.0} # MoM Green's function (PRIOR_SCHEME.md 14.6): "slab_open" (default since 2026-10-10: 350 um substrate, vacuum below), "halfspace" (released models' priors), "slab_pec"
|
| 444 |
+
_IMG_CACHE: OrderedDict = OrderedDict() # LRU of image tables (model, t_um, eps_r) -> (du, T, w, D)
|
| 445 |
_IMG_GRID: dict = {}
|
| 446 |
+
_IMG_KEEP = (4, 512 << 20) # at most 4 tables and 512 MB (the newest is always kept)
|
| 447 |
+
_INTERP: dict = {}
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
def _img_evict():
|
| 451 |
+
while len(_IMG_CACHE) > 1 and (len(_IMG_CACHE) > _IMG_KEEP[0] or sum(v[1].nbytes for v in _IMG_CACHE.values())
|
| 452 |
+
+ sum(g.nbytes for g in _IMG_GRID.values()) > _IMG_KEEP[1]):
|
| 453 |
+
_IMG_GRID.pop(_IMG_CACHE.popitem(last=False)[0], None)
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
try: # compiled np.interp on the uniform image table (_interp_uniform)
|
| 457 |
+
import numba as _nb
|
| 458 |
+
from numba.core import types as _nbt
|
| 459 |
+
from numba.extending import intrinsic as _intrinsic
|
| 460 |
+
|
| 461 |
+
@_intrinsic
|
| 462 |
+
def _fma(typingctx, a, b, c):
|
| 463 |
+
def gen(context, builder, sig, args):
|
| 464 |
+
return builder.fma(*args)
|
| 465 |
+
return _nbt.float64(_nbt.float64, _nbt.float64, _nbt.float64), gen
|
| 466 |
+
|
| 467 |
+
@_nb.njit(nogil=True, cache=True)
|
| 468 |
+
def _interp_run(x, du, fp, out, fused):
|
| 469 |
+
"""numpy's arr_interp on xp_j = du * j: the index by division, corrected with numpy's comparisons, then numpy's slope
|
| 470 |
+
and slope * (x - xp_j) + fp_j, plain or fused (fma) as this numpy build's C compiler does it."""
|
| 471 |
+
n = fp.shape[0]
|
| 472 |
+
last = du * (n - 1)
|
| 473 |
+
for i in range(x.shape[0]):
|
| 474 |
+
v = x[i]
|
| 475 |
+
if v != v:
|
| 476 |
+
out[i] = v
|
| 477 |
+
continue
|
| 478 |
+
if v > last:
|
| 479 |
+
out[i] = fp[n - 1]
|
| 480 |
+
continue
|
| 481 |
+
if v < 0.0:
|
| 482 |
+
out[i] = fp[0]
|
| 483 |
+
continue
|
| 484 |
+
j = min(int(v / du), n - 1)
|
| 485 |
+
while j > 0 and du * j > v:
|
| 486 |
+
j -= 1
|
| 487 |
+
while j < n - 1 and du * (j + 1) <= v:
|
| 488 |
+
j += 1
|
| 489 |
+
xj = du * j
|
| 490 |
+
if j == n - 1 or xj == v:
|
| 491 |
+
out[i] = fp[j]
|
| 492 |
+
continue
|
| 493 |
+
x1 = du * (j + 1)
|
| 494 |
+
s = (fp[j + 1] - fp[j]) / (x1 - xj)
|
| 495 |
+
r = _fma(s, v - xj, fp[j]) if fused else s * (v - xj) + fp[j]
|
| 496 |
+
if r != r:
|
| 497 |
+
r = _fma(s, v - x1, fp[j + 1]) if fused else s * (v - x1) + fp[j + 1]
|
| 498 |
+
if r != r and fp[j] == fp[j + 1]:
|
| 499 |
+
r = fp[j]
|
| 500 |
+
out[i] = r
|
| 501 |
+
except ImportError:
|
| 502 |
+
_interp_run = None
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
def _interp_uniform(d, du, T):
|
| 506 |
+
"""np.interp(d, du * arange(len(T)), T), bit for bit: the compiled kernel (plain or fused multiply-add, whichever matches this
|
| 507 |
+
numpy build) when a probe at first use matches np.interp bit for bit, else None (the caller uses np.interp)."""
|
| 508 |
+
if "fn" not in _INTERP:
|
| 509 |
+
_INTERP["fn"] = None
|
| 510 |
+
if _interp_run is not None:
|
| 511 |
+
try:
|
| 512 |
+
rng, ok = np.random.default_rng(0), []
|
| 513 |
+
for fp in (rng.normal(size=4096), T): # a rough table tells the two apart, then the real one
|
| 514 |
+
xp = du * np.arange(len(fp))
|
| 515 |
+
x = np.concatenate([rng.uniform(-1, 1.01 * xp[-1], 50000), rng.uniform(0, 64 * du, 20000), xp[rng.integers(0, len(fp), 2000)],
|
| 516 |
+
np.nextafter(xp[rng.integers(1, len(fp), 2000)], 0), xp[[0, -1]], [np.nan, np.inf, 1e300]])
|
| 517 |
+
ref, got = np.interp(x, xp, fp).tobytes(), []
|
| 518 |
+
for fused in (False, True):
|
| 519 |
+
y = np.empty_like(x)
|
| 520 |
+
_interp_run(x, du, fp, y, fused)
|
| 521 |
+
got.append(y.tobytes())
|
| 522 |
+
ok.append([g == ref for g in got])
|
| 523 |
+
if ok[0][0] != ok[0][1] and ok[1][ok[0][1]]:
|
| 524 |
+
_INTERP["fn"] = ok[0][1]
|
| 525 |
+
except Exception: # noqa: BLE001 (llvm.fma or the compile unavailable: np.interp)
|
| 526 |
+
pass
|
| 527 |
+
fused = _INTERP["fn"]
|
| 528 |
+
d = np.asarray(d, float)
|
| 529 |
+
if fused is None or d.ndim == 0:
|
| 530 |
+
return None
|
| 531 |
+
x = np.ascontiguousarray(d)
|
| 532 |
+
out = np.empty(x.shape)
|
| 533 |
+
_interp_run(x.reshape(-1), du, T, out.reshape(-1), fused)
|
| 534 |
+
return out
|
| 535 |
|
| 536 |
|
| 537 |
class substrate:
|
|
|
|
| 564 |
if m == "halfspace":
|
| 565 |
return None
|
| 566 |
key = (m, float(SUBSTRATE["t_um"]), float(eps_r))
|
| 567 |
+
if key in _IMG_CACHE:
|
| 568 |
+
_IMG_CACHE.move_to_end(key)
|
| 569 |
+
else:
|
| 570 |
K, t = (eps_r - 1) / (eps_r + 1), float(SUBSTRATE["t_um"])
|
| 571 |
n = np.arange(1, 400)
|
| 572 |
nmax = int(np.argmax(K ** (2 * n) < 1e-4)) + 1
|
|
|
|
| 578 |
w, D = np.r_[w, total - w.sum()], np.r_[2 * n * t, 2 * (nmax + 1) * t]
|
| 579 |
du = t / 1000
|
| 580 |
u = np.arange(0.0, 1e5 + 2 * du, du)
|
| 581 |
+
T = np.empty(len(u))
|
| 582 |
+
for i in range(0, len(u), 1 << 18): # row blocks: the same sums, without len(u) x images temporaries (~8 GB at 10 um)
|
| 583 |
+
ub = u[i:i + (1 << 18)]
|
| 584 |
+
T[i:i + len(ub)] = (w[None, :] / np.sqrt(ub[:, None] ** 2 + D[None, :] ** 2)).sum(1)
|
| 585 |
_IMG_CACHE[key] = (du, T, w, D)
|
| 586 |
+
_img_evict()
|
| 587 |
du, T = _IMG_CACHE[key][:2]
|
| 588 |
if exact:
|
| 589 |
w, D = _IMG_CACHE[key][2:]
|
| 590 |
d2 = np.asarray(d, float) ** 2
|
| 591 |
return sum(wn / np.sqrt(d2 + Dn * Dn) for wn, Dn in zip(w, D))
|
| 592 |
+
out = _interp_uniform(d, du, T)
|
| 593 |
+
if out is not None:
|
| 594 |
+
return out
|
| 595 |
if key not in _IMG_GRID:
|
| 596 |
_IMG_GRID[key] = du * np.arange(len(T))
|
| 597 |
return np.interp(d, _IMG_GRID[key], T)
|
geomgnn/app_flagship.py
CHANGED
|
@@ -20,6 +20,7 @@ from __future__ import annotations
|
|
| 20 |
import functools
|
| 21 |
import html
|
| 22 |
import json
|
|
|
|
| 23 |
import time
|
| 24 |
from pathlib import Path
|
| 25 |
|
|
@@ -34,12 +35,18 @@ from tlsq_infer.registry import load_registry
|
|
| 34 |
from . import __version__
|
| 35 |
from . import access as AC
|
| 36 |
from . import api as A
|
|
|
|
| 37 |
from . import ground_ui as GU
|
| 38 |
from . import flagship as FS
|
| 39 |
from . import ui as UI
|
| 40 |
from . import usage as U
|
| 41 |
|
|
|
|
| 42 |
ORDER = ["accurate", "balanced", "fast"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
def served(reg=None) -> list[str]:
|
|
@@ -74,10 +81,25 @@ def expected(reg, k) -> str | None:
|
|
| 74 |
return f"Expect an error of {UI.pct(b5)} on a new design of a trained family. We measured this on 39 layouts the model never saw." if b5 else None
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def _predict(lay, model, substrate, thickness_um, w=None, own=False):
|
| 78 |
from . import respcache
|
|
|
|
| 79 |
reg = load_registry()
|
| 80 |
name = resolve(reg, model)
|
|
|
|
| 81 |
AC.check_size(lay.n_conductors)
|
| 82 |
fn = lambda: FS.predict(lay, name, reg, substrate=substrate, thickness_um=thickness_um) # noqa: E731
|
| 83 |
if lay.n_conductors > 8:
|
|
@@ -87,10 +109,10 @@ def _predict(lay, model, substrate, thickness_um, w=None, own=False):
|
|
| 87 |
with HEAVY:
|
| 88 |
return fn0()
|
| 89 |
w = w or AC.Who()
|
| 90 |
-
|
| 91 |
-
if not respcache.has(lay,
|
| 92 |
AC.QUOTA.check(w, own)
|
| 93 |
-
res = respcache.cached(lay,
|
| 94 |
if not res["timing_s"].get("response_cache_hit"):
|
| 95 |
AC.QUOTA.charge(w, own)
|
| 96 |
return res
|
|
@@ -187,19 +209,65 @@ def inspect_gfn(f, profile: gr.OAuthProfile | None = None, oauth_token: gr.OAuth
|
|
| 187 |
return inspect_fn(f)
|
| 188 |
|
| 189 |
|
| 190 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
custom_eps=11.45, thickness_um=350.0, model="accurate", ground_pieces="", profile: gr.OAuthProfile | None = None,
|
| 192 |
oauth_token: gr.OAuthToken | None = None, request: gr.Request = None):
|
| 193 |
t = time.perf_counter()
|
| 194 |
-
lay, res = _served(AC.who(profile, request, oauth_token), f, lambda:
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
model, _eps(substrate, custom_eps), float(thickness_um))
|
| 198 |
res["timing_s"]["prepare_and_total_s"] = time.perf_counter() - t
|
| 199 |
res["ground_detection"] = lay.info.get("ground_detection")
|
| 200 |
return res
|
| 201 |
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
def models_fn():
|
| 204 |
reg = load_registry()
|
| 205 |
h = reg["flagship_hub"]
|
|
@@ -213,7 +281,19 @@ def models_fn():
|
|
| 213 |
from . import paper as PA
|
| 214 |
return out + [{"geomgnn_version": __version__, "tlsq_infer_version": TLSQ_VERSION, "registry_version": reg["version"],
|
| 215 |
"training_layouts": h.get("training_layouts"),
|
| 216 |
-
"startup": dict(PA.STARTUP)}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
|
| 219 |
def limits() -> dict:
|
|
@@ -530,27 +610,29 @@ def build_app(title: str, examples_dir=None):
|
|
| 530 |
ui_predict = functools.wraps(predict_fn)(UI.predict_ui(predict_fn, lambda r: expected(reg, r["tier"]), note=True))
|
| 531 |
ui_predict.__name__ = "predict_fn_ui"
|
| 532 |
uouts = pouts + [status, result_box, mat_note]
|
| 533 |
-
|
|
|
|
|
|
|
| 534 |
substrate.change(lambda s: gr.update(visible=s == CUSTOM), substrate, custom_eps, **hidden)
|
| 535 |
for ev in (substrate.change, custom_eps.change, thickness.change):
|
| 536 |
ev(lambda s, e, t: stack_note(reg, s, e, t), [substrate, custom_eps, thickness], sub_note, **hidden)
|
| 537 |
crop.change(lambda c: gr.update(visible=bool(c)), crop, crop_row, **hidden)
|
| 538 |
up = gds.change(upload_fn, [gds, view], [layers, layer_acc, layer_help, upload_msg, pick, role, img, svg_btn, viewbar, vst, view_msg],
|
| 539 |
-
api_visibility="private")
|
| 540 |
-
view.input(show_view, vin, vout, api_visibility="private")
|
| 541 |
-
i_btn.click(_api(inspect_gfn, 2), gds, [layers, layer_plot], api_name="inspect")
|
| 542 |
edit = UI.wire_editor(layers, pick, role)
|
| 543 |
edit.then(lambda t: gr.update(label=_roles_label(t)), layers, layer_acc, **hidden)
|
| 544 |
r_btn.click(_api(prepare_gfn, 4), [gds, layers, crop, margin, margin_um, select, gst], [prep_plot, warn_md, summary, prepared_gds],
|
| 545 |
-
api_name="prepare")
|
| 546 |
after = lambda ev: ev.then(refresh_view, vin, vout, **hidden) # noqa: E731
|
| 547 |
-
GU.wire(gds, layers, pred_btn, gparts, [up, edit], after=after).then(ui_predict, pins, uouts, api_visibility="private")
|
| 548 |
for ev in (crop.change, margin.change, margin_um.change, select.change):
|
| 549 |
ev(preview_fn, vin, [view] + vout, trigger_mode="always_last", **hidden)
|
| 550 |
-
pred_btn.click(ui_predict, pins, uouts, api_visibility="private")
|
| 551 |
-
p_btn.click(_api(predict_fn, 5), pins, pouts, api_name="predict")
|
| 552 |
UI.mark_stale(res_state, status, mat, report, [gds.change, model.change, substrate.change, custom_eps.change, thickness.change,
|
| 553 |
select.change, crop.change, margin.change, margin_um.change, edit.then])
|
| 554 |
-
a_btn.click(_api(api_predict_gds, 1), [gds, a_g, a_c, a_m, substrate, custom_eps, thickness, model, a_gp], a_out, api_name="predict_gds")
|
| 555 |
-
m_btn.click(models_fn, None, m_out, api_name="models")
|
| 556 |
return demo
|
|
|
|
| 20 |
import functools
|
| 21 |
import html
|
| 22 |
import json
|
| 23 |
+
import threading
|
| 24 |
import time
|
| 25 |
from pathlib import Path
|
| 26 |
|
|
|
|
| 35 |
from . import __version__
|
| 36 |
from . import access as AC
|
| 37 |
from . import api as A
|
| 38 |
+
from . import bundle
|
| 39 |
from . import ground_ui as GU
|
| 40 |
from . import flagship as FS
|
| 41 |
from . import ui as UI
|
| 42 |
from . import usage as U
|
| 43 |
|
| 44 |
+
bundle.install()
|
| 45 |
ORDER = ["accurate", "balanced", "fast"]
|
| 46 |
+
MIN_THICKNESS_UM = 1.0
|
| 47 |
+
SI = "Si (cryogenic, training)"
|
| 48 |
+
READY = threading.Event() # cleared by the Space entry while the tiers load in the background; every predict waits for it
|
| 49 |
+
READY.set()
|
| 50 |
|
| 51 |
|
| 52 |
def served(reg=None) -> list[str]:
|
|
|
|
| 81 |
return f"Expect an error of {UI.pct(b5)} on a new design of a trained family. We measured this on 39 layouts the model never saw." if b5 else None
|
| 82 |
|
| 83 |
|
| 84 |
+
def check_thickness(thickness_um) -> float:
|
| 85 |
+
t = float(thickness_um)
|
| 86 |
+
if not t >= MIN_THICKNESS_UM:
|
| 87 |
+
raise ValueError(f"The substrate must be at least {MIN_THICKNESS_UM:g} µm thick (got {thickness_um!r} µm). The models are "
|
| 88 |
+
"tested on substrates of 10-1000 µm.")
|
| 89 |
+
return t
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def settings(reg, name, substrate, thickness_um) -> tuple:
|
| 93 |
+
"""The response-cache settings of a request (with the prepared layout, the cache key)."""
|
| 94 |
+
return ("flagship", name, str(substrate), float(thickness_um), reg["version"])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
def _predict(lay, model, substrate, thickness_um, w=None, own=False):
|
| 98 |
from . import respcache
|
| 99 |
+
READY.wait()
|
| 100 |
reg = load_registry()
|
| 101 |
name = resolve(reg, model)
|
| 102 |
+
check_thickness(thickness_um)
|
| 103 |
AC.check_size(lay.n_conductors)
|
| 104 |
fn = lambda: FS.predict(lay, name, reg, substrate=substrate, thickness_um=thickness_um) # noqa: E731
|
| 105 |
if lay.n_conductors > 8:
|
|
|
|
| 109 |
with HEAVY:
|
| 110 |
return fn0()
|
| 111 |
w = w or AC.Who()
|
| 112 |
+
st = settings(reg, name, substrate, thickness_um)
|
| 113 |
+
if not respcache.has(lay, st):
|
| 114 |
AC.QUOTA.check(w, own)
|
| 115 |
+
res = respcache.cached(lay, st, fn)
|
| 116 |
if not res["timing_s"].get("response_cache_hit"):
|
| 117 |
AC.QUOTA.charge(w, own)
|
| 118 |
return res
|
|
|
|
| 209 |
return inspect_fn(f)
|
| 210 |
|
| 211 |
|
| 212 |
+
def _api_layout(f, ground_layers="1/0", conductor_layers="1/10", margin_gaps=0.0, ground_pieces=""):
|
| 213 |
+
return prepare(_path(f), ground_layers=_parse_layers(ground_layers), conductor_layers=_parse_layers(conductor_layers),
|
| 214 |
+
margin_gaps=_margin_api(margin_gaps), max_conductors=LIMITS["max_conductors"],
|
| 215 |
+
ground_pieces=str(ground_pieces or "").strip() or None)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def api_predict_gds(f, ground_layers="1/0", conductor_layers="1/10", margin_gaps=0.0, substrate=SI,
|
| 219 |
custom_eps=11.45, thickness_um=350.0, model="accurate", ground_pieces="", profile: gr.OAuthProfile | None = None,
|
| 220 |
oauth_token: gr.OAuthToken | None = None, request: gr.Request = None):
|
| 221 |
t = time.perf_counter()
|
| 222 |
+
lay, res = _served(AC.who(profile, request, oauth_token), f, lambda: _api_layout(f, ground_layers, conductor_layers, margin_gaps,
|
| 223 |
+
ground_pieces),
|
| 224 |
+
model, _eps(substrate, custom_eps), float(thickness_um))
|
|
|
|
| 225 |
res["timing_s"]["prepare_and_total_s"] = time.perf_counter() - t
|
| 226 |
res["ground_detection"] = lay.info.get("ground_detection")
|
| 227 |
return res
|
| 228 |
|
| 229 |
|
| 230 |
+
def bake(examples_dir, path) -> dict:
|
| 231 |
+
"""Image build: every bundled example x tier on the training stack, through /predict_gds and the UI Predict path (an example click),
|
| 232 |
+
into the response cache, pickled to path. Both paths prepare the same layout, so they share one entry per example and tier."""
|
| 233 |
+
from . import respcache
|
| 234 |
+
reg = load_registry()
|
| 235 |
+
t = time.perf_counter()
|
| 236 |
+
for f in sorted(Path(examples_dir).glob("*.gds")):
|
| 237 |
+
table = inspect_fn(str(f))[0]
|
| 238 |
+
gstate = GU.check_fn(str(f), table)[4]
|
| 239 |
+
for tier in served(reg):
|
| 240 |
+
api_predict_gds(str(f), model=tier)
|
| 241 |
+
predict_fn(str(f), table, False, 0, None, "", SI, 11.45, 350, tier, gstate)
|
| 242 |
+
out = {"entries": respcache.dump(path), "s": round(time.perf_counter() - t, 1)}
|
| 243 |
+
print("bake " + json.dumps(out), flush=True)
|
| 244 |
+
return out
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _same(a: dict, b: dict) -> bool:
|
| 248 |
+
return {k: v for k, v in a.items() if k != "timing_s"} == {k: v for k, v in b.items() if k != "timing_s"}
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def load_bake(path, examples_dir) -> dict:
|
| 252 |
+
"""Server start: the baked example results join the response cache only if this machine recomputes the interdigital example
|
| 253 |
+
bit for bit on every tier (same packages, CPU code paths and threads as the image build); otherwise they are dropped."""
|
| 254 |
+
from . import respcache
|
| 255 |
+
reg = load_registry()
|
| 256 |
+
t = time.perf_counter()
|
| 257 |
+
items = respcache.load_items(path)
|
| 258 |
+
baked = dict(items)
|
| 259 |
+
for tier in served(reg):
|
| 260 |
+
lay = _api_layout(str(Path(examples_dir) / "interdigital.gds"))
|
| 261 |
+
old = baked.get(respcache.key(lay, *settings(reg, tier, SI, 350.0)), (None,))[0]
|
| 262 |
+
if old is None or not _same(old, FS.predict(lay, tier, reg, substrate=SI, thickness_um=350.0)):
|
| 263 |
+
out = {"bake": "dropped", "reason": f"interdigital / {tier} differs from the baked result", "s": time.perf_counter() - t}
|
| 264 |
+
break
|
| 265 |
+
else:
|
| 266 |
+
out = {"bake": "loaded", "entries": len(items), "cache_entries": respcache.put_many(items), "s": time.perf_counter() - t}
|
| 267 |
+
print("bake " + json.dumps(out, default=float), flush=True)
|
| 268 |
+
return out
|
| 269 |
+
|
| 270 |
+
|
| 271 |
def models_fn():
|
| 272 |
reg = load_registry()
|
| 273 |
h = reg["flagship_hub"]
|
|
|
|
| 281 |
from . import paper as PA
|
| 282 |
return out + [{"geomgnn_version": __version__, "tlsq_infer_version": TLSQ_VERSION, "registry_version": reg["version"],
|
| 283 |
"training_layouts": h.get("training_layouts"),
|
| 284 |
+
"startup": dict(PA.STARTUP), "packages": packages()}]
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def packages() -> dict:
|
| 288 |
+
"""Versions of the main packages (the image's full list: IMAGE_FREEZE.txt next to app.py, Docker variant)."""
|
| 289 |
+
from importlib.metadata import PackageNotFoundError, version
|
| 290 |
+
out = {}
|
| 291 |
+
for p in ("torch", "numpy", "scipy", "numba", "shapely", "gdstk", "gradio"):
|
| 292 |
+
try:
|
| 293 |
+
out[p] = version(p)
|
| 294 |
+
except PackageNotFoundError:
|
| 295 |
+
out[p] = None
|
| 296 |
+
return out
|
| 297 |
|
| 298 |
|
| 299 |
def limits() -> dict:
|
|
|
|
| 610 |
ui_predict = functools.wraps(predict_fn)(UI.predict_ui(predict_fn, lambda r: expected(reg, r["tier"]), note=True))
|
| 611 |
ui_predict.__name__ = "predict_fn_ui"
|
| 612 |
uouts = pouts + [status, result_box, mat_note]
|
| 613 |
+
light = dict(concurrency_id="light", concurrency_limit=1) # previews and file handling: never queued behind a solve
|
| 614 |
+
solve = dict(concurrency_id="predict", concurrency_limit=1) # every predict path: one at a time (process-global prior stack)
|
| 615 |
+
hidden = dict(api_visibility="private", show_progress="hidden", **light)
|
| 616 |
substrate.change(lambda s: gr.update(visible=s == CUSTOM), substrate, custom_eps, **hidden)
|
| 617 |
for ev in (substrate.change, custom_eps.change, thickness.change):
|
| 618 |
ev(lambda s, e, t: stack_note(reg, s, e, t), [substrate, custom_eps, thickness], sub_note, **hidden)
|
| 619 |
crop.change(lambda c: gr.update(visible=bool(c)), crop, crop_row, **hidden)
|
| 620 |
up = gds.change(upload_fn, [gds, view], [layers, layer_acc, layer_help, upload_msg, pick, role, img, svg_btn, viewbar, vst, view_msg],
|
| 621 |
+
api_visibility="private", **light)
|
| 622 |
+
view.input(show_view, vin, vout, api_visibility="private", **light)
|
| 623 |
+
i_btn.click(_api(inspect_gfn, 2), gds, [layers, layer_plot], api_name="inspect", **light)
|
| 624 |
edit = UI.wire_editor(layers, pick, role)
|
| 625 |
edit.then(lambda t: gr.update(label=_roles_label(t)), layers, layer_acc, **hidden)
|
| 626 |
r_btn.click(_api(prepare_gfn, 4), [gds, layers, crop, margin, margin_um, select, gst], [prep_plot, warn_md, summary, prepared_gds],
|
| 627 |
+
api_name="prepare", **light)
|
| 628 |
after = lambda ev: ev.then(refresh_view, vin, vout, **hidden) # noqa: E731
|
| 629 |
+
GU.wire(gds, layers, pred_btn, gparts, [up, edit], after=after).then(ui_predict, pins, uouts, api_visibility="private", **solve)
|
| 630 |
for ev in (crop.change, margin.change, margin_um.change, select.change):
|
| 631 |
ev(preview_fn, vin, [view] + vout, trigger_mode="always_last", **hidden)
|
| 632 |
+
pred_btn.click(ui_predict, pins, uouts, api_visibility="private", **solve)
|
| 633 |
+
p_btn.click(_api(predict_fn, 5), pins, pouts, api_name="predict", **solve)
|
| 634 |
UI.mark_stale(res_state, status, mat, report, [gds.change, model.change, substrate.change, custom_eps.change, thickness.change,
|
| 635 |
select.change, crop.change, margin.change, margin_um.change, edit.then])
|
| 636 |
+
a_btn.click(_api(api_predict_gds, 1), [gds, a_g, a_c, a_m, substrate, custom_eps, thickness, model, a_gp], a_out, api_name="predict_gds", **solve)
|
| 637 |
+
m_btn.click(models_fn, None, m_out, api_name="models", **light)
|
| 638 |
return demo
|
geomgnn/bundle.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Integrity check of a Space bundle's checkpoint copies. deploy/sync.py --flagship ships each checkpoint without its train_keys (unused at
|
| 2 |
+
inference) and records both hashes in models/<tier>/info.json: <key>_sha256 = the published checkpoint (= registry, the provenance) and
|
| 3 |
+
<key>_bundle_sha256 = the shipped copy. install() makes geomgnn.paper check the copy against the latter; folders without
|
| 4 |
+
*_bundle_sha256 and the registry's source paths keep the registry check unchanged."""
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from . import paper as PA
|
| 11 |
+
|
| 12 |
+
_REGISTRY_CHECK = PA._check
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _check(reg, name, model_dir=None):
|
| 16 |
+
md = PA._model_dir(model_dir)
|
| 17 |
+
info = Path(md) / name / "info.json" if md else None
|
| 18 |
+
z = json.loads(info.read_text()) if info is not None and info.exists() else {}
|
| 19 |
+
if "checkpoints_bundle_sha256" not in z:
|
| 20 |
+
return _REGISTRY_CHECK(reg, name, model_dir)
|
| 21 |
+
a = PA.arms(reg)[name]
|
| 22 |
+
for key in ("checkpoints", "surrogate"):
|
| 23 |
+
fs, hs = PA.files(reg, name, key, model_dir), z.get(key + "_bundle_sha256") or []
|
| 24 |
+
if z.get(key + "_sha256", []) != PA._hashes(a, key) or len(fs) != len(hs):
|
| 25 |
+
raise RuntimeError(f"{name}: {info} does not list the registry's {key} (sha256)")
|
| 26 |
+
for f, h in zip(fs, hs):
|
| 27 |
+
if PA._sha(f) != h:
|
| 28 |
+
raise RuntimeError(f"{name}: {f.name} SHA256 differs from the bundle manifest ({h[:12]})")
|
| 29 |
+
return a
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def install() -> None:
|
| 33 |
+
PA._check = _check
|
geomgnn/fastprior_pkg.py
CHANGED
|
@@ -823,7 +823,7 @@ def _mixed_chol(A, B):
|
|
| 823 |
try:
|
| 824 |
cf = cho_factor(A.astype(np.float32, order="F"), lower=True, overwrite_a=True, check_finite=False)
|
| 825 |
except np.linalg.LinAlgError:
|
| 826 |
-
return _ORIG["chol_solve"](A, B)
|
| 827 |
B = np.asfortranarray(B, dtype=float)
|
| 828 |
X = cho_solve(cf, B.astype(np.float32), check_finite=False).astype(float)
|
| 829 |
bn = np.linalg.norm(B, axis=0)
|
|
@@ -832,7 +832,7 @@ def _mixed_chol(A, B):
|
|
| 832 |
if (np.linalg.norm(R, axis=0) <= CFG["refine_tol"] * bn).all():
|
| 833 |
return X
|
| 834 |
X += cho_solve(cf, R.astype(np.float32), check_finite=False)
|
| 835 |
-
return _ORIG["chol_solve"](A, B)
|
| 836 |
|
| 837 |
|
| 838 |
def _chol_solve(A, B):
|
|
@@ -845,7 +845,13 @@ def _chol_solve(A, B):
|
|
| 845 |
|
| 846 |
def _sym_solve(A, B):
|
| 847 |
if not isinstance(A, _Dev):
|
| 848 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
if A.t.shape[0] > FROZEN_DENSE_MAX:
|
| 850 |
return _gpu_chol(A, B)
|
| 851 |
try:
|
|
|
|
| 823 |
try:
|
| 824 |
cf = cho_factor(A.astype(np.float32, order="F"), lower=True, overwrite_a=True, check_finite=False)
|
| 825 |
except np.linalg.LinAlgError:
|
| 826 |
+
return _ORIG["chol_solve"](A.copy(order="F"), B)
|
| 827 |
B = np.asfortranarray(B, dtype=float)
|
| 828 |
X = cho_solve(cf, B.astype(np.float32), check_finite=False).astype(float)
|
| 829 |
bn = np.linalg.norm(B, axis=0)
|
|
|
|
| 832 |
if (np.linalg.norm(R, axis=0) <= CFG["refine_tol"] * bn).all():
|
| 833 |
return X
|
| 834 |
X += cho_solve(cf, R.astype(np.float32), check_finite=False)
|
| 835 |
+
return _ORIG["chol_solve"](A.copy(order="F"), B)
|
| 836 |
|
| 837 |
|
| 838 |
def _chol_solve(A, B):
|
|
|
|
| 845 |
|
| 846 |
def _sym_solve(A, B):
|
| 847 |
if not isinstance(A, _Dev):
|
| 848 |
+
if "mixed" not in STATE["components"]:
|
| 849 |
+
return _ORIG["sym_solve"](A, B)
|
| 850 |
+
try: # = _ORIG["sym_solve"] without its copy of A: _mixed_chol only reads A (its float64 fallbacks copy it)
|
| 851 |
+
return _mixed_chol(A, B)
|
| 852 |
+
except np.linalg.LinAlgError:
|
| 853 |
+
from scipy.linalg import solve
|
| 854 |
+
return solve(A, B, lower=True, assume_a="sym", overwrite_a=True, check_finite=False)
|
| 855 |
if A.t.shape[0] > FROZEN_DENSE_MAX:
|
| 856 |
return _gpu_chol(A, B)
|
| 857 |
try:
|
geomgnn/paper.py
CHANGED
|
@@ -19,6 +19,7 @@ import hashlib
|
|
| 19 |
import json
|
| 20 |
import os
|
| 21 |
import time
|
|
|
|
| 22 |
from pathlib import Path
|
| 23 |
|
| 24 |
import numpy as np
|
|
@@ -186,13 +187,82 @@ def apply_stack(reg, a, threads=2):
|
|
| 186 |
A._thread_limits(threads)
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def solve_levels(sc, levels, threads=2, stack=None) -> tuple[dict, dict]:
|
| 190 |
"""Positive-mutual prior matrices P = -C at each level under the installed stack (the statements of
|
| 191 |
geomgnn.api.predict_scene's prior loop, any level list); stack = (eps_r, thickness_um) of the substrate the prior is solved at
|
| 192 |
-
(default the scene's, i.e. the training stack).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
from ._tlsq.embed.fastprior_loc import micro_mom_loc
|
| 194 |
from . import levelpar
|
| 195 |
-
eps_r, t_um = stack or (sc.stack["substrate_eps_r"], sc.stack["substrate_thickness_um"])
|
| 196 |
if levelpar.enabled(sc, levels, threads): # the levels concurrently (spawned workers, same stack and statements)
|
| 197 |
return levelpar.solve(sc, list(levels), threads, ALPHA, (eps_r, t_um))
|
| 198 |
proxy.NUM_THREADS = threads
|
|
|
|
| 19 |
import json
|
| 20 |
import os
|
| 21 |
import time
|
| 22 |
+
from collections import OrderedDict
|
| 23 |
from pathlib import Path
|
| 24 |
|
| 25 |
import numpy as np
|
|
|
|
| 187 |
A._thread_limits(threads)
|
| 188 |
|
| 189 |
|
| 190 |
+
_LEVELS: OrderedDict = OrderedDict() # solved prior levels: (layout, level, substrate, stack) -> P; TLSQ_PRIOR_LEVEL_CACHE_MB (0 = off)
|
| 191 |
+
_MESHES: OrderedDict = OrderedDict() # the prior's window meshes (geometry and lattice only, no substrate), same bound
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _geom_hash(geoms) -> str:
|
| 195 |
+
import shapely
|
| 196 |
+
h = hashlib.sha256()
|
| 197 |
+
for g in geoms:
|
| 198 |
+
h.update(shapely.to_wkb(g))
|
| 199 |
+
h.update(b"|")
|
| 200 |
+
return h.hexdigest()
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def _level_key(sc, threads, eps_r, t_um) -> tuple:
|
| 204 |
+
return (_geom_hash([c.geom for c in sc.conductors]), float(eps_r), float(t_um), int(threads), ALPHA, A._STATE["prior_impl"],
|
| 205 |
+
repr(A._STATE.get("stack")), repr(A._STATE.get("pr")))
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def _put(cache, k, v, cap) -> None:
|
| 209 |
+
cache[k] = v
|
| 210 |
+
nb = lambda x: sum(a.nbytes for a in (x if isinstance(x, tuple) else (x,)) if isinstance(a, np.ndarray)) # noqa: E731
|
| 211 |
+
while len(cache) > 1 and sum(nb(x) for x in cache.values()) > cap:
|
| 212 |
+
cache.popitem(last=False)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _memo_mesh(f, cap):
|
| 216 |
+
"""f(metals, *args) -> mesh arrays, memoised on the metals' WKB and the arguments; hits return copies."""
|
| 217 |
+
def g(metals, *args, **kw):
|
| 218 |
+
k = (f.__module__, f.__name__, _geom_hash(metals), repr(args), repr(sorted(kw.items())))
|
| 219 |
+
v = _MESHES.get(k)
|
| 220 |
+
if v is None:
|
| 221 |
+
v = tuple(x.copy() if isinstance(x, np.ndarray) else x for x in f(metals, *args, **kw))
|
| 222 |
+
_put(_MESHES, k, v, cap)
|
| 223 |
+
else:
|
| 224 |
+
_MESHES.move_to_end(k)
|
| 225 |
+
return tuple(x.copy() if isinstance(x, np.ndarray) else x for x in v)
|
| 226 |
+
return g
|
| 227 |
+
|
| 228 |
+
|
| 229 |
def solve_levels(sc, levels, threads=2, stack=None) -> tuple[dict, dict]:
|
| 230 |
"""Positive-mutual prior matrices P = -C at each level under the installed stack (the statements of
|
| 231 |
geomgnn.api.predict_scene's prior loop, any level list); stack = (eps_r, thickness_um) of the substrate the prior is solved at
|
| 232 |
+
(default the scene's, i.e. the training stack). With TLSQ_PRIOR_LEVEL_CACHE_MB > 0 every solved level is kept (LRU, bounded
|
| 233 |
+
in MB) and reused by any later call with the same layout, level, substrate and prior stack (tiers sharing a level), and the
|
| 234 |
+
window meshes are reused across substrates (same layout and level)."""
|
| 235 |
+
eps_r, t_um = stack or (sc.stack["substrate_eps_r"], sc.stack["substrate_thickness_um"])
|
| 236 |
+
cap = float(os.environ.get("TLSQ_PRIOR_LEVEL_CACHE_MB", "0")) * 2**20
|
| 237 |
+
key = _level_key(sc, threads, eps_r, t_um) if cap > 0 and levels else None
|
| 238 |
+
out, tm = {}, {}
|
| 239 |
+
for p in levels if key else ():
|
| 240 |
+
v = _LEVELS.get(key + (float(p),))
|
| 241 |
+
if v is not None:
|
| 242 |
+
_LEVELS.move_to_end(key + (float(p),))
|
| 243 |
+
out[p], tm[f"{p:g}"] = v.copy(), 0.0
|
| 244 |
+
todo = [p for p in levels if p not in out]
|
| 245 |
+
if todo:
|
| 246 |
+
from ._tlsq.embed import fastprior_loc as FL
|
| 247 |
+
from . import priorv2
|
| 248 |
+
hooks = [(m, n, getattr(m, n)) for m, n in ((priorv2, "_mesh"), (FL, "mesh_local"))] if key else []
|
| 249 |
+
try:
|
| 250 |
+
for m, n, f in hooks:
|
| 251 |
+
setattr(m, n, _memo_mesh(f, cap))
|
| 252 |
+
P, t = _solve_levels(sc, todo, threads, eps_r, t_um)
|
| 253 |
+
finally:
|
| 254 |
+
for m, n, f in hooks:
|
| 255 |
+
setattr(m, n, f)
|
| 256 |
+
out.update(P)
|
| 257 |
+
tm.update(t)
|
| 258 |
+
for p in todo if key else ():
|
| 259 |
+
_put(_LEVELS, key + (float(p),), P[p].copy(), cap)
|
| 260 |
+
return {p: out[p] for p in levels}, {f"{p:g}": tm[f"{p:g}"] for p in levels}
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def _solve_levels(sc, levels, threads, eps_r, t_um) -> tuple[dict, dict]:
|
| 264 |
from ._tlsq.embed.fastprior_loc import micro_mom_loc
|
| 265 |
from . import levelpar
|
|
|
|
| 266 |
if levelpar.enabled(sc, levels, threads): # the levels concurrently (spawned workers, same stack and statements)
|
| 267 |
return levelpar.solve(sc, list(levels), threads, ALPHA, (eps_r, t_um))
|
| 268 |
proxy.NUM_THREADS = threads
|
geomgnn/respcache.py
CHANGED
|
@@ -10,6 +10,7 @@ import os
|
|
| 10 |
import pickle
|
| 11 |
import threading
|
| 12 |
from collections import OrderedDict
|
|
|
|
| 13 |
|
| 14 |
_LRU: OrderedDict = OrderedDict()
|
| 15 |
_LOCK = threading.Lock()
|
|
@@ -62,6 +63,34 @@ def cached(lay, settings: tuple, fn):
|
|
| 62 |
return res
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def stats() -> dict:
|
| 66 |
with _LOCK:
|
| 67 |
return {"entries": len(_LRU), "mb": _BYTES[0] / 2**20}
|
|
|
|
| 10 |
import pickle
|
| 11 |
import threading
|
| 12 |
from collections import OrderedDict
|
| 13 |
+
from pathlib import Path
|
| 14 |
|
| 15 |
_LRU: OrderedDict = OrderedDict()
|
| 16 |
_LOCK = threading.Lock()
|
|
|
|
| 63 |
return res
|
| 64 |
|
| 65 |
|
| 66 |
+
def dump(path) -> int:
|
| 67 |
+
"""Pickle the entries (image build: the bundled examples, loaded back by load_items + put_many at start)."""
|
| 68 |
+
with _LOCK:
|
| 69 |
+
items = list(_LRU.items())
|
| 70 |
+
Path(path).parent.mkdir(parents=True, exist_ok=True)
|
| 71 |
+
Path(path).write_bytes(pickle.dumps(items, protocol=5))
|
| 72 |
+
return len(items)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def load_items(path) -> list:
|
| 76 |
+
return pickle.loads(Path(path).read_bytes())
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def put_many(items) -> int:
|
| 80 |
+
n, mb = _limits()
|
| 81 |
+
if n <= 0:
|
| 82 |
+
return 0
|
| 83 |
+
with _LOCK:
|
| 84 |
+
for k, (res, size) in items:
|
| 85 |
+
if k not in _LRU:
|
| 86 |
+
_LRU[k] = (res, size)
|
| 87 |
+
_BYTES[0] += size
|
| 88 |
+
while len(_LRU) > n or _BYTES[0] > mb:
|
| 89 |
+
_, (_, s) = _LRU.popitem(last=False)
|
| 90 |
+
_BYTES[0] -= s
|
| 91 |
+
return len(_LRU)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
def stats() -> dict:
|
| 95 |
with _LOCK:
|
| 96 |
return {"entries": len(_LRU), "mb": _BYTES[0] / 2**20}
|
models/accurate/acc_v2m_sf_s0.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c7a9e3be100f083ee9418695525ae54c8469f8a82e8da4d8c728da5e0cd2ca3
|
| 3 |
+
size 381223
|
models/accurate/acc_v2m_sf_s1.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:857b75095a29d8fa0b12d27a161750cdc89611c2227a1545e1ac447518d0c414
|
| 3 |
+
size 381223
|
models/accurate/acc_v2m_sf_s2.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6e86e6d1e42df20fc7255974b7f739d59317148d2b16be93f012425819f309ac
|
| 3 |
+
size 381223
|
models/accurate/info.json
CHANGED
|
@@ -11,6 +11,11 @@
|
|
| 11 |
"2f88606dbec5c599550d088213a4c37af3b3ad5134ebad2e60519fb534553a57",
|
| 12 |
"d13bafc6b2eb7cadcd97a387d791c0210976db1a9d618f9acc1b614e3701daed"
|
| 13 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"checkpoints_source": [
|
| 15 |
"data_local/flagship_v4/hpc/runs/acc_v2m_sf_s0/model.pt",
|
| 16 |
"data_local/flagship_v4/hpc/runs/acc_v2m_sf_s1/model.pt",
|
|
@@ -18,5 +23,6 @@
|
|
| 18 |
],
|
| 19 |
"surrogate": [],
|
| 20 |
"surrogate_sha256": [],
|
|
|
|
| 21 |
"surrogate_source": []
|
| 22 |
}
|
|
|
|
| 11 |
"2f88606dbec5c599550d088213a4c37af3b3ad5134ebad2e60519fb534553a57",
|
| 12 |
"d13bafc6b2eb7cadcd97a387d791c0210976db1a9d618f9acc1b614e3701daed"
|
| 13 |
],
|
| 14 |
+
"checkpoints_bundle_sha256": [
|
| 15 |
+
"1c7a9e3be100f083ee9418695525ae54c8469f8a82e8da4d8c728da5e0cd2ca3",
|
| 16 |
+
"857b75095a29d8fa0b12d27a161750cdc89611c2227a1545e1ac447518d0c414",
|
| 17 |
+
"6e86e6d1e42df20fc7255974b7f739d59317148d2b16be93f012425819f309ac"
|
| 18 |
+
],
|
| 19 |
"checkpoints_source": [
|
| 20 |
"data_local/flagship_v4/hpc/runs/acc_v2m_sf_s0/model.pt",
|
| 21 |
"data_local/flagship_v4/hpc/runs/acc_v2m_sf_s1/model.pt",
|
|
|
|
| 23 |
],
|
| 24 |
"surrogate": [],
|
| 25 |
"surrogate_sha256": [],
|
| 26 |
+
"surrogate_bundle_sha256": [],
|
| 27 |
"surrogate_source": []
|
| 28 |
}
|
models/balanced/bal_v2m_sf_s0.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7a0353f2e8875c73c4188eccb641d15e8279a65870535a78cabf94f2e410f3ab
|
| 3 |
+
size 381223
|
models/balanced/bal_v2m_sf_s1.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79654f3fe6a647e0e678eb027ae5f11590ba2ec588deb127d3d1e0c468283b4e
|
| 3 |
+
size 381223
|
models/balanced/bal_v2m_sf_s2.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f4fa6514b7f2740c376f664105c6fe723aca1c7c76a5eadec625e9685d721a30
|
| 3 |
+
size 381223
|
models/balanced/info.json
CHANGED
|
@@ -11,6 +11,11 @@
|
|
| 11 |
"486466473eba61c090f4e3fa7988bf880fc183570c5d02bd78f4c1356691f926",
|
| 12 |
"1b55ded04fd624585eeeccf2ab6e4a8e9354a9b96694131e1737dde43ad3ff58"
|
| 13 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"checkpoints_source": [
|
| 15 |
"data_local/flagship_v4/hpc/runs/bal_v2m_sf_s0/model.pt",
|
| 16 |
"data_local/flagship_v4/hpc/runs/bal_v2m_sf_s1/model.pt",
|
|
@@ -18,5 +23,6 @@
|
|
| 18 |
],
|
| 19 |
"surrogate": [],
|
| 20 |
"surrogate_sha256": [],
|
|
|
|
| 21 |
"surrogate_source": []
|
| 22 |
}
|
|
|
|
| 11 |
"486466473eba61c090f4e3fa7988bf880fc183570c5d02bd78f4c1356691f926",
|
| 12 |
"1b55ded04fd624585eeeccf2ab6e4a8e9354a9b96694131e1737dde43ad3ff58"
|
| 13 |
],
|
| 14 |
+
"checkpoints_bundle_sha256": [
|
| 15 |
+
"7a0353f2e8875c73c4188eccb641d15e8279a65870535a78cabf94f2e410f3ab",
|
| 16 |
+
"79654f3fe6a647e0e678eb027ae5f11590ba2ec588deb127d3d1e0c468283b4e",
|
| 17 |
+
"f4fa6514b7f2740c376f664105c6fe723aca1c7c76a5eadec625e9685d721a30"
|
| 18 |
+
],
|
| 19 |
"checkpoints_source": [
|
| 20 |
"data_local/flagship_v4/hpc/runs/bal_v2m_sf_s0/model.pt",
|
| 21 |
"data_local/flagship_v4/hpc/runs/bal_v2m_sf_s1/model.pt",
|
|
|
|
| 23 |
],
|
| 24 |
"surrogate": [],
|
| 25 |
"surrogate_sha256": [],
|
| 26 |
+
"surrogate_bundle_sha256": [],
|
| 27 |
"surrogate_source": []
|
| 28 |
}
|
models/fast/acc_v1_s0.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2909bd0bf06d3cd07be27160050e323a69700de732ef54c9afa00c38b7521e0
|
| 3 |
+
size 380559
|
models/fast/acc_v1_s1.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:085a7819d86f66962a840e1279017f23487d8d3b12fa9773a1fd0f884621b241
|
| 3 |
+
size 380559
|
models/fast/acc_v1_s2.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5b607329a83a938911d4ebbd8d801b9c58306ce3c96b34cd82ed502a8fb588fc
|
| 3 |
+
size 380559
|
models/fast/info.json
CHANGED
|
@@ -11,6 +11,11 @@
|
|
| 11 |
"f1ad2ca065dd650ccabcad73a3c6ad2ac1042f4f68bb828893bbdecc47411ffe",
|
| 12 |
"8cbada211724df5cc05a7b4fdd232607de047b248a43993d3844bd68ff8060c4"
|
| 13 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"checkpoints_source": [
|
| 15 |
"data_local/flagship_v4/hpc/runs/acc_v1_s0/model.pt",
|
| 16 |
"data_local/flagship_v4/hpc/runs/acc_v1_s1/model.pt",
|
|
@@ -22,6 +27,9 @@
|
|
| 22 |
"surrogate_sha256": [
|
| 23 |
"132d6f389eda798d31bd5654a96e24cce18fa750134a9fb2a9725eafed339dac"
|
| 24 |
],
|
|
|
|
|
|
|
|
|
|
| 25 |
"surrogate_source": [
|
| 26 |
"data_local/flagship_v4/hpc/sur/sall_all_s0/model.pt"
|
| 27 |
]
|
|
|
|
| 11 |
"f1ad2ca065dd650ccabcad73a3c6ad2ac1042f4f68bb828893bbdecc47411ffe",
|
| 12 |
"8cbada211724df5cc05a7b4fdd232607de047b248a43993d3844bd68ff8060c4"
|
| 13 |
],
|
| 14 |
+
"checkpoints_bundle_sha256": [
|
| 15 |
+
"e2909bd0bf06d3cd07be27160050e323a69700de732ef54c9afa00c38b7521e0",
|
| 16 |
+
"085a7819d86f66962a840e1279017f23487d8d3b12fa9773a1fd0f884621b241",
|
| 17 |
+
"5b607329a83a938911d4ebbd8d801b9c58306ce3c96b34cd82ed502a8fb588fc"
|
| 18 |
+
],
|
| 19 |
"checkpoints_source": [
|
| 20 |
"data_local/flagship_v4/hpc/runs/acc_v1_s0/model.pt",
|
| 21 |
"data_local/flagship_v4/hpc/runs/acc_v1_s1/model.pt",
|
|
|
|
| 27 |
"surrogate_sha256": [
|
| 28 |
"132d6f389eda798d31bd5654a96e24cce18fa750134a9fb2a9725eafed339dac"
|
| 29 |
],
|
| 30 |
+
"surrogate_bundle_sha256": [
|
| 31 |
+
"132d6f389eda798d31bd5654a96e24cce18fa750134a9fb2a9725eafed339dac"
|
| 32 |
+
],
|
| 33 |
"surrogate_source": [
|
| 34 |
"data_local/flagship_v4/hpc/sur/sall_all_s0/model.pt"
|
| 35 |
]
|
registry.yaml
CHANGED
|
@@ -729,7 +729,7 @@ gnn_models:
|
|
| 729 |
patches: [priorv2m] # VALUE-CHANGING: geomgnn/priorv2.py = scripts/priorv2/priorv2.py, installed(policy='fc', dip=True, margin=True)
|
| 730 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 731 |
mode: exact_compiled # geomgnn.fastprior_pkg solver mode (fv + hmat_vec + mixed + numba compiled H-matrix); TLSQ_GNN_PRIOR_MODE overrides
|
| 732 |
-
speed_package_sha256:
|
| 733 |
speed_approved: "user 2026-10-17 ('faster at equal accuracy is a win'): fastprior_pkg 'Ready to deploy' (agents/fastprior_pkg/RESULTS.md); exact_compiled VAL tie on all 13 families; deploy-path parity gate in deploy/tests/test_gnn_space.py (<= 1e-6 vs the v2m exact path)"
|
| 734 |
certified_opt_in: "mode certified (+ Rayleigh-Ritz windows with an error certificate) is gated on VAL (tie) but not enabled here; set TLSQ_GNN_PRIOR_MODE=certified (Space variable) to opt in"
|
| 735 |
value_changing_approved: "user 2026-10-17 ('do whatever to make the models faster and better'); prior v2 PASSED its pre-declared protocol, arm Bm (frozen nets + v2m) recommended for deployment (agents/priorv2/RESULTS.md verdict 4, FINALIZATION_V2.json)"
|
|
@@ -971,7 +971,7 @@ paper_hub:
|
|
| 971 |
mode: exact_compiled
|
| 972 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 973 |
farfield_sha256: 6c877b47c2894fe78a38ad4199b29e450b610c2c45a261c8cf4d53efc1912836 # scripts/farfield/farfield.py (agents/farfield), vendored verbatim
|
| 974 |
-
speed_package_sha256:
|
| 975 |
value_changing_approved: "user 2026-10-17 (v2m, gnn_models.GNN); user 2026-10-20: adopted arm (b) of agents/farfield (substrate dipole for far pairs in different ground pockets; pre-declared rule met, agents/farfield/RESULTS.md; adoption agents/farfield/ADOPTION.md)"
|
| 976 |
speed_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 977 |
previous: corrected_halfspace # the same stack with the half-space far field (before 2026-10-20); process-wide override: TLSQ_FAR_FIELD=halfspace
|
|
@@ -981,7 +981,7 @@ paper_hub:
|
|
| 981 |
patches: [priorv2m]
|
| 982 |
mode: exact_compiled
|
| 983 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 984 |
-
speed_package_sha256:
|
| 985 |
value_changing_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 986 |
speed_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 987 |
uncorrected: # prior v1, frozen solver (+ the value-preserving rejection-tail fix, bit-identical)
|
|
@@ -993,7 +993,7 @@ paper_hub:
|
|
| 993 |
uncorrected_certified: # prior v1, certified solve (Rayleigh-Ritz windows with an error estimate)
|
| 994 |
patches: []
|
| 995 |
mode: certified
|
| 996 |
-
speed_package_sha256:
|
| 997 |
speed_approved: "VAL tie on all 13 families (agents/fastprior_pkg/RESULTS.md); paper tab:routes (d)"
|
| 998 |
|
| 999 |
_paper_ckpt:
|
|
@@ -1391,7 +1391,7 @@ paper_arms:
|
|
| 1391 |
flagship_hub:
|
| 1392 |
public_link: SQuADDS/planar-capacitance # static Space, printed in the paper; opens the demo top-level (deploy/spaces/SQuADDS-planar-capacitance); never rename
|
| 1393 |
deploy_20261114: # public-demo limits + short card (no paper model); Docker SYSTEM=spaces so HF OAuth works
|
| 1394 |
-
commit:
|
| 1395 |
live: deploy/tests/results/flagship_space_live_limits20261114.json # examples x tiers vs Mac <= 1.1e-3 rel; anon non-example refused; oauth_token call ran
|
| 1396 |
space: shanto268/PlanarCapacitanceModel # the URL is kept; its earlier v3 tiers are archived (archive below)
|
| 1397 |
title: Planar Capacitance Model
|
|
@@ -1403,7 +1403,7 @@ flagship_hub:
|
|
| 1403 |
checkpoints: data_local/flagship_v4/checkpoints.json # sha256 of every flagship checkpoint; sync.py refuses any other file
|
| 1404 |
results: agents/flagship_v4/RESULTS.md
|
| 1405 |
hf_cards_20261114: # README-only rewrite (re-pushed same day: /ml-paper/ link, then no links to the private paper model) (handoff/hf_cards/), private; package pins unchanged (manifest bb9d0ce / 5d4e094, dataset 13d46953)
|
| 1406 |
-
SQuADDS/SQuADDS_PlanarCapacitance:
|
| 1407 |
SQuADDS/SQuADDS_PlanarCapacitance-Synthetic: 3179ea7aed6f0ba92b549cc29aa645feea937513
|
| 1408 |
SQuADDS/SQuADDS_PlanarCapacitance-heldout: c538385b3e8d48f4183b68d00e376a06762b0705
|
| 1409 |
SQuADDS/PlanarCapacitance-flagship: a89f30850b638da1f693042b7d7cf14f20b19098 # + balanced/bal_v2m_sf_s{0,1,2}.pt (same sha256 as the Space) and SHA256SUMS
|
|
|
|
| 729 |
patches: [priorv2m] # VALUE-CHANGING: geomgnn/priorv2.py = scripts/priorv2/priorv2.py, installed(policy='fc', dip=True, margin=True)
|
| 730 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 731 |
mode: exact_compiled # geomgnn.fastprior_pkg solver mode (fv + hmat_vec + mixed + numba compiled H-matrix); TLSQ_GNN_PRIOR_MODE overrides
|
| 732 |
+
speed_package_sha256: 4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a # scripts/fastprior_pkg/fastprior_pkg.py, vendored verbatim
|
| 733 |
speed_approved: "user 2026-10-17 ('faster at equal accuracy is a win'): fastprior_pkg 'Ready to deploy' (agents/fastprior_pkg/RESULTS.md); exact_compiled VAL tie on all 13 families; deploy-path parity gate in deploy/tests/test_gnn_space.py (<= 1e-6 vs the v2m exact path)"
|
| 734 |
certified_opt_in: "mode certified (+ Rayleigh-Ritz windows with an error certificate) is gated on VAL (tie) but not enabled here; set TLSQ_GNN_PRIOR_MODE=certified (Space variable) to opt in"
|
| 735 |
value_changing_approved: "user 2026-10-17 ('do whatever to make the models faster and better'); prior v2 PASSED its pre-declared protocol, arm Bm (frozen nets + v2m) recommended for deployment (agents/priorv2/RESULTS.md verdict 4, FINALIZATION_V2.json)"
|
|
|
|
| 971 |
mode: exact_compiled
|
| 972 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 973 |
farfield_sha256: 6c877b47c2894fe78a38ad4199b29e450b610c2c45a261c8cf4d53efc1912836 # scripts/farfield/farfield.py (agents/farfield), vendored verbatim
|
| 974 |
+
speed_package_sha256: 4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a
|
| 975 |
value_changing_approved: "user 2026-10-17 (v2m, gnn_models.GNN); user 2026-10-20: adopted arm (b) of agents/farfield (substrate dipole for far pairs in different ground pockets; pre-declared rule met, agents/farfield/RESULTS.md; adoption agents/farfield/ADOPTION.md)"
|
| 976 |
speed_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 977 |
previous: corrected_halfspace # the same stack with the half-space far field (before 2026-10-20); process-wide override: TLSQ_FAR_FIELD=halfspace
|
|
|
|
| 981 |
patches: [priorv2m]
|
| 982 |
mode: exact_compiled
|
| 983 |
module_sha256: 1a0bdcb71500c7f11e63238afe531c18caabd5c9f6f7aaa73d9b7dcd0ad61f8c
|
| 984 |
+
speed_package_sha256: 4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a
|
| 985 |
value_changing_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 986 |
speed_approved: "user 2026-10-17 (gnn_models.GNN)"
|
| 987 |
uncorrected: # prior v1, frozen solver (+ the value-preserving rejection-tail fix, bit-identical)
|
|
|
|
| 993 |
uncorrected_certified: # prior v1, certified solve (Rayleigh-Ritz windows with an error estimate)
|
| 994 |
patches: []
|
| 995 |
mode: certified
|
| 996 |
+
speed_package_sha256: 4fff680f35cb8b098de6c9b1b6fc55780064362ffc829bb47bf69a77454ce38a
|
| 997 |
speed_approved: "VAL tie on all 13 families (agents/fastprior_pkg/RESULTS.md); paper tab:routes (d)"
|
| 998 |
|
| 999 |
_paper_ckpt:
|
|
|
|
| 1391 |
flagship_hub:
|
| 1392 |
public_link: SQuADDS/planar-capacitance # static Space, printed in the paper; opens the demo top-level (deploy/spaces/SQuADDS-planar-capacitance); never rename
|
| 1393 |
deploy_20261114: # public-demo limits + short card (no paper model); Docker SYSTEM=spaces so HF OAuth works
|
| 1394 |
+
commit: 142609ed7021861aea2be8ee5f51594b70e5918b # + text in the author's voice, Fast in the selector, Model not Tier, footer (was 4d44ef6)
|
| 1395 |
live: deploy/tests/results/flagship_space_live_limits20261114.json # examples x tiers vs Mac <= 1.1e-3 rel; anon non-example refused; oauth_token call ran
|
| 1396 |
space: shanto268/PlanarCapacitanceModel # the URL is kept; its earlier v3 tiers are archived (archive below)
|
| 1397 |
title: Planar Capacitance Model
|
|
|
|
| 1403 |
checkpoints: data_local/flagship_v4/checkpoints.json # sha256 of every flagship checkpoint; sync.py refuses any other file
|
| 1404 |
results: agents/flagship_v4/RESULTS.md
|
| 1405 |
hf_cards_20261114: # README-only rewrite (re-pushed same day: /ml-paper/ link, then no links to the private paper model) (handoff/hf_cards/), private; package pins unchanged (manifest bb9d0ce / 5d4e094, dataset 13d46953)
|
| 1406 |
+
SQuADDS/SQuADDS_PlanarCapacitance: c79953313874e9c116ca2f39a414d92025d18484 # physics_prior rename (24de414) + data/legacy_v1 removed
|
| 1407 |
SQuADDS/SQuADDS_PlanarCapacitance-Synthetic: 3179ea7aed6f0ba92b549cc29aa645feea937513
|
| 1408 |
SQuADDS/SQuADDS_PlanarCapacitance-heldout: c538385b3e8d48f4183b68d00e376a06762b0705
|
| 1409 |
SQuADDS/PlanarCapacitance-flagship: a89f30850b638da1f693042b7d7cf14f20b19098 # + balanced/bal_v2m_sf_s{0,1,2}.pt (same sha256 as the Space) and SHA256SUMS
|
requirements.txt
CHANGED
|
@@ -1,17 +1,15 @@
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cpu
|
| 2 |
-
torch
|
| 3 |
-
numpy
|
| 4 |
-
scipy
|
| 5 |
-
shapely
|
| 6 |
-
gdstk
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
matplotlib
|
| 12 |
-
huggingface_hub
|
| 13 |
numba==0.68.0
|
| 14 |
llvmlite==0.50.0
|
| 15 |
-
threadpoolctl
|
| 16 |
authlib==1.6.5
|
| 17 |
itsdangerous==2.2.0
|
|
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cpu
|
| 2 |
+
torch==2.14.1
|
| 3 |
+
numpy==2.5.3
|
| 4 |
+
scipy==1.18.1
|
| 5 |
+
shapely==2.1.2
|
| 6 |
+
gdstk==1.0.1
|
| 7 |
+
pandas==3.0.6
|
| 8 |
+
pyyaml==6.0.3
|
| 9 |
+
matplotlib==3.11.2
|
| 10 |
+
huggingface_hub==2.2.0
|
|
|
|
|
|
|
| 11 |
numba==0.68.0
|
| 12 |
llvmlite==0.50.0
|
| 13 |
+
threadpoolctl==3.7.0
|
| 14 |
authlib==1.6.5
|
| 15 |
itsdangerous==2.2.0
|
warm.py
CHANGED
|
@@ -1,10 +1,22 @@
|
|
| 1 |
"""Build-time warm-up (Docker variant): the Space's own preload at import of app.py (every arm / tier on the interdigital
|
| 2 |
-
example: the prior's numba kernels, the NN kernel, the surrogates), so the image carries the compiled cache
|
|
|
|
|
|
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
-
t = time.perf_counter()
|
| 7 |
os.environ["TLSQ_PRELOAD"] = "1"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
print("warm.py: preload and cache population", round(time.perf_counter() - t, 1), "s", flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""Build-time warm-up (Docker variant): the Space's own preload at import of app.py (every arm / tier on the interdigital
|
| 2 |
+
example: the prior's numba kernels, the NN kernel, the surrogates), so the image carries the compiled cache; then (flagship) the
|
| 3 |
+
examples' results baked for the response cache. Each step runs in its own process: the preload must succeed; the bake may fail
|
| 4 |
+
(e.g. the builder runs out of memory), and the image is then built without it (the Space computes the examples on demand)."""
|
| 5 |
import os
|
| 6 |
+
import resource
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
import time
|
| 10 |
+
from pathlib import Path
|
| 11 |
|
|
|
|
| 12 |
os.environ["TLSQ_PRELOAD"] = "1"
|
| 13 |
+
t = time.perf_counter()
|
| 14 |
+
subprocess.run([sys.executable, "-c", "import app"], check=True) # noqa: S603 (app.py preloads at import; no server)
|
| 15 |
print("warm.py: preload and cache population", round(time.perf_counter() - t, 1), "s", flush=True)
|
| 16 |
+
t = time.perf_counter()
|
| 17 |
+
r = subprocess.run([sys.executable, "-c", "import app\nif hasattr(app, 'bake'):\n app.bake()"]) # noqa: S603
|
| 18 |
+
peak = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss / 2**10
|
| 19 |
+
if r.returncode:
|
| 20 |
+
Path(os.environ.get("TLSQ_RESPONSE_BAKE", "bake/respcache.pkl")).unlink(missing_ok=True)
|
| 21 |
+
print(f"warm.py: bake FAILED (exit {r.returncode}, e.g. out of memory): the image is built without baked example results", flush=True)
|
| 22 |
+
print("warm.py: bake step", round(time.perf_counter() - t, 1), "s, peak RSS of a step", round(peak), "MB", flush=True)
|