Skip to content

Commit 69822d1

Browse files
explorer + ci: V2 strength GP web hookup + artifact / parity gates
Hooks the V2 strength GP up to the in-browser BOxCrete explorer and wires up the CI gates that enforce coherence between the deployed boxcrete model and the published model artifacts. JS-side V2 implementation (docs/explorer): * docs/gp_v2_fast.mjs — pure-JS implementation of the V2 gated-kernel posterior, optimised for the in-browser explorer. * docs/feature_registry.mjs — JS port of the F5_alllog feature builders to keep the JS path byte-identical to the Python path. * docs/gp.mjs / docs/ui.mjs / docs/units.mjs — explorer integration. * docs/generate_mix_analyses.py — produces per-mix analysis pages consumed by the explorer. * docs/model/README.md — documents the docs/model/ artifact layout. * docs/model/strength.json + compositions.json + test_vectors.json — refreshed model artifacts produced by the V2 fit. CI gates: * .github/workflows/strength-parity.yml — guards that the V2 fit factory produces byte-equivalent posteriors to the research-side catalog (test_strength_model_parity.py). * .github/workflows/model-artifacts-coherence.yml — guards that the published docs/model/ artifacts match the boxcrete fit output (catches stale artifacts after model code changes). JS-side regression tests: * test/test_js_strength_v2.mjs — V2 posterior parity (Python vs JS). * test/test_js_physical_constraints.mjs — JS-side f(x, t=0) = 0 guard. * test/test_lengthscales_v2.mjs — JS-side lengthscale parity. * test/test_curve_monotonicity.mjs — strength-curve monotonicity. * test/test_data_freshness.mjs — guards that test_vectors.json is derived from the same data the deployed model was fit on. * test/test_js_ui_smoke.mjs — explorer UI smoke test. * experiments/regenerate_compositions_strength_predictions.mjs + augment_test_vectors_with_gwp_cost.mjs — JS-side artifact regeneration scripts.
1 parent ab13237 commit 69822d1

27 files changed

