Spaces:
Running
Running
Update MagNet static website
Browse files- README.md +5 -3
- assets/app.js +145 -98
- assets/styles.css +19 -4
- index.html +37 -9
README.md
CHANGED
|
@@ -15,9 +15,11 @@ This Space hosts the [MagNet website](https://huggingface.co/spaces/minjiechen/M
|
|
| 15 |
a public catalog of magnetic-material measurements, training-ready datasets,
|
| 16 |
models, and documentation. Its steady-state iGSE predictor runs in your browser;
|
| 17 |
the ten original steady-state B-H Transformer models also run in the browser as
|
| 18 |
-
an experimental preview.
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
The full downloadable data are published separately in the
|
| 23 |
[MagNet dataset repository](https://huggingface.co/datasets/minjiechen/MagNet)
|
|
|
|
| 15 |
a public catalog of magnetic-material measurements, training-ready datasets,
|
| 16 |
models, and documentation. Its steady-state iGSE predictor runs in your browser;
|
| 17 |
the ten original steady-state B-H Transformer models also run in the browser as
|
| 18 |
+
an experimental preview. One Predict form shows both volumetric-loss estimates
|
| 19 |
+
and plots the Transformer's predicted B–H loop. The neural conversion was
|
| 20 |
+
checked numerically against the preserved PyTorch weights, but its independent
|
| 21 |
+
predictive accuracy has not been certified. No server-side prediction API is
|
| 22 |
+
provided.
|
| 23 |
|
| 24 |
The full downloadable data are published separately in the
|
| 25 |
[MagNet dataset repository](https://huggingface.co/datasets/minjiechen/MagNet)
|
assets/app.js
CHANGED
|
@@ -6,6 +6,7 @@ const state = {
|
|
| 6 |
modelQuery: "",
|
| 7 |
route: "home",
|
| 8 |
neuralPredictor: null,
|
|
|
|
| 9 |
};
|
| 10 |
|
| 11 |
const staticMode = document.documentElement.dataset.magnetStatic === "true";
|
|
@@ -254,36 +255,70 @@ function drawWaveform(values) {
|
|
| 254 |
function currentWaveform() {
|
| 255 |
const kind = el("waveform").value;
|
| 256 |
const duty = Number(el("duty").value);
|
| 257 |
-
const
|
| 258 |
-
|
| 259 |
-
if (!neural || kind !== "triangle") return values;
|
| 260 |
const shift = Math.trunc((duty <= 0.5 ? 0.5 - duty / 2 : -duty / 2) * 128);
|
| 261 |
return values.map((_, index) => values[((index - shift) % 128 + 128) % 128]);
|
| 262 |
}
|
| 263 |
|
| 264 |
-
function
|
| 265 |
-
const modelId = el("prediction-model").value;
|
| 266 |
-
const neural = modelId === "legacy-transformer-v1";
|
| 267 |
const selectedMaterial = el("material").value;
|
| 268 |
-
const
|
|
|
|
| 269 |
const supported = state.catalog.materials.filter((item) =>
|
| 270 |
-
|
| 271 |
el("material").innerHTML = supported.map((item) =>
|
| 272 |
`<option value="${escapeHtml(item.id)}">${escapeHtml(item.manufacturer)} ${escapeHtml(item.id)}</option>`).join("");
|
| 273 |
if (supported.some((item) => item.id === selectedMaterial)) el("material").value = selectedMaterial;
|
| 274 |
-
el("bias-control").hidden = !neural;
|
| 275 |
-
el("predict-description").textContent = neural
|
| 276 |
-
? "The legacy MagNet Transformer predicts a B–H loop and integrates steady-state loss. This browser conversion passed numerical parity checks; independent accuracy is not certified."
|
| 277 |
-
: "Use the transparent iGSE baseline for a steady-state estimate. Results outside the measured frequency range are flagged.";
|
| 278 |
-
el("prediction-note").textContent = neural
|
| 279 |
-
? "Experimental legacy neural model. The first run downloads a browser runtime and material model."
|
| 280 |
-
: "Set an operating point and calculate.";
|
| 281 |
-
el("loss-result").textContent = "—";
|
| 282 |
el("predict-button").disabled = !supported.length;
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
| 284 |
updateWaveform();
|
| 285 |
}
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
function updateDutyVisibility() {
|
| 288 |
const triangular = el("waveform").value === "triangle";
|
| 289 |
el("duty-control").hidden = !triangular;
|
|
@@ -295,9 +330,9 @@ function updateWaveform() {
|
|
| 295 |
const dutySummary = el("waveform").value === "triangle"
|
| 296 |
? `, ${Math.round(Number(el("duty").value) * 100)}% rising / ${Math.round((1 - Number(el("duty").value)) * 100)}% falling`
|
| 297 |
: "";
|
| 298 |
-
const phaseSummary = el("
|
| 299 |
? " Phase-aligned for the legacy model." : "";
|
| 300 |
-
el("waveform-summary").textContent = `${waveformName} waveform, ${el("flux").value} mT peak${dutySummary}.${phaseSummary}`;
|
| 301 |
}
|
| 302 |
|
| 303 |
function errorMessage(detail) {
|
|
@@ -309,70 +344,33 @@ function errorMessage(detail) {
|
|
| 309 |
|
| 310 |
async function predict(event) {
|
| 311 |
event.preventDefault();
|
| 312 |
-
|
|
|
|
| 313 |
const values = currentWaveform();
|
| 314 |
updateWaveform();
|
| 315 |
-
|
|
|
|
|
|
|
| 316 |
el("predict-button").disabled = true;
|
| 317 |
const controls = Array.from(el("prediction-form").querySelectorAll("input, select"));
|
| 318 |
controls.forEach((control) => { control.disabled = true; });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
try {
|
| 320 |
-
const
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
b_waveform_t: values,
|
| 326 |
-
};
|
| 327 |
let result;
|
| 328 |
-
|
| 329 |
-
if (modelId === "legacy-transformer-v1") {
|
| 330 |
-
if (!staticMode || !window.MagNetNeuralPredictor) {
|
| 331 |
-
throw new Error("Browser neural predictor unavailable. Please refresh the page.");
|
| 332 |
-
}
|
| 333 |
-
const material = encodeURIComponent(request.material_id);
|
| 334 |
-
const modelBase = `./assets/neural/${material}/`;
|
| 335 |
-
const normResponse = await fetch(`${modelBase}norm.json`);
|
| 336 |
-
if (!normResponse.ok) throw new Error(`Neural model normalization unavailable (${normResponse.status}).`);
|
| 337 |
-
const norm = await normResponse.json();
|
| 338 |
-
if (!state.neuralPredictor) {
|
| 339 |
-
state.neuralPredictor = new window.MagNetNeuralPredictor({
|
| 340 |
-
workerUrl: "./assets/neural-worker.js",
|
| 341 |
-
ortScriptUrl: "./assets/ort.wasm.min.js",
|
| 342 |
-
wasmBaseUrl: "./assets/",
|
| 343 |
-
});
|
| 344 |
-
}
|
| 345 |
-
const duty = el("waveform").value === "triangle" ? Number(el("duty").value) : 0.5;
|
| 346 |
-
const domainCheck = window.MagNetNeuralDomain
|
| 347 |
-
? window.MagNetNeuralDomain.check(request.material_id, [
|
| 348 |
-
request.frequency_hz, Number(el("flux").value) / 1000,
|
| 349 |
-
Number(el("bias").value), request.temperature_c, duty,
|
| 350 |
-
]).catch((error) => ({ error: error.message }))
|
| 351 |
-
: Promise.resolve({ error: "domain checker unavailable" });
|
| 352 |
-
result = await state.neuralPredictor.predict({
|
| 353 |
-
materialId: request.material_id,
|
| 354 |
-
b_waveform_t: values,
|
| 355 |
-
frequency_hz: request.frequency_hz,
|
| 356 |
-
temperature_c: request.temperature_c,
|
| 357 |
-
bias_a_per_m: Number(el("bias").value),
|
| 358 |
-
norm,
|
| 359 |
-
encoderUrl: `${modelBase}encoder.onnx`,
|
| 360 |
-
decoderUrl: `${modelBase}decoder.onnx`,
|
| 361 |
-
}, {
|
| 362 |
-
onProgress(progress) {
|
| 363 |
-
el("loss-result").textContent = progress.stage === "loading"
|
| 364 |
-
? "Loading model…" : progress.stage === "decoding"
|
| 365 |
-
? `Calculating ${Math.min(progress.completedSteps, 128)}/128…` : "Finishing…";
|
| 366 |
-
},
|
| 367 |
-
});
|
| 368 |
-
const domain = await domainCheck;
|
| 369 |
-
if (domain?.error) domainNote = "Operating-domain check unavailable; use caution.";
|
| 370 |
-
else if ((typeof domain === "boolean" ? domain : domain?.inDomain) === false) {
|
| 371 |
-
domainNote = "Outside the legacy model's measured operating domain; this is an extrapolation.";
|
| 372 |
-
}
|
| 373 |
-
} else if (staticMode) {
|
| 374 |
if (!window.MagNetStaticPredictor?.predictLoss) {
|
| 375 |
-
throw new Error("
|
| 376 |
}
|
| 377 |
result = await window.MagNetStaticPredictor.predictLoss(request, state.catalog);
|
| 378 |
} else {
|
|
@@ -384,21 +382,76 @@ async function predict(event) {
|
|
| 384 |
result = await response.json();
|
| 385 |
if (!response.ok) throw new Error(errorMessage(result.detail));
|
| 386 |
}
|
| 387 |
-
el("loss-result").textContent =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
const notes = [...(result.warnings || [])];
|
| 389 |
-
if (
|
| 390 |
-
if (
|
| 391 |
-
notes.push("
|
| 392 |
-
} else {
|
| 393 |
-
notes.push(staticMode
|
| 394 |
-
? "Calculated in your browser with iGSE; temperature and DC bias are not modeled."
|
| 395 |
-
: `${result.model_id} ${result.model_version}; ${result.waveform_points} waveform points.`);
|
| 396 |
}
|
| 397 |
-
|
|
|
|
| 398 |
} catch (error) {
|
| 399 |
-
el("loss-result").textContent = "Unavailable";
|
| 400 |
-
el("prediction-note").textContent = error.message;
|
|
|
|
|
|
|
| 401 |
} finally {
|
|
|
|
| 402 |
el("predict-button").disabled = !el("material").options.length;
|
| 403 |
controls.forEach((control) => { control.disabled = false; });
|
| 404 |
}
|
|
@@ -411,17 +464,10 @@ async function init() {
|
|
| 411 |
el("material-count").textContent = state.catalog.materials.length;
|
| 412 |
el("dataset-count").textContent = state.catalog.datasets.length;
|
| 413 |
el("model-count").textContent = state.catalog.models.length;
|
| 414 |
-
const neural = state.catalog.models.find((item) => item.id === "legacy-transformer-v1");
|
| 415 |
-
if (staticMode && neural?.status === "available" && neural.inference_available) {
|
| 416 |
-
const option = document.createElement("option");
|
| 417 |
-
option.value = neural.id;
|
| 418 |
-
option.textContent = "MagNet Transformer (experimental)";
|
| 419 |
-
el("prediction-model").append(option);
|
| 420 |
-
}
|
| 421 |
renderDatasets();
|
| 422 |
renderModels();
|
| 423 |
updateDutyVisibility();
|
| 424 |
-
|
| 425 |
}
|
| 426 |
|
| 427 |
function configureStaticLinks() {
|
|
@@ -466,19 +512,20 @@ el("model-search").addEventListener("input", () => {
|
|
| 466 |
renderModels();
|
| 467 |
});
|
| 468 |
|
| 469 |
-
el("prediction-model").addEventListener("change", syncPredictionModel);
|
| 470 |
-
|
| 471 |
[["frequency", "frequency-output"], ["flux", "flux-output"], ["temperature", "temperature-output"]].forEach(([input, output]) => el(input).addEventListener("input", () => {
|
| 472 |
el(output).value = el(input).value;
|
|
|
|
| 473 |
if (input === "flux") updateWaveform();
|
| 474 |
}));
|
| 475 |
-
el("
|
|
|
|
| 476 |
el("waveform").addEventListener("change", updateDutyVisibility);
|
| 477 |
el("duty").addEventListener("input", () => {
|
| 478 |
el("duty-output").value = `${Math.round(Number(el("duty").value) * 100)}%`;
|
|
|
|
| 479 |
updateWaveform();
|
| 480 |
});
|
| 481 |
-
el("bias").addEventListener("input", () => { el("bias-output").value = el("bias").value; });
|
| 482 |
el("prediction-form").addEventListener("submit", predict);
|
| 483 |
window.addEventListener("resize", () => {
|
| 484 |
if (state.catalog && state.route === "predict") updateWaveform();
|
|
|
|
| 6 |
modelQuery: "",
|
| 7 |
route: "home",
|
| 8 |
neuralPredictor: null,
|
| 9 |
+
predictionRunning: false,
|
| 10 |
};
|
| 11 |
|
| 12 |
const staticMode = document.documentElement.dataset.magnetStatic === "true";
|
|
|
|
| 255 |
function currentWaveform() {
|
| 256 |
const kind = el("waveform").value;
|
| 257 |
const duty = Number(el("duty").value);
|
| 258 |
+
const values = waveform(kind, Number(el("flux").value), duty, 128);
|
| 259 |
+
if (kind !== "triangle") return values;
|
|
|
|
| 260 |
const shift = Math.trunc((duty <= 0.5 ? 0.5 - duty / 2 : -duty / 2) * 128);
|
| 261 |
return values.map((_, index) => values[((index - shift) % 128 + 128) % 128]);
|
| 262 |
}
|
| 263 |
|
| 264 |
+
function syncPredictionMaterials() {
|
|
|
|
|
|
|
| 265 |
const selectedMaterial = el("material").value;
|
| 266 |
+
const baseline = state.catalog.models.find((item) => item.id === "igse-v1");
|
| 267 |
+
const neural = state.catalog.models.find((item) => item.id === "legacy-transformer-v1");
|
| 268 |
const supported = state.catalog.materials.filter((item) =>
|
| 269 |
+
(item.igse && baseline?.materials?.includes(item.id)) || neural?.materials?.includes(item.id));
|
| 270 |
el("material").innerHTML = supported.map((item) =>
|
| 271 |
`<option value="${escapeHtml(item.id)}">${escapeHtml(item.manufacturer)} ${escapeHtml(item.id)}</option>`).join("");
|
| 272 |
if (supported.some((item) => item.id === selectedMaterial)) el("material").value = selectedMaterial;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
el("predict-button").disabled = !supported.length;
|
| 274 |
+
resetPrediction();
|
| 275 |
+
if (!supported.length) {
|
| 276 |
+
el("neural-prediction-note").textContent = "No material has an online iGSE or Transformer prediction.";
|
| 277 |
+
}
|
| 278 |
updateWaveform();
|
| 279 |
}
|
| 280 |
|
| 281 |
+
function resetPrediction() {
|
| 282 |
+
el("igse-loss-result").textContent = "—";
|
| 283 |
+
el("neural-loss-result").textContent = "—";
|
| 284 |
+
el("igse-prediction-note").textContent = "Uses waveform, frequency, and material; ignores temperature and DC bias.";
|
| 285 |
+
el("neural-prediction-note").textContent = "Experimental legacy model. First run downloads the browser runtime and material model.";
|
| 286 |
+
el("bh-loop-section").hidden = true;
|
| 287 |
+
el("bh-loop-path").setAttribute("d", "");
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
function formatLoss(loss) {
|
| 291 |
+
if (!Number.isFinite(loss)) throw new Error("Model returned a non-finite volumetric loss.");
|
| 292 |
+
return `${(loss / 1000).toLocaleString(undefined, { maximumFractionDigits: 1 })} kW/m³`;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
function drawBhLoop(b, h) {
|
| 296 |
+
if (!Array.isArray(b) || !Array.isArray(h) || b.length !== 128 || h.length !== b.length
|
| 297 |
+
|| !b.every(Number.isFinite) || !h.every(Number.isFinite)) {
|
| 298 |
+
throw new Error("Transformer returned an invalid 128-point B–H loop.");
|
| 299 |
+
}
|
| 300 |
+
const maxH = Math.max(...h.map(Math.abs), 1e-9);
|
| 301 |
+
const maxB = Math.max(...b.map(Math.abs), 1e-9);
|
| 302 |
+
const left = 74; const right = 728; const top = 40; const bottom = 300;
|
| 303 |
+
const centerX = (left + right) / 2;
|
| 304 |
+
const centerY = (top + bottom) / 2;
|
| 305 |
+
const path = h.map((field, index) => {
|
| 306 |
+
const x = centerX + field / maxH * (right - left) / 2;
|
| 307 |
+
const y = centerY - b[index] / maxB * (bottom - top) / 2;
|
| 308 |
+
return `${index ? "L" : "M"}${x.toFixed(2)} ${y.toFixed(2)}`;
|
| 309 |
+
}).join(" ");
|
| 310 |
+
el("bh-loop-path").setAttribute("d", path);
|
| 311 |
+
el("bh-loop-start").setAttribute("cx", (centerX + h[0] / maxH * (right - left) / 2).toFixed(2));
|
| 312 |
+
el("bh-loop-start").setAttribute("cy", (centerY - b[0] / maxB * (bottom - top) / 2).toFixed(2));
|
| 313 |
+
const fieldLabel = maxH >= 10 ? maxH.toFixed(1) : maxH.toPrecision(2);
|
| 314 |
+
const fluxLabel = (maxB * 1000).toFixed(0);
|
| 315 |
+
el("bh-h-negative").textContent = `−${fieldLabel}`;
|
| 316 |
+
el("bh-h-positive").textContent = `+${fieldLabel}`;
|
| 317 |
+
el("bh-b-positive").textContent = `+${fluxLabel}`;
|
| 318 |
+
el("bh-b-negative").textContent = `−${fluxLabel}`;
|
| 319 |
+
el("bh-loop-section").hidden = false;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
function updateDutyVisibility() {
|
| 323 |
const triangular = el("waveform").value === "triangle";
|
| 324 |
el("duty-control").hidden = !triangular;
|
|
|
|
| 330 |
const dutySummary = el("waveform").value === "triangle"
|
| 331 |
? `, ${Math.round(Number(el("duty").value) * 100)}% rising / ${Math.round((1 - Number(el("duty").value)) * 100)}% falling`
|
| 332 |
: "";
|
| 333 |
+
const phaseSummary = el("waveform").value === "triangle"
|
| 334 |
? " Phase-aligned for the legacy model." : "";
|
| 335 |
+
el("waveform-summary").textContent = `${waveformName} waveform, ${el("flux").value} mT peak${dutySummary}. Both methods receive the same 128 B samples.${phaseSummary}`;
|
| 336 |
}
|
| 337 |
|
| 338 |
function errorMessage(detail) {
|
|
|
|
| 344 |
|
| 345 |
async function predict(event) {
|
| 346 |
event.preventDefault();
|
| 347 |
+
if (state.predictionRunning) return;
|
| 348 |
+
state.predictionRunning = true;
|
| 349 |
const values = currentWaveform();
|
| 350 |
updateWaveform();
|
| 351 |
+
resetPrediction();
|
| 352 |
+
el("igse-loss-result").textContent = "Calculating…";
|
| 353 |
+
el("neural-loss-result").textContent = "Waiting…";
|
| 354 |
el("predict-button").disabled = true;
|
| 355 |
const controls = Array.from(el("prediction-form").querySelectorAll("input, select"));
|
| 356 |
controls.forEach((control) => { control.disabled = true; });
|
| 357 |
+
const request = {
|
| 358 |
+
model_id: "igse-v1",
|
| 359 |
+
material_id: el("material").value,
|
| 360 |
+
frequency_hz: Number(el("frequency").value) * 1000,
|
| 361 |
+
temperature_c: Number(el("temperature").value),
|
| 362 |
+
b_waveform_t: values,
|
| 363 |
+
};
|
| 364 |
try {
|
| 365 |
+
const baseline = state.catalog.models.find((item) => item.id === "igse-v1");
|
| 366 |
+
if (!baseline?.materials?.includes(request.material_id)
|
| 367 |
+
|| !state.catalog.materials.find((item) => item.id === request.material_id)?.igse) {
|
| 368 |
+
throw new Error("No iGSE coefficients are available for this material.");
|
| 369 |
+
}
|
|
|
|
|
|
|
| 370 |
let result;
|
| 371 |
+
if (staticMode) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
if (!window.MagNetStaticPredictor?.predictLoss) {
|
| 373 |
+
throw new Error("iGSE browser predictor unavailable. Please refresh the page.");
|
| 374 |
}
|
| 375 |
result = await window.MagNetStaticPredictor.predictLoss(request, state.catalog);
|
| 376 |
} else {
|
|
|
|
| 382 |
result = await response.json();
|
| 383 |
if (!response.ok) throw new Error(errorMessage(result.detail));
|
| 384 |
}
|
| 385 |
+
el("igse-loss-result").textContent = formatLoss(result.loss_w_per_m3);
|
| 386 |
+
el("igse-prediction-note").textContent = [
|
| 387 |
+
...(result.warnings || []),
|
| 388 |
+
"iGSE does not model temperature or DC bias.",
|
| 389 |
+
].join(" ");
|
| 390 |
+
} catch (error) {
|
| 391 |
+
el("igse-loss-result").textContent = "Unavailable";
|
| 392 |
+
el("igse-prediction-note").textContent = error.message;
|
| 393 |
+
}
|
| 394 |
+
try {
|
| 395 |
+
el("neural-loss-result").textContent = "Loading model…";
|
| 396 |
+
const neural = state.catalog.models.find((item) => item.id === "legacy-transformer-v1");
|
| 397 |
+
if (!neural?.materials?.includes(request.material_id)) {
|
| 398 |
+
throw new Error("No Transformer checkpoint is available for this material.");
|
| 399 |
+
}
|
| 400 |
+
if (!staticMode || !window.MagNetNeuralPredictor) {
|
| 401 |
+
throw new Error("Transformer browser inference is available in the static MagNet Space, not this server deployment.");
|
| 402 |
+
}
|
| 403 |
+
const material = encodeURIComponent(request.material_id);
|
| 404 |
+
const modelBase = `./assets/neural/${material}/`;
|
| 405 |
+
const normResponse = await fetch(`${modelBase}norm.json`);
|
| 406 |
+
if (!normResponse.ok) throw new Error(`Neural model normalization unavailable (${normResponse.status}).`);
|
| 407 |
+
const norm = await normResponse.json();
|
| 408 |
+
if (!state.neuralPredictor) {
|
| 409 |
+
state.neuralPredictor = new window.MagNetNeuralPredictor({
|
| 410 |
+
workerUrl: "./assets/neural-worker.js",
|
| 411 |
+
ortScriptUrl: "./assets/ort.wasm.min.js",
|
| 412 |
+
wasmBaseUrl: "./assets/",
|
| 413 |
+
});
|
| 414 |
+
}
|
| 415 |
+
const duty = el("waveform").value === "triangle" ? Number(el("duty").value) : 0.5;
|
| 416 |
+
const domainCheck = window.MagNetNeuralDomain
|
| 417 |
+
? window.MagNetNeuralDomain.check(request.material_id, [
|
| 418 |
+
request.frequency_hz, Number(el("flux").value) / 1000,
|
| 419 |
+
Number(el("bias").value), request.temperature_c, duty,
|
| 420 |
+
]).catch((error) => ({ error: error.message }))
|
| 421 |
+
: Promise.resolve({ error: "domain checker unavailable" });
|
| 422 |
+
const result = await state.neuralPredictor.predict({
|
| 423 |
+
materialId: request.material_id,
|
| 424 |
+
b_waveform_t: values,
|
| 425 |
+
frequency_hz: request.frequency_hz,
|
| 426 |
+
temperature_c: request.temperature_c,
|
| 427 |
+
bias_a_per_m: Number(el("bias").value),
|
| 428 |
+
norm,
|
| 429 |
+
encoderUrl: `${modelBase}encoder.onnx`,
|
| 430 |
+
decoderUrl: `${modelBase}decoder.onnx`,
|
| 431 |
+
}, {
|
| 432 |
+
onProgress(progress) {
|
| 433 |
+
el("neural-loss-result").textContent = progress.stage === "loading"
|
| 434 |
+
? "Loading model…" : progress.stage === "decoding"
|
| 435 |
+
? `Calculating ${Math.min(progress.completedSteps, 128)}/128…` : "Finishing…";
|
| 436 |
+
},
|
| 437 |
+
});
|
| 438 |
+
drawBhLoop(values, result.h_waveform_a_per_m);
|
| 439 |
+
el("neural-loss-result").textContent = formatLoss(result.loss_w_per_m3);
|
| 440 |
+
const domain = await domainCheck;
|
| 441 |
const notes = [...(result.warnings || [])];
|
| 442 |
+
if (domain?.error) notes.push("Operating-domain check unavailable; use caution.");
|
| 443 |
+
else if ((typeof domain === "boolean" ? domain : domain?.inDomain) === false) {
|
| 444 |
+
notes.push("Outside the legacy model's measured operating domain; this is an extrapolation.");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
}
|
| 446 |
+
notes.push("Legacy neural model; numerical port parity checked, independent accuracy not certified. Calculated in your browser.");
|
| 447 |
+
el("neural-prediction-note").textContent = notes.join(" ");
|
| 448 |
} catch (error) {
|
| 449 |
+
el("neural-loss-result").textContent = "Unavailable";
|
| 450 |
+
el("neural-prediction-note").textContent = error.message;
|
| 451 |
+
el("bh-loop-section").hidden = true;
|
| 452 |
+
el("bh-loop-path").setAttribute("d", "");
|
| 453 |
} finally {
|
| 454 |
+
state.predictionRunning = false;
|
| 455 |
el("predict-button").disabled = !el("material").options.length;
|
| 456 |
controls.forEach((control) => { control.disabled = false; });
|
| 457 |
}
|
|
|
|
| 464 |
el("material-count").textContent = state.catalog.materials.length;
|
| 465 |
el("dataset-count").textContent = state.catalog.datasets.length;
|
| 466 |
el("model-count").textContent = state.catalog.models.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
renderDatasets();
|
| 468 |
renderModels();
|
| 469 |
updateDutyVisibility();
|
| 470 |
+
syncPredictionMaterials();
|
| 471 |
}
|
| 472 |
|
| 473 |
function configureStaticLinks() {
|
|
|
|
| 512 |
renderModels();
|
| 513 |
});
|
| 514 |
|
|
|
|
|
|
|
| 515 |
[["frequency", "frequency-output"], ["flux", "flux-output"], ["temperature", "temperature-output"]].forEach(([input, output]) => el(input).addEventListener("input", () => {
|
| 516 |
el(output).value = el(input).value;
|
| 517 |
+
resetPrediction();
|
| 518 |
if (input === "flux") updateWaveform();
|
| 519 |
}));
|
| 520 |
+
el("material").addEventListener("change", resetPrediction);
|
| 521 |
+
el("waveform").addEventListener("change", () => { resetPrediction(); updateWaveform(); });
|
| 522 |
el("waveform").addEventListener("change", updateDutyVisibility);
|
| 523 |
el("duty").addEventListener("input", () => {
|
| 524 |
el("duty-output").value = `${Math.round(Number(el("duty").value) * 100)}%`;
|
| 525 |
+
resetPrediction();
|
| 526 |
updateWaveform();
|
| 527 |
});
|
| 528 |
+
el("bias").addEventListener("input", () => { el("bias-output").value = el("bias").value; resetPrediction(); });
|
| 529 |
el("prediction-form").addEventListener("submit", predict);
|
| 530 |
window.addEventListener("resize", () => {
|
| 531 |
if (state.catalog && state.route === "predict") updateWaveform();
|
assets/styles.css
CHANGED
|
@@ -108,10 +108,22 @@ h3 { margin-bottom: 0; font-size: 18px; line-height: 1.3; }
|
|
| 108 |
.waveform-chart { padding: 10px; border: 1px solid var(--line); background: white; }
|
| 109 |
.waveform-chart canvas { width: 100%; height: auto; display: block; }
|
| 110 |
.waveform-summary { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
|
| 111 |
-
.
|
| 112 |
-
.
|
| 113 |
-
.
|
| 114 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
.button { min-height: 44px; border: 1px solid var(--ink); border-radius: 3px; padding: 10px 18px; display: inline-flex; align-items: center; justify-content: center; background: white; color: var(--ink); font-weight: 700; text-decoration: none; cursor: pointer; }
|
| 116 |
.button.primary { background: var(--ink); color: white; }
|
| 117 |
.button:hover, .button:focus-visible { border-color: var(--orange-dark); color: var(--orange-dark); }
|
|
@@ -149,6 +161,9 @@ footer a:hover, footer a:focus-visible { color: var(--orange-dark); }
|
|
| 149 |
.library-actions { align-items: flex-start; }
|
| 150 |
.library-action, .release-state { width: 100%; }
|
| 151 |
.prediction-layout { gap: 32px; padding: 20px; }
|
|
|
|
|
|
|
|
|
|
| 152 |
.learning-list li { grid-template-columns: 30px 1fr; }
|
| 153 |
.learning-list span { grid-column: 2; }
|
| 154 |
footer { flex-direction: column; }
|
|
|
|
| 108 |
.waveform-chart { padding: 10px; border: 1px solid var(--line); background: white; }
|
| 109 |
.waveform-chart canvas { width: 100%; height: auto; display: block; }
|
| 110 |
.waveform-summary { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
|
| 111 |
+
.prediction-results { margin-top: 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
| 112 |
+
.loss-card { min-width: 0; padding: 18px; border: 1px solid var(--line); background: white; }
|
| 113 |
+
.loss-card h2 { margin: 0 0 16px; font-size: 16px; }
|
| 114 |
+
.loss-card strong { display: block; font-size: clamp(25px, 3vw, 34px); line-height: 1.2; overflow-wrap: anywhere; }
|
| 115 |
+
.loss-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
|
| 116 |
+
.loss-card p { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
|
| 117 |
+
.bh-loop-section { margin-top: 28px; }
|
| 118 |
+
.bh-loop-section h2 { margin-bottom: 12px; font-size: 20px; }
|
| 119 |
+
.bh-loop-chart { border: 1px solid var(--line); background: white; }
|
| 120 |
+
.bh-loop-chart svg { display: block; width: 100%; height: auto; }
|
| 121 |
+
.bh-axis { stroke: #b7b7b2; stroke-width: 1.5; }
|
| 122 |
+
#bh-loop-path { stroke: var(--orange-dark); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
|
| 123 |
+
#bh-loop-start { fill: var(--ink); }
|
| 124 |
+
.bh-loop-chart text { fill: var(--muted); font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
|
| 125 |
+
.bh-loop-chart .bh-axis-label { fill: var(--ink); font-size: 15px; font-weight: 650; }
|
| 126 |
+
.bh-loop-note { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
|
| 127 |
.button { min-height: 44px; border: 1px solid var(--ink); border-radius: 3px; padding: 10px 18px; display: inline-flex; align-items: center; justify-content: center; background: white; color: var(--ink); font-weight: 700; text-decoration: none; cursor: pointer; }
|
| 128 |
.button.primary { background: var(--ink); color: white; }
|
| 129 |
.button:hover, .button:focus-visible { border-color: var(--orange-dark); color: var(--orange-dark); }
|
|
|
|
| 161 |
.library-actions { align-items: flex-start; }
|
| 162 |
.library-action, .release-state { width: 100%; }
|
| 163 |
.prediction-layout { gap: 32px; padding: 20px; }
|
| 164 |
+
.prediction-results { grid-template-columns: 1fr; }
|
| 165 |
+
.bh-loop-chart text { font-size: 25px; }
|
| 166 |
+
.bh-loop-chart .bh-axis-label { font-size: 28px; }
|
| 167 |
.learning-list li { grid-template-columns: 30px 1fr; }
|
| 168 |
.learning-list span { grid-column: 2; }
|
| 169 |
footer { flex-direction: column; }
|
index.html
CHANGED
|
@@ -109,29 +109,57 @@
|
|
| 109 |
<section class="view module-view" data-view="predict" tabindex="-1" hidden>
|
| 110 |
<a class="back-link" href="#/"><span aria-hidden="true">←</span> All modules</a>
|
| 111 |
<header class="module-header">
|
| 112 |
-
<div><p class="eyebrow">Predict</p><h1>
|
| 113 |
-
<p id="predict-description">
|
| 114 |
</header>
|
| 115 |
<div class="prediction-layout">
|
| 116 |
<form id="prediction-form" class="prediction-form">
|
| 117 |
-
<label>Prediction model<select id="prediction-model" name="model"><option value="igse-v1">iGSE baseline</option></select></label>
|
| 118 |
<label>Material<select id="material" name="material" required></select></label>
|
| 119 |
<label>Waveform<select id="waveform" name="waveform"><option value="sine">Sinusoidal</option><option value="triangle">Triangular</option></select></label>
|
| 120 |
<label id="duty-control" hidden>Rising duty ratio <span><output id="duty-output">50%</output></span><input id="duty" type="range" min="0.01" max="0.99" value="0.50" step="0.01" aria-describedby="duty-help"><small id="duty-help">Fraction of one cycle used to ramp from −Bpk to +Bpk.</small></label>
|
| 121 |
<label>Frequency <span><output id="frequency-output">100</output> kHz</span><input id="frequency" type="range" min="10" max="1000" value="100" step="5"></label>
|
| 122 |
<label>Peak flux density <span><output id="flux-output">100</output> mT</span><input id="flux" type="range" min="5" max="400" value="100" step="5"></label>
|
| 123 |
<label>Temperature <span><output id="temperature-output">25</output> °C</span><input id="temperature" type="range" min="0" max="120" value="25" step="5"></label>
|
| 124 |
-
<label id="bias-control"
|
| 125 |
-
<button id="predict-button" class="button primary" type="submit">Calculate
|
| 126 |
</form>
|
| 127 |
<div class="prediction-output" aria-live="polite">
|
| 128 |
<div class="waveform-chart"><canvas id="waveform-chart" width="760" height="260" aria-label="Input flux-density waveform">Flux-density waveform preview.</canvas></div>
|
| 129 |
<p id="waveform-summary" class="waveform-summary">Sinusoidal waveform, 100 mT peak.</p>
|
| 130 |
-
<div class="
|
| 131 |
-
<
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
</div>
|
| 136 |
</div>
|
| 137 |
</section>
|
|
|
|
| 109 |
<section class="view module-view" data-view="predict" tabindex="-1" hidden>
|
| 110 |
<a class="back-link" href="#/"><span aria-hidden="true">←</span> All modules</a>
|
| 111 |
<header class="module-header">
|
| 112 |
+
<div><p class="eyebrow">Predict</p><h1>Compare core-loss predictions</h1></div>
|
| 113 |
+
<p id="predict-description">Enter one steady-state operating point to see the iGSE baseline and MagNet Transformer estimates together, plus the Transformer's predicted B–H loop. Model limitations and operating-range warnings appear with each result.</p>
|
| 114 |
</header>
|
| 115 |
<div class="prediction-layout">
|
| 116 |
<form id="prediction-form" class="prediction-form">
|
|
|
|
| 117 |
<label>Material<select id="material" name="material" required></select></label>
|
| 118 |
<label>Waveform<select id="waveform" name="waveform"><option value="sine">Sinusoidal</option><option value="triangle">Triangular</option></select></label>
|
| 119 |
<label id="duty-control" hidden>Rising duty ratio <span><output id="duty-output">50%</output></span><input id="duty" type="range" min="0.01" max="0.99" value="0.50" step="0.01" aria-describedby="duty-help"><small id="duty-help">Fraction of one cycle used to ramp from −Bpk to +Bpk.</small></label>
|
| 120 |
<label>Frequency <span><output id="frequency-output">100</output> kHz</span><input id="frequency" type="range" min="10" max="1000" value="100" step="5"></label>
|
| 121 |
<label>Peak flux density <span><output id="flux-output">100</output> mT</span><input id="flux" type="range" min="5" max="400" value="100" step="5"></label>
|
| 122 |
<label>Temperature <span><output id="temperature-output">25</output> °C</span><input id="temperature" type="range" min="0" max="120" value="25" step="5"></label>
|
| 123 |
+
<label id="bias-control">DC bias field <span><output id="bias-output">0</output> A/m</span><input id="bias" type="range" min="0" max="75" value="0" step="5"><small>Used by the Transformer; iGSE does not model DC bias or temperature.</small></label>
|
| 124 |
+
<button id="predict-button" class="button primary" type="submit">Calculate both models</button>
|
| 125 |
</form>
|
| 126 |
<div class="prediction-output" aria-live="polite">
|
| 127 |
<div class="waveform-chart"><canvas id="waveform-chart" width="760" height="260" aria-label="Input flux-density waveform">Flux-density waveform preview.</canvas></div>
|
| 128 |
<p id="waveform-summary" class="waveform-summary">Sinusoidal waveform, 100 mT peak.</p>
|
| 129 |
+
<div class="prediction-results" aria-label="Predicted volumetric loss density">
|
| 130 |
+
<article class="loss-card">
|
| 131 |
+
<h2>iGSE baseline</h2>
|
| 132 |
+
<strong id="igse-loss-result">—</strong>
|
| 133 |
+
<small>Predicted volumetric loss</small>
|
| 134 |
+
<p id="igse-prediction-note">Uses waveform, frequency, and material; ignores temperature and DC bias.</p>
|
| 135 |
+
</article>
|
| 136 |
+
<article class="loss-card">
|
| 137 |
+
<h2>MagNet Transformer</h2>
|
| 138 |
+
<strong id="neural-loss-result">—</strong>
|
| 139 |
+
<small>Predicted volumetric loss</small>
|
| 140 |
+
<p id="neural-prediction-note">Experimental legacy model. First run downloads the browser runtime and material model.</p>
|
| 141 |
+
</article>
|
| 142 |
</div>
|
| 143 |
+
<section id="bh-loop-section" class="bh-loop-section" aria-labelledby="bh-loop-heading" hidden>
|
| 144 |
+
<h2 id="bh-loop-heading">Predicted B–H loop</h2>
|
| 145 |
+
<div class="bh-loop-chart">
|
| 146 |
+
<svg id="bh-loop-svg" viewBox="0 0 760 360" role="img" aria-labelledby="bh-loop-title bh-loop-description">
|
| 147 |
+
<title id="bh-loop-title">Transformer-predicted B–H loop</title>
|
| 148 |
+
<desc id="bh-loop-description">Predicted field strength H on the horizontal axis and input flux density B on the vertical axis, in sample order.</desc>
|
| 149 |
+
<line class="bh-axis" x1="74" y1="170" x2="728" y2="170"></line>
|
| 150 |
+
<line class="bh-axis" x1="401" y1="40" x2="401" y2="300"></line>
|
| 151 |
+
<path id="bh-loop-path" d="" fill="none"></path>
|
| 152 |
+
<circle id="bh-loop-start" r="4" cx="0" cy="0"></circle>
|
| 153 |
+
<text id="bh-h-negative" x="74" y="326" text-anchor="start"></text>
|
| 154 |
+
<text id="bh-h-positive" x="728" y="326" text-anchor="end"></text>
|
| 155 |
+
<text id="bh-b-positive" x="76" y="34" text-anchor="start"></text>
|
| 156 |
+
<text id="bh-b-negative" x="76" y="298" text-anchor="start"></text>
|
| 157 |
+
<text class="bh-axis-label" x="401" y="348" text-anchor="middle">H (A/m)</text>
|
| 158 |
+
<text class="bh-axis-label" x="30" y="170" transform="rotate(-90 30 170)" text-anchor="middle">B (mT)</text>
|
| 159 |
+
</svg>
|
| 160 |
+
</div>
|
| 161 |
+
<p class="bh-loop-note">128 paired samples, in cycle order. The trace is not artificially closed; Transformer loss follows the original 127-interval H dB integration.</p>
|
| 162 |
+
</section>
|
| 163 |
</div>
|
| 164 |
</div>
|
| 165 |
</section>
|