/* Workbench: adapt the pretrained FNO to a compatible study through the /flow API. * * Six steps: Describe, Upload, Adapt, Explore, Next runs, Report. Every number on * these screens comes from the server (validation, worker jobs, stored models and * the cost ledger). There is no browser model and no fallback: failures are shown. */ (function () { "use strict"; const F = window.DeltaFlow; const A = window.DeltaFlowApi; const $ = (id) => document.getElementById(id); const esc = F.esc; const STEPS = ["Your study", "Predict", "Next runs", "Summary"]; const CURVE_POINTS = 21; const client = A.createClient(); const W = { step: 0, cap: null, view: null, runs: null, report: null, message: null, notice: null, issues: [], busy: false, outcome: 0, xIndex: 0, fixed: null, curve: null, point: null, next: null, nextOpts: { policy: null, batch: 8 }, poll: null, ready: false, showProjected: false, showNext: true, uploading: null, }; /* ---------- helpers ---------- */ function errorHtml(msg, issues) { const list = (issues || []).filter((i) => i && i.message); return ( '
' + lede + "
" : "") + "' + esc(availabilityLine()) + "
" + '' + esc(NEW_PROBLEM) + " " + esc(GPU_NOTE) + "
" + 'Download a sample study ZIP 8 training runs from the same flow family, ready to upload.
' + dropZone(null) + (W.message ? errorHtml(W.message, W.issues) : "") + '| Study | Data | Created | Open |
|---|---|---|---|
| " + esc(displayName(s)) + " | " + dataTag(s.data_kind) + " | " + esc(new Date(s.created_at * 1000).toLocaleDateString()) + ' |
| Role | Runs | Used for |
|---|---|---|
| " + r[0] + ' | ' + r[1] + " | " + r[2] + " |
' + esc(W.view.example_id ? EXAMPLE_ABOUT : v.provenance.description || "") +
" Fingerprint " + short(v.content_sha256) + ".
study.json: what the study is", "runs.csv: one row per run, with its role",
"fields/: start and end state of each run", "checksums.json: file fingerprints"]) + '' + esc(STORAGE_NOTE) + "
"; async function uploadFile(file) { if (!file) return; if (file.size > ((W.cap && W.cap.limits && W.cap.limits.zip_bytes) || Infinity)) { W.message = "This copy of the site can't take a file that large."; render(false); return; } W.uploading = file.name; await guard(async () => { try { const view = await client.upload(file); await loadStudy(view.study_id); W.notice = "Checked and stored: " + displayName(view) + "."; } finally { W.uploading = null; } }); } /* ---------- Adapt ---------- */ function jobPanel(job) { if (!job) return ""; const pct = Math.round(A.fitFraction(job) * 100); return ( '' + esc(A.jobText(job)) + "" + (job.profile && job.profile !== "task8-fno-lhs-v1" ? ' Test profile' : "") + "
" + 'Progress comes from the training steps as they are reported.
' + (job.queue_note ? noteHtml(job.queue_note) : "") + 'Each dot is one of ' + check.n + " checking runs the model never saw: its real result (across) against the prediction (up). Dots on the diagonal are perfect; the grey band is the accuracy target. Nondimensional units.
" + '| Copy (seed) | Best step | Weights fingerprint |
|---|---|---|
| " + x.seed + ' | ' + x.best_step + " | " + short(x.weights_sha256) + " |
' + esc(profileName(m.profile, m.profile_label)) + "; source checkpoint " + short(m.source_sha256) + "; " +
esc(m.environment.device_name) + ". Model " + esc(m.model_id) + ".
This fit also used ' + used.development + " development runs and " + used.calibration + " calibration runs.
"; const check = m.verification; html += '' + Math.round(check.joint_accuracy_success * check.n) + " of " + check.n + " held-out runs met the original accuracy targets for both predictions (" + check.tolerance.map(t => "±" + t).join(", ") + ").
"; if (Number.isFinite(check.joint_coverage)) html += 'The 90% prediction intervals contained both solver results on ' + Math.round(check.joint_coverage * check.n) + " of those " + check.n + " runs (" + F.pct(check.joint_coverage, 1) + ").
"; } else html += noteHtml("This fit has no held-out solver results to compare."); const L = limits(); const now = A.probeCheck(m.probe_bands, L.target); html += 'Each bar shows typical uncertainty as a share of your limit. At each sampled setting we use the larger of the two relative half-widths, then take the median. ' + (mixed ? "" : now.calibrated ? "Intervals are calibrated. " : "Uncalibrated: ensemble spread, not a confidence interval. ") + (m.version_id !== v.version_id ? "The latest model uses version " + ((W.view.versions.find((y) => y.version_id === m.version_id) || {}).number || "?") + "; runs added after it count toward the budget but not yet toward these bars. " : "") + "A new fit adds a bar.
"; return html; } function progressHtml() { return 'This generated example has a fitted model ready. Choose Predict outcomes to try a new setting.
' : !m && !job && !enabled ? '' + GPU_NOTE + "
" : ""; return ( head("Your study", lede) + about + (W.message ? errorHtml(W.message, W.issues) : "") + (m ? '' : "") + (job ? jobPanel(job) : "") + (!job && last && last.status === "failed" ? errorHtml("The last fit stopped with an error: " + ((last.error && last.error.message) || "unknown error"), []) : "") + (!job && last && last.status === "cancelled" ? noteHtml("The last fit was cancelled.") : "") + (!enabled && !m ? '' : "") + (canFit ? '' + (pts.observed.length ? pts.observed.length + " training run" + (pts.observed.length === 1 ? "" : "s") + " share" + (pts.observed.length === 1 ? "s" : "") + " the held settings" : "No training run shares the held settings") + " (within " + F.SLICE_TOLERANCE * 100 + "% of each control's range, one slider step). " + (W.showProjected ? "Hollow points have different held settings, so the curve is not expected to pass through them." : pts.otherCount + " other training runs are hidden.") + " Outcomes are nondimensional.
" + F.dataTable([F.axisName(names[c.xIndex]), "Prediction", "Lower", "Upper"], c.xs.map((x, i) => [x, c.result.mean[i][j], b.lower[i], b.upper[i]]), "Curve values as a table") ); } function latestRecommendation() { const m = model(); return W.view.recommendations.filter((r) => r.model_id === m.model_id).slice(-1)[0] || null; } function renderCurve() { const box = $("wb-curve"); if (box) F.mountChart(box, curveHtml); } /* The Predict story: what the model learned from, that it is fitted, and how much it has * been used. The prediction count is the server's own usage ledger for this study. */ // A compact line under the prediction: what the model learned from, how it was checked, and // how many settings it has evaluated (the server's ledger, including the automatic checks). // Pending messages carry a start time; one ticker shows elapsed seconds so a slow request // reads as working, not stuck. No invented progress. const pending = (label) => '' + esc(label) + "
"; if (typeof window !== "undefined") setInterval(() => { document.querySelectorAll("[data-since]").forEach((el) => { const s = Math.floor((Date.now() - Number(el.dataset.since)) / 1000); const e = el.querySelector(".elapsed"); if (e && s >= 2) e.textContent = s + " s" + (s >= 20 ? ". The free server can be slow when busy." : ""); }); }, 1000); function storyHtml() { const m = model(); const used = m.role_counts_used || latestVersion().role_counts; const per = W.predictTiming ? W.predictTiming.ms / W.predictTiming.points / 1000 : null; const check = m.verification; return ( 'Trained on ' + used.train + " runs (plus " + used.development + " to choose checkpoints and " + used.calibration + " to calibrate intervals)" + (check ? "; both predictions met the accuracy target on " + Math.round(check.joint_accuracy_success * check.n) + " of " + check.n + " held-out settings" : "") + '; ' + (W.predCount == null ? "…" : W.predCount.toLocaleString()) + " settings evaluated so far, including the automatic checks on this page" + (per ? " (about " + F.fmt(per, 2) + " s per setting in timed batches)" : "") + ".
" ); } async function refreshCount() { try { const r = await DeltaLoading.track(client.report(W.view.study_id), "workbench"); W.predCount = r.usage.untested_settings_predicted; W.report = r; } catch (e) { return; } if ($("wb-story")) $("wb-story").innerHTML = storyHtml(); } // Time model calls so the counter can say how quick a prediction is. Measured, never assumed. async function timedPredict(m, points, fields) { const t0 = performance.now(); const done = await DeltaLoading.track(client.predict(m.model_id, points, fields).then(job => client.settle(job)), "workbench"); // Only batch calls are timed: a lone point is mostly network round trip, not model time. if (points.length >= 16) { const t = W.predictTiming || { ms: 0, points: 0 }; W.predictTiming = { ms: t.ms + performance.now() - t0, points: t.points + points.length }; } refreshCount(); return done; } // Where is the model still unsure? A 4 x 4 x 4 grid over the whole study range, each 90% half-width // compared with the accuracy target. The widest spots are what the next runs should cover. async function computeUnsure() { const m = model(); const L = limits(); const steps = [0.125, 0.375, 0.625, 0.875]; const pts = []; steps.forEach((a) => steps.forEach((b) => steps.forEach((c) => pts.push([a, b, c].map((t, j) => m.ranges[j][0] + t * (m.ranges[j][1] - m.ranges[j][0])))))); W.unsure = { model: m.model_id, pending: true }; const box = () => $("wb-unsure") && ($("wb-unsure").innerHTML = unsureHtml()); box(); try { const res = (await timedPredict(m, pts)).result; const lo = res.lower || res.raw_lower; const hi = res.upper || res.raw_upper; const rows = pts.map((x, i) => ({ x, ratio: Math.max(...L.target.map((t, j) => (hi[i][j] - lo[i][j]) / 2 / t)), half: L.target.map((t, j) => (hi[i][j] - lo[i][j]) / 2) })); W.unsure = { model: m.model_id, calibrated: !!res.lower, n: pts.length, wide: rows.filter((r) => r.ratio > 1).length, top: rows.sort((a, b) => b.ratio - a.ratio).slice(0, 3), target: L.target.slice() }; } catch (e) { W.unsure = { model: m.model_id, error: e.message }; } box(); } function unsureHtml() { const u = W.unsure; const names = ctlNames(); let body; if (!u || u.pending) body = pending("Checking 64 test settings across your study…"); else if (u.error) body = noteHtml("The check could not run: " + u.error); else { const width = u.calibrated ? "90% interval half-width" : "uncalibrated model half-spread"; body = "" + (u.wide ? "At " + u.wide + " of " + u.n + " sampled settings across your study, the " + width + " exceeds the accuracy target (±" + u.target.join(", ±") + "). The largest estimates are at:" : "At all " + u.n + " sampled settings across your study, the " + width + " meets the accuracy target. A small confirming batch in your solver is still worth running. The largest estimates are at:") + "
" + 'These estimates use a regular grid across your study. Use solver runs to check the predictions at settings that matter to your decision.
'; } function viewExplore() { const m = model(); const names = ctlNames(); const rec = latestRecommendation(); const train = W.runs.runs.filter((r) => r.role === "train"); const fixedText = names.map((n, j) => (j === W.xIndex ? null : F.axisName(n) + " " + F.fmt(W.fixed[j], 3))).filter(Boolean).join(", "); return ( head("Predict outcomes", m.calibration.status === "calibrated" ? "Enter a setting to predict both outcomes with calibrated 90% prediction intervals." : "Enter a setting to predict both outcomes. The uncalibrated ranges show how much the fitted models disagree.") + (m.profile !== "task8-fno-lhs-v1" ? '" : "") + 'How one outcome changes as one setting varies. The trend keeps its own held settings, shown on the right. ' + (m.calibration.status === "calibrated" ? "Shading is the calibrated 90% prediction interval." : "Shading is raw spread, not a calibrated range.") + "
" + '' + esc(A.intervalText(m.calibration)) + "
" + (m.calibration.scope ? '' + esc(m.calibration.scope) + "
" : "") + "Calibrated so that, on cases like the held-out ones, both outcomes fall inside together about 90% of the time. Not a guarantee for one setting.' + (model().verification && Number.isFinite(model().verification.joint_coverage) ? " Measured on this example: " + F.pct(model().verification.joint_coverage, 1) + " of " + model().verification.n + " held-out settings." : "") + "
" : "") + 'For ' + names.map((n, k) => F.axisName(n) + " " + F.fmt(p.x[k], 3)).join(", ") + ". Nondimensional units. A prediction, not a simulation.
" + (r.fields || r.fields_uint8 ? '' : "") ); } /** One 64 x 64 channel of the first point as rows, from byte-packed fields or plain nested lists. */ function fieldGrid(result, c) { const packed = result.fields_uint8; if (!packed) return result.fields ? result.fields[0][c] : null; const [, channels, ny, nx] = packed.shape; const raw = atob(packed.data), lo = packed.lo[0][c], hi = packed.hi[0][c], start = c * ny * nx; const rows = []; for (let i = 0; i < ny; i++) { const row = new Array(nx); for (let j = 0; j < nx; j++) row[j] = lo + (raw.charCodeAt(start + i * nx + j) / 255) * (hi - lo); rows.push(row); } return channels > c ? rows : null; } function drawFields(result) { const box = $("wb-maps"); if (!box || !result || !fieldGrid(result, 1)) return; box.innerHTML = ""; // Signed fields on a shared, symmetric, zero-centred diverging scale per field, with a numeric colour bar. [[1, "Pressure"], [2, "Velocity u"], [3, "Velocity v"]].forEach(([c, name]) => { const grid = fieldGrid(result, c); let max = 0; grid.forEach((row) => row.forEach((v) => (max = Math.max(max, Math.abs(v))))); const canvas = document.createElement("canvas"); canvas.width = 64; canvas.height = 64; canvas.setAttribute("role", "img"); canvas.setAttribute("aria-label", "Predicted " + name.toLowerCase() + " field at t = 2 on the 64 × 64 grid, colour scale −" + F.fmt(max, 3) + " to +" + F.fmt(max, 3)); const ctx = canvas.getContext("2d"); const img = ctx.createImageData(64, 64); for (let i = 0; i < 64; i++) for (let j = 0; j < 64; j++) { const t = max ? grid[63 - i][j] / max : 0; const k = (i * 64 + j) * 4; const rgb = COLORMAPS.BrBG[Math.max(0, Math.min(255, Math.round((t + 1) * 127.5)))]; img.data[k] = rgb >> 16; img.data[k + 1] = (rgb >> 8) & 255; img.data[k + 2] = rgb & 255; img.data[k + 3] = 255; } ctx.putImageData(img, 0, 0); const bar = document.createElement("canvas"); bar.width = 128; bar.height = 1; bar.className = "cbar-strip"; bar.setAttribute("aria-hidden", "true"); const bctx = bar.getContext("2d"); const bimg = bctx.createImageData(128, 1); for (let i = 0; i < 128; i++) { const rgb = COLORMAPS.BrBG[i * 2]; bimg.data.set([rgb >> 16, (rgb >> 8) & 255, rgb & 255, 255], i * 4); } bctx.putImageData(bimg, 0, 0); const fig = document.createElement("figure"); fig.appendChild(canvas); const cap = document.createElement("figcaption"); cap.innerHTML = "" + esc(name) + ""; cap.appendChild(bar); const ticks = document.createElement("span"); ticks.className = "cbar-ticks"; ticks.innerHTML = "−" + F.fmt(max, 2) + "0+" + F.fmt(max, 2) + ""; cap.appendChild(ticks); fig.appendChild(cap); box.appendChild(fig); }); } async function predictPoint() { const m = model(); const requestId = (W.pointRequest = (W.pointRequest || 0) + 1); const x = [...document.querySelectorAll("[data-pt]")].map((i) => Number(i.value)); const bad = x.findIndex((v, j) => !Number.isFinite(v) || v < m.ranges[j][0] || v > m.ranges[j][1]); const fields = $("wb-fields").checked; if (bad >= 0) { W.point = { x, fields, error: "Enter " + F.axisName(W.cap.controls[bad].name) + " between " + m.ranges[bad][0] + " and " + m.ranges[bad][1] + " (the study's range)." }; const input = document.querySelector('[data-pt="' + bad + '"]'); if (input) input.setAttribute("aria-invalid", "true"); } else { document.querySelectorAll("[data-pt]").forEach((i) => i.removeAttribute("aria-invalid")); W.point = { x, fields, pending: true }; $("wb-point").innerHTML = pointHtml(); $("wb-predict").disabled = true; try { const done = await timedPredict(m, [x], fields); if (requestId !== W.pointRequest || !model() || model().model_id !== m.model_id) return; W.point = { x, fields, result: done.result }; } catch (e) { if (requestId !== W.pointRequest) return; W.point = { x, fields, error: "Prediction failed: " + e.message }; } } if (!$("wb-point")) return; $("wb-predict").disabled = false; $("wb-point").innerHTML = pointHtml(); if (W.point.result) drawFields(W.point.result); } /* ---------- Next runs ---------- */ // Display names describe what each backend policy does; the exact recipe stays visible underneath. const PROFILE_NAME = { "task8-fno-lhs-v1": "Standard fine-tuning recipe: three copies, calibrated intervals" }; const profileName = (id, label) => PROFILE_NAME[id] || label; const POLICY_NAME = { "mapped-lhs-v1": "Even coverage (recommended)", "maximin-v1": "Even coverage, largest gaps first", "uncertainty-diversity-experimental": "Uncertainty-driven (experimental)", }; const WHY = { "mapped-lhs-v1": "These are the next settings in this study's space-filling plan, which spreads runs evenly; it did best in our research.", "maximin-v1": "These fill the largest gaps between the runs you already have.", "uncertainty-diversity-experimental": "These are where the model's spread is widest, kept apart from each other. Experimental: it did worse than even coverage in our research." }; // The user's limits for the next batch: where to look, how accurate is enough, how many runs. function limits() { const m = model(); if (!W.limits || W.limits.model !== m.model_id) W.limits = { model: m.model_id, region: m.ranges.map((r) => r.slice()), target: m.tolerance.slice() }; return W.limits; } const POLICY_HELP = { "mapped-lhs-v1": "Spreads runs evenly across your settings, following the study's own plan. Did best in our research.", "maximin-v1": "Spreads runs evenly, filling the biggest empty gaps between the runs you have first.", "uncertainty-diversity-experimental": "Picks where the model is least sure, kept apart from each other. Experimental: did worse than even coverage in our research.", }; function viewNext() { const m = model(); const v = latestVersion(); const L = limits(); const names = ctlNames(); const policies = W.cap.recommendation_policies; const hasAcq = !!v.acquisition; const policy = W.nextOpts.policy || (hasAcq ? "mapped-lhs-v1" : "maximin-v1"); const isExample = !!W.view.example_id; return ( head("Plan next runs", "Choose a batch size and a method for picking settings. Run the suggested settings in your solver, then add the results here.") + progressHtml() + '" + (W.message ? errorHtml(W.message, W.issues) : "") + 'Adding results creates a new study version. ' + (W.cap.adapt.enabled ? "The model stays on its current version until you fit it again." : "The model stays on its current version until it is fitted again.") + "
" + 'Worked example only: these are solver results recorded during our research, replayed here. No new simulation runs.
' : "") + "Checking against your accuracy target…
'; if (t.error) return noteHtml("The accuracy check could not run: " + t.error); const pct = Math.round((t.wide / t.n) * 100); const width = t.calibrated ? "Calibrated uncertainty" : "Uncalibrated model spread"; const result = t.wide === 0 ? "meets your limits at all " + t.n + " test settings" : "exceeds your limits at " + t.wide + " of " + t.n + " test settings (" + pct + "%)"; return 'Set your limits above, then choose Suggest next runs.
'; if (r.pending) return pending("Finding next runs…"); const names = ctlNames(); const outcomes = W.runs.outcomes; const ci = r.rows.some((row) => row.calibrated_interval); return ( targetHtml(W.targetCheck) + (r.rows.length ? '' + esc(WHY[r.policy] || r.policy_label) + " Run them in your solver, then upload the completed runs below.
" : "") + (r.notes || []).filter((n) => !/differs from the eight-run|prefix of the recorded order|batches of/.test(n)).map(noteHtml).join("") + (r.rows.length ? '' + '| # | ' + names.map((n) => '' + esc(ctlLabel(n)) + " | ").join("") + outcomes.map((o) => 'Expected ' + esc(lcFirst(A.OUTCOME_LABEL[o])) + (ci ? " (90% range)" : "") + " | ").join("") + "
|---|---|---|
| ' + (i + 1) + " | " + row.controls.map((x) => '' + F.fmt(x, 3) + " | ").join("") + outcomes.map((o, j) => '' + F.fmt(row.predicted[j], 3) + (row.calibrated_interval ? ' (' + F.fmt(row.calibrated_interval[0][j], 3) + "–" + F.fmt(row.calibrated_interval[1][j], 3) + ")" : "") + " | ").join("") + "
Loading the report…
'); const u = r.usage; const sc = r.scenario; const m = r.model; const used = u.labels_consumed_by_latest_model; const by = u.supplied_by_role; const runtime = Object.entries(u.worker_runtime_seconds); const charges = Object.entries(u.known_charges); const verOk = m && m.verification ? Math.round(m.verification.joint_accuracy_success * m.verification.n) : null; const row = (k, v, note) => "| Item | Count | Note |
|---|
Compare these numbers with the solver runs you planned. The result is budget remaining under your assumptions, not verified savings.
Removes the study, its versions and its models from this server. You will be asked to confirm. This cannot be undone.
' + 'For ' + esc(displayName(r.study)) + ". " + esc(r.verified_cost_savings) + "
" + '' + esc(sc.message || "Enter your plan to compare.") + "
" : '| ' + esc(a) + ' | ' + esc(b) + " |
|---|
A scenario against your own plan. It shows budget not yet spent, not proven savings. Unknown inputs stay unknown, and going over plan shows as extra cost.
' ); } async function renderBudget(box) { if (!box) return; const id = client.studyId(); if (!id) { box.innerHTML = 'Walk through a real study or open the earlier generated example to see a budget here.
'; return; } box.innerHTML = 'Loading your study…
'; try { if (!W.view || W.view.study_id !== id) { W.cap = W.cap || (await client.capabilities()); await loadStudy(id); } W.report = await client.report(id); const draw = (msg) => { box.innerHTML = budgetHtml(W.report) + (msg ? errorHtml(msg) : ""); const sf = box.querySelector("#wb-scenario"); sf.onsubmit = async (e) => { e.preventDefault(); const btn = sf.querySelector("button"); btn.disabled = true; btn.textContent = "Comparing…"; try { W.report = await DeltaLoading.track(client.scenario(W.view.study_id, formJson(sf)), "how"); draw(); } catch (err) { draw(err.message); } }; }; draw(); } catch (e) { box.innerHTML = errorHtml("Your study could not be loaded: " + e.message); } } async function loadReport() { W.report = await client.report(W.view.study_id); } function formJson(form) { const out = {}; new FormData(form).forEach((v, k) => { if (v === "") return; out[k] = ["planned_runs", "concurrency"].includes(k) ? parseInt(v, 10) : ["cost_per_run", "wall_hours_per_run", "amount"].includes(k) ? Number(v) : k === "currency" ? String(v).toUpperCase() : v; }); return out; } function openExample() { guard(async () => { const v = await client.startExample(); await loadStudy(v.study_id); W.step = model() ? 1 : 0; W.notice = null; }); } /* ---------- render + events ---------- */ /* Step states come from server state (study, version, model, jobs, recommendations), * never from which step happens to be selected. */ function stepStates() { const v = latestVersion(); const m = model(); const fit = activeFit(); const rec = m && latestRecommendation(); const noModel = fit ? "Fitting" : W.view ? "Needs a model" : "Open a study first"; return [ !W.view ? { state: "available" } : fit ? { state: "running", text: "Fitting" } : m ? (m.version_id === v.version_id ? { state: "done", text: "Model ready" } : { state: "done", text: "Model ready" }) : { state: "available", text: "Awaiting fit" }, m ? { state: "available" } : { state: "blocked", text: noModel }, m ? (rec ? { state: "done", text: "Suggested" } : { state: "available" }) : { state: "blocked", text: noModel }, m ? { state: "available" } : { state: "blocked", text: noModel }, ]; } function renderHeading() { const v = latestVersion(); const m = model(); const fit = activeFit(); $("wb-scope").hidden = !!W.view; if (!W.view) { $("wb-eyebrow").textContent = "WORKBENCH"; $("wb-title").textContent = "Workbench"; $("wb-sub").textContent = "Bring compatible simulation runs, fit a model to them, explore untested settings and plan the next batch."; return; } const status = fit ? "Fitting the model" : m ? (m.version_id === v.version_id ? (m.preadapted ? "Example model ready" : "Model ready") : "Model still uses version " + ((W.view.versions.find((x) => x.version_id === m.version_id) || {}).number || 1)) : "Awaiting fit yet"; $("wb-eyebrow").textContent = "WORKBENCH"; $("wb-title").textContent = displayName(W.view); // One compact line: data label, version, model status. Counts live in Your study and Summary. const r = m ? modelRuns(m, v) : null; $("wb-sub").innerHTML = dataTag(v.data_kind) + " Version " + v.number + " " + esc(status) + (r ? " · trained on " + r.used.train + " runs" + (r.added ? ", " + r.added + " newer runs not yet used" : "") : "") + ""; } function renderSteps() { const max = maxStep(); const states = stepStates(); renderHeading(); $("wb-step-label").textContent = "Step " + (W.step + 1) + " of " + STEPS.length; $("wb-step-select").innerHTML = STEPS.map((s, i) => '").join(""); $("wb-step-select").onchange = (e) => setStep(Number(e.target.value)); $("wb-steps").innerHTML = STEPS.map((s, i) => { const st = states[i]; const locked = i > max; return '"; }).join(""); } function render(focus) { if (!W.ready) return; renderSteps(); if (!W.cap) { $("wb-panel").innerHTML = W.message ? errorHtml(W.message, W.issues) : 'Connecting to the study API…
'; return; } W.step = Math.min(W.step, maxStep()); const views = [viewStudy, viewExplore, viewNext, viewReport]; const previousFocus = document.activeElement && document.activeElement.id; $("wb-panel").innerHTML = (W.notice ? okHtml(W.notice) : "") + views[W.step](); W.notice = null; bind(); if (W.step === 1) { if (W.predCount == null || W.countStudy !== W.view.study_id) { W.countStudy = W.view.study_id; refreshCount(); } renderCurve(); // Your own prediction first, then the trend, then the probe check; one server job at a time. (async () => { if (!W.point) await predictPoint(); await requestCurve(); if (!W.unsure || W.unsure.model !== model().model_id) await computeUnsure(); })(); if (W.point && W.point.result) drawFields(W.point.result); } if (W.step === 0 && $("wb-parity")) F.mountChart($("wb-parity"), (w) => parityHtml(model(), w)); if (W.step === 0) DeltaLoading.track(renderStudyList(), "workbench"); if (W.step === 3 && !W.report && !W.message) guard(loadReport); if (!focus && previousFocus && $(previousFocus)) $(previousFocus).focus({ preventScroll: true }); if (focus) { const h = $("wb-panel").querySelector("h2"); if (h) h.focus({ preventScroll: false }); } } function bind() { const on = (id, fn) => { const n = $(id); if (n) n.onclick = fn; }; if (W.step === 0) { on("wb-example", openExample); const drop = $("wb-drop"); drop.ondragover = (e) => { e.preventDefault(); drop.classList.add("over"); }; drop.ondragleave = () => drop.classList.remove("over"); drop.ondrop = (e) => { e.preventDefault(); drop.classList.remove("over"); uploadFile(e.dataTransfer.files[0]); }; $("wb-file").onchange = (e) => uploadFile(e.target.files[0]); on("wb-fit", () => guard(async () => { const body = { allow_uncalibrated: !!($("wb-uncal") && $("wb-uncal").checked) }; if ($("wb-profile")) body.profile = $("wb-profile").value; await client.fit(W.view.study_id, body); await refreshStudy(); })); on("wb-cancel", () => guard(async () => { await client.cancel(activeFit().job_id); await refreshStudy(); })); on("wb-go-explore", () => setStep(1)); const po = $("wb-parity-outcome"); if (po) po.onchange = () => { W.outcome = Number(po.value); render(false); }; } if (W.step === 1) { $("wb-outcome").onchange = (e) => { W.outcome = Number(e.target.value); e.target.nextElementSibling.textContent = OUTCOME_HELP[W.runs.outcomes[W.outcome]] || ""; renderCurve(); }; $("wb-xsel").onchange = (e) => { W.xIndex = Number(e.target.value); render(false); }; const heldText = () => { const t = $("wb-fixed-text"); if (t) t.textContent = "Held at " + ctlNames().map((n, j) => (j === W.xIndex ? null : F.axisName(n) + " " + F.fmt(W.fixed[j], 3))).filter(Boolean).join(", "); }; let timer = null; document.querySelectorAll("[data-fix]").forEach((r) => { r.oninput = () => { const j = Number(r.dataset.fix); W.fixed[j] = Number(r.value); $("wb-out-" + j).textContent = F.fmt(W.fixed[j], 3); heldText(); }; // One request when the slider is released, not one per movement. r.onchange = () => { clearTimeout(timer); timer = setTimeout(requestCurve, 250); }; }); $("wb-hold-run").onchange = (e) => { const run = W.runs.runs.find((r) => r.run_id === e.target.value); if (!run) return; run.controls.forEach((v, k) => { if (k !== W.xIndex) W.fixed[k] = v; }); render(false); }; $("wb-show-projected").onchange = (e) => { W.showProjected = e.target.checked; renderCurve(); }; if ($("wb-show-next")) $("wb-show-next").onchange = (e) => { W.showNext = e.target.checked; renderCurve(); }; on("wb-predict", () => predictPoint()); on("wb-point-to-trend", () => { const x = [...document.querySelectorAll("[data-pt]")].map((i) => Number(i.value)); x.forEach((v, k) => { if (k !== W.xIndex && Number.isFinite(v)) W.fixed[k] = v; }); render(false); }); on("wb-go-next", () => setStep(2)); } if (W.step === 0 || W.step === 2) bindProgress(); if (W.step === 2) { // The accuracy target defines which settings count as within target, so the progress bars follow it as you type. document.querySelectorAll("[data-target]").forEach((t) => (t.oninput = () => { const target = W.runs.outcomes.map((o, j) => Number(document.querySelector('[data-target="' + j + '"]').value)); if (!target.every((x) => x > 0)) return; limits().target = target; $("wb-progress-body").innerHTML = progressBody(); })); $("wb-policy").onchange = (e) => { W.nextOpts.policy = e.target.value; $("wb-policy-help").textContent = POLICY_HELP[e.target.value] || ""; }; $("wb-batch").onchange = (e) => (W.nextOpts.batch = Number(e.target.value)); $("wb-limits").onsubmit = (e) => { e.preventDefault(); guard(suggest); }; on("wb-next-csv", () => guard(() => downloadArtifact("next-runs-" + W.next.recommendation_id + ".csv"))); $("wb-add-file").onchange = (e) => e.target.files[0] && guard(() => addRuns(e.target.files[0])); on("wb-example-complete", () => guard(async () => { const res = await client.exampleCompletions(W.next.rows.map((r) => r.candidate_id)); await addRuns(await res.blob()); })); on("wb-example-dl", () => guard(async () => { const res = await client.exampleCompletions(W.next.rows.map((r) => r.candidate_id)); download("deltav-example-completed-runs.zip", await res.blob()); })); } if (W.step === 3) { const cf = $("wb-charge"); if (cf) cf.onsubmit = (e) => { e.preventDefault(); guard(async () => { W.report = await client.charge(W.view.study_id, formJson(cf)); }); }; document.querySelectorAll("[data-artifact]").forEach((b) => (b.onclick = () => guard(() => downloadArtifact(b.dataset.artifact)))); on("wb-artifacts", () => guard(async () => { const list = await client.artifacts(W.view.study_id); W.artifacts = list.artifacts; })); if (W.artifacts && $("wb-artifact-list")) { $("wb-artifact-list").innerHTML = '| Artifact | Kind | SHA-256 | |
|---|---|---|---|
| " + esc(a.name) + " | " + esc(a.kind) + (a.weights_location ? " " + esc(a.weights_location) + "" : "") + " | " + short(a.sha256) +
' |