Lines changed: 4144 additions & 524 deletions
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Verifies that docs/model/*.json artifacts are coherent with the
2+
# Python V2 strength GP fit. Runs the regen pipeline and asserts no
3+
# diff — any uncommitted drift in strength.json / test_vectors.json /
4+
# compositions.json (e.g., from a manual edit, a partial regen, or
5+
# upstream model code that wasn't followed by a regen run) fails CI.
6+
#
7+
# See docs/model/README.md for the artifact schema + regen workflow.
8+
9+
name: Model Artifacts Coherence
10+
11+
permissions:
12+
contents: read
13+
14+
on:
15+
push:
16+
branches: [main, master]
17+
paths:
18+
- 'boxcrete/strength_model.py'
19+
- 'boxcrete/kernels.py'
20+
- 'boxcrete/likelihoods.py'
21+
- 'boxcrete/priors.py'
22+
- 'boxcrete/features.py'
23+
- 'boxcrete/utils.py'
24+
- 'boxcrete/__init__.py'
25+
- 'data/**'
26+
- 'experiments/regenerate_strength_json.py'
27+
- 'experiments/regenerate_compositions_strength_predictions.mjs'
28+
- 'experiments/augment_test_vectors_with_gwp_cost.mjs'
29+
- 'experiments/regenerate_all_artifacts.sh'
30+
- 'docs/model/**'
31+
- 'docs/feature_registry.mjs'
32+
- 'docs/gp.mjs'
33+
- 'docs/gp_v2_fast.mjs'
34+
- '.github/workflows/model-artifacts-coherence.yml'
35+
pull_request:
36+
branches: [main, master]
37+
paths:
38+
- 'boxcrete/strength_model.py'
39+
- 'boxcrete/kernels.py'
40+
- 'boxcrete/likelihoods.py'
41+
- 'boxcrete/priors.py'
42+
- 'boxcrete/features.py'
43+
- 'boxcrete/utils.py'
44+
- 'boxcrete/__init__.py'
45+
- 'data/**'
46+
- 'experiments/regenerate_strength_json.py'
47+
- 'experiments/regenerate_compositions_strength_predictions.mjs'
48+
- 'experiments/augment_test_vectors_with_gwp_cost.mjs'
49+
- 'experiments/regenerate_all_artifacts.sh'
50+
- 'docs/model/**'
51+
- 'docs/feature_registry.mjs'
52+
- 'docs/gp.mjs'
53+
- 'docs/gp_v2_fast.mjs'
54+
- '.github/workflows/model-artifacts-coherence.yml'
55+
workflow_dispatch: {}
56+
57+
jobs:
58+
regen-idempotency:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- uses: actions/setup-python@v5
64+
with:
65+
python-version: '3.12'
66+
cache: 'pip'
67+
68+
- uses: actions/setup-node@v4
69+
with:
70+
node-version: '20'
71+
72+
- name: Install Python deps
73+
run: |
74+
python -m pip install --upgrade pip
75+
pip install -e .
76+
77+
- name: Save committed docs/model/ for later comparison
78+
# Snapshot the JSON artifacts BEFORE regen overwrites them, so
79+
# the post-regen comparison can diff against the committed copy.
80+
# We snapshot only the JSONs (not the .pt) because cross-arch
81+
# determinism on binary state_dicts requires bit-equality which
82+
# we can't expect from a multi-modal MLL fit; the JSON-level
83+
# checks cover the same coverage surface (lengthscales +
84+
# prediction surface) via experiments/check_artifacts_drift.py.
85+
run: |
86+
mkdir -p /tmp/committed_docs_model
87+
cp docs/model/strength.json /tmp/committed_docs_model/
88+
cp docs/model/test_vectors.json /tmp/committed_docs_model/
89+
cp docs/model/compositions.json /tmp/committed_docs_model/
90+
91+
- name: Run regen pipeline
92+
run: bash experiments/regenerate_all_artifacts.sh
93+
94+
- name: Assert artifacts agree with committed copy within tolerance
95+
# Replaces the legacy ``git diff --exit-code docs/model/`` check,
96+
# which was over-strict: it required bit-equality of JSON output
97+
# across architectures, but the V2 strength GP fit goes through
98+
# scipy's L-BFGS-B against a multi-modal MLL surface, and
99+
# different CPU architectures land in different local optima
100+
# (Apple Silicon via qemu-emulated amd64 vs GitHub-runner native
101+
# x86_64 produce ~2x different lengthscales while predicting
102+
# nearly the same surface). The new check tolerates this
103+
# cross-architecture basin divergence (10x ratio band on
104+
# internal hyperparameters) while still catching the original
105+
# failure mode (a stale export typically shifts predictions
106+
# by 100s of psi at OOT compositions). See the docstring of
107+
# ``experiments/check_artifacts_drift.py`` for the full rationale.
108+
run: |
109+
python experiments/check_artifacts_drift.py \
110+
--committed-dir /tmp/committed_docs_model \
111+
--fresh-dir docs/model

.github/workflows/notebooks.yml

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Set up Python 3.10
4747
uses: actions/setup-python@v5
4848
with:
49-
python-version: '3.10'
49+
python-version: '3.12'
5050

5151
- name: Cache pip dependencies
5252
uses: actions/cache@v4
@@ -71,47 +71,87 @@ jobs:
7171
BOXCRETE_OPTIMIZATION_MODE: ${{ matrix.optimization-mode }}
7272
BOXCRETE_INCLUDE_COST: ${{ matrix.include-cost }}
7373
run: |
74+
# Diagnostics so we can see *why* nbconvert dies on the GitHub
75+
# Linux runner. Local Mac runs of this notebook complete cleanly
76+
# in ~3 min; CI silently kills the kernel mid-execution. The
77+
# block below prints memory + disk before, captures nbconvert
78+
# stdout AND stderr explicitly (the previous wrapper relied on
79+
# inherited streams which were getting truncated when the
80+
# kernel was SIGKILL'd), and on failure dumps OOM evidence
81+
# from dmesg and the negative returncode signal name.
82+
echo "=== runner resources before nbconvert ==="
83+
free -h || true
84+
df -h /home/runner/work || true
85+
uname -a || true
86+
python -c "import torch; print('torch:', torch.__version__, 'threads:', torch.get_num_threads())" || true
87+
7488
python - << 'PYEOF'
75-
import subprocess, sys, os
89+
import os, signal, subprocess, sys
7690
from pathlib import Path
7791
78-
# Only notebooks that use BOXCRETE_OPTIMIZATION_MODE
79-
MODE_DEPENDENT = [
80-
"notebooks/prediction_and_optimization_tutorial.ipynb",
81-
]
82-
92+
MODE_DEPENDENT = ["notebooks/prediction_and_optimization_tutorial.ipynb"]
8393
mode = os.environ.get("BOXCRETE_OPTIMIZATION_MODE", "concrete")
8494
failed = []
8595
8696
for nb in MODE_DEPENDENT:
87-
nb_path = Path(nb)
88-
if not nb_path.exists():
97+
if not Path(nb).exists():
8998
print(f"⚠️ Skipping (not found): {nb}")
9099
continue
91-
92100
print(f"{'=' * 40}")
93101
print(f"Executing ({mode}): {nb}")
94102
print(f"{'=' * 40}")
103+
sys.stdout.flush()
95104
96-
result = subprocess.run(
105+
proc = subprocess.run(
97106
[
98107
sys.executable, "-m", "jupyter", "nbconvert",
99108
"--to", "notebook",
100109
"--execute",
101110
"--inplace",
102111
"--ExecutePreprocessor.timeout=600",
103112
"--ExecutePreprocessor.kernel_name=python3",
113+
"--debug",
104114
str(nb),
105115
],
106-
capture_output=False,
116+
capture_output=True,
117+
text=True,
107118
)
108-
109-
if result.returncode != 0:
119+
# Always print captured streams — they're often empty when
120+
# the kernel was killed mid-cell, but when they aren't,
121+
# they tell us exactly which cell failed.
122+
print("--- nbconvert stdout ---")
123+
print(proc.stdout if proc.stdout else "(empty)")
124+
print("--- nbconvert stderr ---")
125+
print(proc.stderr if proc.stderr else "(empty)")
126+
print(f"--- returncode: {proc.returncode} ---")
127+
if proc.returncode < 0:
128+
try:
129+
sig = signal.Signals(-proc.returncode)
130+
print(f" nbconvert was terminated by {sig.name} (signal {-proc.returncode})")
131+
except (ValueError, AttributeError):
132+
print(f" nbconvert was terminated by signal {-proc.returncode}")
133+
134+
if proc.returncode != 0:
110135
failed.append(str(nb))
111136
print(f"❌ Failed ({mode}): {nb}")
137+
# OOM / kernel-killed evidence (Linux runner only).
138+
print("--- dmesg | tail (OOM evidence if any) ---")
139+
try:
140+
d = subprocess.run(
141+
["sudo", "dmesg", "--ctime"],
142+
capture_output=True, text=True, timeout=5,
143+
)
144+
tail = d.stdout.splitlines()[-50:]
145+
print("\n".join(tail) if tail else "(dmesg empty)")
146+
except Exception as e:
147+
print(f"(dmesg unavailable: {e})")
148+
print("--- runner resources after failure ---")
149+
subprocess.run(["free", "-h"], check=False)
150+
subprocess.run(["df", "-h", "/home/runner/work"], check=False)
112151
else:
113152
print(f"✅ Successfully executed ({mode}): {nb}")
114153
print()
154+
sys.stdout.flush()
115155
116156
if failed:
117157
print(f"\n{len(failed)} notebook(s) failed in {mode} mode:")
@@ -144,7 +184,7 @@ jobs:
144184
- name: Set up Python 3.10
145185
uses: actions/setup-python@v5
146186
with:
147-
python-version: '3.10'
187+
python-version: '3.12'
148188

149189
- name: Cache pip dependencies
150190
uses: actions/cache@v4
@@ -232,7 +272,7 @@ jobs:
232272
- name: Set up Python
233273
uses: actions/setup-python@v5
234274
with:
235-
python-version: '3.10'
275+
python-version: '3.12'
236276

237277
- name: Install dependencies
238278
run: |
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Verifies that boxcrete.fit_strength_gp (production) and the
2+
# experiments.model_variant_study variant catalog produce byte-equivalent
3+
# posteriors for the V2 strength GP configuration, AND that
4+
# boxcrete.load_pretrained_strength_gp() faithfully reconstructs the
5+
# deployed V2 strength GP from docs/model/strength_model.pt.
6+
#
7+
# Runs:
8+
# - test/test_strength_model_parity.py (atol=1e-8 / rtol=1e-6, ~3s)
9+
# - test/test_pretrained_loader_fidelity.py (atol=1e-5 / 1e-3, ~3s)
10+
#
11+
# See those test files for the rationale.
12+
13+
name: Strength GP Parity
14+
15+
permissions:
16+
contents: read
17+
18+
on:
19+
push:
20+
branches: [main, master]
21+
paths:
22+
- 'boxcrete/strength_model.py'
23+
- 'boxcrete/kernels.py'
24+
- 'boxcrete/likelihoods.py'
25+
- 'boxcrete/priors.py'
26+
- 'boxcrete/features.py'
27+
- 'boxcrete/__init__.py'
28+
- 'experiments/model_variant_study.py'
29+
- 'experiments/_research_features.py'
30+
- 'test/test_strength_model_parity.py'
31+
- 'test/test_pretrained_loader_fidelity.py'
32+
- 'docs/model/strength.json'
33+
- 'docs/model/strength_model.pt'
34+
- 'docs/model/test_vectors.json'
35+
- '.github/workflows/strength-parity.yml'
36+
pull_request:
37+
branches: [main, master]
38+
paths:
39+
- 'boxcrete/strength_model.py'
40+
- 'boxcrete/kernels.py'
41+
- 'boxcrete/likelihoods.py'
42+
- 'boxcrete/priors.py'
43+
- 'boxcrete/features.py'
44+
- 'boxcrete/__init__.py'
45+
- 'experiments/model_variant_study.py'
46+
- 'experiments/_research_features.py'
47+
- 'test/test_strength_model_parity.py'
48+
- 'test/test_pretrained_loader_fidelity.py'
49+
- 'docs/model/strength.json'
50+
- 'docs/model/strength_model.pt'
51+
- 'docs/model/test_vectors.json'
52+
- '.github/workflows/strength-parity.yml'
53+
workflow_dispatch: {}
54+
55+
jobs:
56+
parity:
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- uses: actions/setup-python@v5
62+
with:
63+
python-version: '3.12'
64+
cache: 'pip'
65+
66+
- name: Install Python deps
67+
run: |
68+
python -m pip install --upgrade pip
69+
pip install -e .
70+
pip install pytest
71+
72+
- name: Run parity test
73+
run: python -m pytest test/test_strength_model_parity.py -v --tb=short
74+
75+
- name: Run pretrained-loader fidelity test
76+
run: python -m pytest test/test_pretrained_loader_fidelity.py -v --tb=short

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
python-version: ['3.10', '3.11', '3.12']
28+
python-version: ['3.11', '3.12']
2929

3030
steps:
3131
- name: Checkout repository
@@ -56,7 +56,7 @@ jobs:
5656
5757
- name: Upload coverage reports
5858
uses: codecov/codecov-action@v4
59-
if: matrix.python-version == '3.10'
59+
if: matrix.python-version == '3.12'
6060
with:
6161
file: ./coverage.xml
6262
flags: unittests
@@ -72,7 +72,7 @@ jobs:
7272
- name: Set up Python
7373
uses: actions/setup-python@v5
7474
with:
75-
python-version: '3.10'
75+
python-version: '3.12'
7676

7777
- name: Install linting dependencies
7878
run: |

0 commit comments

Comments
 (0)