Spaces:
Running
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): benchmarks/pinn/run_bench.py
Deleted (gone from the repo + Dockerfile COPY set): (none)
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- benchmarks/pinn/run_bench.py +129 -24
benchmarks/pinn/run_bench.py
CHANGED
|
@@ -354,11 +354,68 @@ def _modulus_stub(problem: str) -> Dict[str, Any]:
|
|
| 354 |
"train; report rel-L2 vs the same exact closed form.")}
|
| 355 |
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
def assemble(out_path: str) -> Dict[str, Any]:
|
| 358 |
szl = _load_partial("szl.json")
|
| 359 |
dx_pois = _load_partial("deepxde_poisson.json")
|
| 360 |
dx_burg = _load_partial("deepxde_burgers.json")
|
| 361 |
dx_duff = _load_partial("deepxde_duffing.json")
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
problems = [
|
| 364 |
{
|
|
@@ -374,7 +431,7 @@ def assemble(out_path: str) -> Dict[str, Any]:
|
|
| 374 |
"metric": "rel_l2_vs_exact",
|
| 375 |
"arms": [szl["poisson"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 376 |
_dx_summary(dx_pois, "rel_l2_vs_exact", "poisson"),
|
| 377 |
-
|
| 378 |
},
|
| 379 |
{
|
| 380 |
"id": "steady_burgers_shock",
|
|
@@ -389,7 +446,7 @@ def assemble(out_path: str) -> Dict[str, Any]:
|
|
| 389 |
"metric": "rel_l2_vs_exact",
|
| 390 |
"arms": [szl["burgers"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 391 |
_dx_summary(dx_burg, "rel_l2_vs_exact", "burgers"),
|
| 392 |
-
|
| 393 |
},
|
| 394 |
{
|
| 395 |
"id": "inverse_duffing",
|
|
@@ -403,17 +460,78 @@ def assemble(out_path: str) -> Dict[str, Any]:
|
|
| 403 |
"metric": "abs_err",
|
| 404 |
"arms": [szl["duffing"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 405 |
_dx_summary(dx_duff, "abs_err", "duffing"),
|
| 406 |
-
|
| 407 |
},
|
| 408 |
]
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
result = {
|
| 411 |
"service": "a11oy.pinn.bench",
|
| 412 |
"title": "SZL Governed spectral collocation vs DeepXDE (neural PINN) vs Modulus/PhysicsNeMo",
|
| 413 |
-
"overall_label":
|
| 414 |
"ran_at": _now(),
|
| 415 |
"hardware": {"cpus": 2, "ram_gib": 15, "gpu": None, "torch_threads": 2,
|
| 416 |
-
"note": "Replit sandbox — CPU-only, no CUDA GPU"
|
|
|
|
|
|
|
|
|
|
| 417 |
"frameworks": {
|
| 418 |
"szl": {"method_class": ("classical spectral collocation least-squares (+ Newton "
|
| 419 |
"for nonlinear BVP) — NOT a neural PINN"),
|
|
@@ -427,20 +545,10 @@ def assemble(out_path: str) -> Dict[str, Any]:
|
|
| 427 |
"any shipped module. The /pinn/bench endpoint only reads this "
|
| 428 |
"committed artifact."),
|
| 429 |
"versions": (dx_pois or dx_burg or dx_duff or {}).get("framework_versions")},
|
| 430 |
-
"modulus_physicsnemo":
|
| 431 |
-
"status": "NOT-RUN", "license": "Apache-2.0",
|
| 432 |
-
"note": "NVIDIA Modulus was renamed PhysicsNeMo (same framework)."},
|
| 433 |
},
|
| 434 |
"problems": problems,
|
| 435 |
-
"interpretation":
|
| 436 |
-
"poisson": ("SZL is ~machine precision BY CONSTRUCTION (solution in basis, disclosed); "
|
| 437 |
-
"DeepXDE reaches a solid neural-PINN accuracy without knowing the basis."),
|
| 438 |
-
"burgers": ("honest nonlinear head-to-head: SZL's new Newton-spectral solver and the "
|
| 439 |
-
"neural PINN both target the exact tanh shock; compare rel-L2 and wall time. "
|
| 440 |
-
"The DeepXDE arm is a STANDARD, non-shock-adapted PINN \u2014 shock-adaptation "
|
| 441 |
-
"(RAR / curriculum / hard-BC) is NOT-TESTED and would likely narrow the gap."),
|
| 442 |
-
"duffing": ("both recover α from the same data; compare |α̂-1| and cost."),
|
| 443 |
-
},
|
| 444 |
"scope_limits": (
|
| 445 |
"This is a LOW-DIMENSIONAL (1D), SMOOTH, CPU-ONLY suite with KNOWN good bases. "
|
| 446 |
"It structurally favors spectral methods. The regimes neural PINNs are designed "
|
|
@@ -448,18 +556,15 @@ def assemble(out_path: str) -> Dict[str, Any]:
|
|
| 448 |
"geometry, and problems with NO known good basis — are NOT exercised here and are "
|
| 449 |
"reported as NOT-TESTED, not as a neural-arm loss. Do not read SZL wins on this "
|
| 450 |
"suite as universal superiority."),
|
| 451 |
-
"honesty":
|
| 452 |
-
"All rel-L2 and wall-time numbers are MEASURED on this box against the exact closed "
|
| 453 |
-
"form; ≥3 seeds are reported as median[min,max] for the neural arm. No joules are "
|
| 454 |
-
"reported (NOT-MEASURED: no power meter). Poisson's in-basis advantage is disclosed. "
|
| 455 |
-
"DeepXDE (LGPL) is benchmark-only and never shipped. Modulus/PhysicsNeMo is NOT-RUN "
|
| 456 |
-
"with a reproduce spec (no GPU)."),
|
| 457 |
"doctrine": "Doctrine v11 LOCKED — no fabricated numbers; MEASURED/MODELED/NOT-RUN/NOT-MEASURED/NOT-TESTED labels only.",
|
| 458 |
"reproduce": {
|
| 459 |
"szl": "python benchmarks/pinn/run_bench.py --arm szl",
|
| 460 |
"deepxde": "python benchmarks/pinn/run_bench.py --arm deepxde --problem {poisson|burgers|duffing} --seeds 3",
|
| 461 |
"assemble": "python benchmarks/pinn/run_bench.py --assemble --out benchmarks/pinn/results.json",
|
| 462 |
-
"modulus": "
|
|
|
|
|
|
|
| 463 |
},
|
| 464 |
}
|
| 465 |
outp = Path(out_path)
|
|
|
|
| 354 |
"train; report rel-L2 vs the same exact closed form.")}
|
| 355 |
|
| 356 |
|
| 357 |
+
# PhysicsNeMo (NVIDIA Modulus) neural arm — produced by run_modulus.py on a CUDA GPU
|
| 358 |
+
# and written to modulus_partial/. These configs mirror the DeepXDE arms EXACTLY (same
|
| 359 |
+
# nets / optimizer budgets / exact solutions) so the two neural arms are comparable.
|
| 360 |
+
_MODULUS_DIR = HERE.parent / "modulus_partial"
|
| 361 |
+
_MODULUS_CONFIG = {
|
| 362 |
+
"poisson": {"net": "FNN [1,32,32,32,1] tanh (PhysicsNeMo FullyConnected, num_layers=3, layer_size=32)",
|
| 363 |
+
"optimizer": "Adam 8000 iters (lr=1e-3) + L-BFGS (max_iter=2000, strong_wolfe)",
|
| 364 |
+
"num_domain": 64, "num_boundary": 2, "num_eval": 400, "loss_weights": None},
|
| 365 |
+
"burgers": {"net": "FNN [1,40,40,40,1] tanh (PhysicsNeMo FullyConnected, num_layers=3, layer_size=40)",
|
| 366 |
+
"optimizer": "Adam 8000 iters (lr=1e-3) + L-BFGS (max_iter=2000, strong_wolfe)",
|
| 367 |
+
"num_domain": 200, "num_boundary": 2, "num_eval": 400, "loss_weights": [1.0, 100.0]},
|
| 368 |
+
"duffing": {"net": "FNN [1,40,40,40,1] tanh (PhysicsNeMo FullyConnected, num_layers=3, layer_size=40)",
|
| 369 |
+
"optimizer": "Adam 10000 iters (lr=1e-3) + L-BFGS (max_iter=3000, strong_wolfe)",
|
| 370 |
+
"num_domain": 200, "num_boundary": 2, "anchors": "120 observation points; alpha init=2.0"},
|
| 371 |
+
}
|
| 372 |
+
_MODULUS_CAVEAT = {
|
| 373 |
+
"burgers": ("STANDARD, non-shock-adapted PINN config IDENTICAL to the DeepXDE arm; "
|
| 374 |
+
"shock-adaptation (RAR / curriculum / hard-BC) is NOT-TESTED \u2014 the large "
|
| 375 |
+
"burgers error reflects the vanilla config, NOT a neural-PINN ceiling."),
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def _load_modulus_partial(problem: str) -> Optional[Dict[str, Any]]:
|
| 380 |
+
fp = _MODULUS_DIR / ("modulus_%s.json" % problem)
|
| 381 |
+
if fp.is_file():
|
| 382 |
+
with fp.open("r", encoding="utf-8") as fh:
|
| 383 |
+
return json.load(fh)
|
| 384 |
+
return None
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
def _modulus_summary(part: Optional[Dict[str, Any]], metric: str, problem: str) -> Dict[str, Any]:
|
| 388 |
+
if not part or not part.get("seeds"):
|
| 389 |
+
return _modulus_stub(problem)
|
| 390 |
+
vals = [row[metric] for row in part["seeds"]]
|
| 391 |
+
walls = [row["wall_s"] for row in part["seeds"]]
|
| 392 |
+
out = {"framework": "modulus_physicsnemo", "method_class": part.get("method_class"),
|
| 393 |
+
"license": part.get("license"), "seeds_run": len(vals),
|
| 394 |
+
metric: _stats(vals), "wall_s": _stats(walls),
|
| 395 |
+
"trainable_params": part["seeds"][0].get("trainable_params"),
|
| 396 |
+
"config": _MODULUS_CONFIG.get(problem),
|
| 397 |
+
"framework_versions": part.get("framework_versions"),
|
| 398 |
+
"device": part.get("device"),
|
| 399 |
+
"label": "MEASURED", "energy": part.get("energy")}
|
| 400 |
+
if problem in _MODULUS_CAVEAT:
|
| 401 |
+
out["caveat"] = _MODULUS_CAVEAT[problem]
|
| 402 |
+
if metric == "abs_err":
|
| 403 |
+
out["label"] = "MEASURED (fit error vs synthetic ground truth; not measured physics)"
|
| 404 |
+
out["alpha_estimate_median"] = float(statistics.median(
|
| 405 |
+
[row["alpha_estimate"] for row in part["seeds"]]))
|
| 406 |
+
out["alpha_truth"] = ALPHA_TRUTH
|
| 407 |
+
out["note"] = part.get("note")
|
| 408 |
+
return out
|
| 409 |
+
|
| 410 |
+
|
| 411 |
def assemble(out_path: str) -> Dict[str, Any]:
|
| 412 |
szl = _load_partial("szl.json")
|
| 413 |
dx_pois = _load_partial("deepxde_poisson.json")
|
| 414 |
dx_burg = _load_partial("deepxde_burgers.json")
|
| 415 |
dx_duff = _load_partial("deepxde_duffing.json")
|
| 416 |
+
mod_pois = _load_modulus_partial("poisson")
|
| 417 |
+
mod_burg = _load_modulus_partial("burgers")
|
| 418 |
+
mod_duff = _load_modulus_partial("duffing")
|
| 419 |
|
| 420 |
problems = [
|
| 421 |
{
|
|
|
|
| 431 |
"metric": "rel_l2_vs_exact",
|
| 432 |
"arms": [szl["poisson"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 433 |
_dx_summary(dx_pois, "rel_l2_vs_exact", "poisson"),
|
| 434 |
+
_modulus_summary(mod_pois, "rel_l2_vs_exact", "poisson")],
|
| 435 |
},
|
| 436 |
{
|
| 437 |
"id": "steady_burgers_shock",
|
|
|
|
| 446 |
"metric": "rel_l2_vs_exact",
|
| 447 |
"arms": [szl["burgers"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 448 |
_dx_summary(dx_burg, "rel_l2_vs_exact", "burgers"),
|
| 449 |
+
_modulus_summary(mod_burg, "rel_l2_vs_exact", "burgers")],
|
| 450 |
},
|
| 451 |
{
|
| 452 |
"id": "inverse_duffing",
|
|
|
|
| 460 |
"metric": "abs_err",
|
| 461 |
"arms": [szl["duffing"] if szl else {"framework": "szl", "label": "NOT-RUN"},
|
| 462 |
_dx_summary(dx_duff, "abs_err", "duffing"),
|
| 463 |
+
_modulus_summary(mod_duff, "abs_err", "duffing")],
|
| 464 |
},
|
| 465 |
]
|
| 466 |
|
| 467 |
+
mod_present = bool(mod_pois and mod_burg and mod_duff)
|
| 468 |
+
mod_vers = (mod_pois or mod_burg or mod_duff or {}).get("framework_versions")
|
| 469 |
+
if mod_present:
|
| 470 |
+
overall_label = ("MEASURED 3-way (SZL classical spectral on CPU; DeepXDE and NVIDIA "
|
| 471 |
+
"Modulus/PhysicsNeMo neural PINNs \u2014 both neural arms GPU-measured, "
|
| 472 |
+
"see each arm's framework_versions/device)")
|
| 473 |
+
modulus_fw = {"method_class": ("neural PINN (NVIDIA; PhysicsNeMo FullyConnected core model "
|
| 474 |
+
"+ manual PDE-residual loop, Adam + L-BFGS)"),
|
| 475 |
+
"status": "MEASURED", "deps": ["nvidia-physicsnemo", "pytorch-cuda"],
|
| 476 |
+
"license": "Apache-2.0", "shipped": False,
|
| 477 |
+
"usage": ("benchmark-only dev dependency; NEVER imported by serve.py or any "
|
| 478 |
+
"shipped module. The /pinn/bench endpoint only reads this artifact."),
|
| 479 |
+
"versions": mod_vers,
|
| 480 |
+
"note": ("NVIDIA Modulus was renamed PhysicsNeMo (same framework). Uses the "
|
| 481 |
+
"PhysicsNeMo core model layer (physicsnemo.models.mlp.FullyConnected), "
|
| 482 |
+
"NOT the PhysicsNeMo-Sym PDE DSL.")}
|
| 483 |
+
interp = {
|
| 484 |
+
"poisson": ("SZL is ~machine precision BY CONSTRUCTION (solution in basis, disclosed); "
|
| 485 |
+
"both neural PINNs (DeepXDE and PhysicsNeMo) reach solid neural accuracy "
|
| 486 |
+
"without knowing the basis."),
|
| 487 |
+
"burgers": ("honest nonlinear head-to-head: SZL's Newton-spectral solver targets the "
|
| 488 |
+
"exact tanh shock. BOTH neural arms are STANDARD, non-shock-adapted PINNs "
|
| 489 |
+
"and land at ~0.5\u20130.7 rel-L2 (vanilla config, not a ceiling); "
|
| 490 |
+
"shock-adaptation (RAR / curriculum / hard-BC) is NOT-TESTED for either."),
|
| 491 |
+
"duffing": ("all three recover \u03b1 from the SAME synthetic data; compare "
|
| 492 |
+
"|\u03b1\u0302-1| and cost. PhysicsNeMo's L-BFGS fit is typically the tightest."),
|
| 493 |
+
}
|
| 494 |
+
honesty = (
|
| 495 |
+
"All rel-L2 / |\u03b1\u0302-1| / wall-time numbers are MEASURED against the exact closed "
|
| 496 |
+
"form or synthetic ground truth; the two neural arms report 3 seeds as median[min,max]. "
|
| 497 |
+
"No joules (NOT-MEASURED: no power meter). Poisson's in-basis advantage is disclosed. "
|
| 498 |
+
"DeepXDE (LGPL) and NVIDIA PhysicsNeMo (Apache-2.0) are BOTH benchmark-only dev "
|
| 499 |
+
"dependencies, never imported by shipped code. The PhysicsNeMo arm uses the core "
|
| 500 |
+
"FullyConnected model (not PhysicsNeMo-Sym), mirroring the DeepXDE net/optimizer budget "
|
| 501 |
+
"and exact solutions. The two neural arms ran on the SAME GPU but may differ in CUDA "
|
| 502 |
+
"stack (see each arm's framework_versions) \u2014 accuracy is apples-to-apples, wall_s "
|
| 503 |
+
"only broadly comparable.")
|
| 504 |
+
else:
|
| 505 |
+
overall_label = "MEASURED (SZL + DeepXDE on this CPU box); Modulus NOT-RUN"
|
| 506 |
+
modulus_fw = {"method_class": "neural PINN (NVIDIA)", "status": "NOT-RUN",
|
| 507 |
+
"license": "Apache-2.0",
|
| 508 |
+
"note": "NVIDIA Modulus was renamed PhysicsNeMo (same framework)."}
|
| 509 |
+
interp = {
|
| 510 |
+
"poisson": ("SZL is ~machine precision BY CONSTRUCTION (solution in basis, disclosed); "
|
| 511 |
+
"DeepXDE reaches a solid neural-PINN accuracy without knowing the basis."),
|
| 512 |
+
"burgers": ("honest nonlinear head-to-head: SZL's new Newton-spectral solver and the "
|
| 513 |
+
"neural PINN both target the exact tanh shock; compare rel-L2 and wall time. "
|
| 514 |
+
"The DeepXDE arm is a STANDARD, non-shock-adapted PINN \u2014 shock-adaptation "
|
| 515 |
+
"(RAR / curriculum / hard-BC) is NOT-TESTED and would likely narrow the gap."),
|
| 516 |
+
"duffing": ("both recover \u03b1 from the same data; compare |\u03b1\u0302-1| and cost."),
|
| 517 |
+
}
|
| 518 |
+
honesty = (
|
| 519 |
+
"All rel-L2 and wall-time numbers are MEASURED on this box against the exact closed "
|
| 520 |
+
"form; \u22653 seeds are reported as median[min,max] for the neural arm. No joules are "
|
| 521 |
+
"reported (NOT-MEASURED: no power meter). Poisson's in-basis advantage is disclosed. "
|
| 522 |
+
"DeepXDE (LGPL) is benchmark-only and never shipped. Modulus/PhysicsNeMo is NOT-RUN "
|
| 523 |
+
"with a reproduce spec (no GPU).")
|
| 524 |
+
|
| 525 |
result = {
|
| 526 |
"service": "a11oy.pinn.bench",
|
| 527 |
"title": "SZL Governed spectral collocation vs DeepXDE (neural PINN) vs Modulus/PhysicsNeMo",
|
| 528 |
+
"overall_label": overall_label,
|
| 529 |
"ran_at": _now(),
|
| 530 |
"hardware": {"cpus": 2, "ram_gib": 15, "gpu": None, "torch_threads": 2,
|
| 531 |
+
"note": ("Replit sandbox — CPU-only, no CUDA GPU. NOTE: the DeepXDE and "
|
| 532 |
+
"PhysicsNeMo neural partials, when present, were MEASURED on a CUDA "
|
| 533 |
+
"GPU host (see each arm's framework_versions/device), not on this "
|
| 534 |
+
"assemble host.")},
|
| 535 |
"frameworks": {
|
| 536 |
"szl": {"method_class": ("classical spectral collocation least-squares (+ Newton "
|
| 537 |
"for nonlinear BVP) — NOT a neural PINN"),
|
|
|
|
| 545 |
"any shipped module. The /pinn/bench endpoint only reads this "
|
| 546 |
"committed artifact."),
|
| 547 |
"versions": (dx_pois or dx_burg or dx_duff or {}).get("framework_versions")},
|
| 548 |
+
"modulus_physicsnemo": modulus_fw,
|
|
|
|
|
|
|
| 549 |
},
|
| 550 |
"problems": problems,
|
| 551 |
+
"interpretation": interp,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
"scope_limits": (
|
| 553 |
"This is a LOW-DIMENSIONAL (1D), SMOOTH, CPU-ONLY suite with KNOWN good bases. "
|
| 554 |
"It structurally favors spectral methods. The regimes neural PINNs are designed "
|
|
|
|
| 556 |
"geometry, and problems with NO known good basis — are NOT exercised here and are "
|
| 557 |
"reported as NOT-TESTED, not as a neural-arm loss. Do not read SZL wins on this "
|
| 558 |
"suite as universal superiority."),
|
| 559 |
+
"honesty": honesty,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
"doctrine": "Doctrine v11 LOCKED — no fabricated numbers; MEASURED/MODELED/NOT-RUN/NOT-MEASURED/NOT-TESTED labels only.",
|
| 561 |
"reproduce": {
|
| 562 |
"szl": "python benchmarks/pinn/run_bench.py --arm szl",
|
| 563 |
"deepxde": "python benchmarks/pinn/run_bench.py --arm deepxde --problem {poisson|burgers|duffing} --seeds 3",
|
| 564 |
"assemble": "python benchmarks/pinn/run_bench.py --assemble --out benchmarks/pinn/results.json",
|
| 565 |
+
"modulus": ("python benchmarks/pinn/run_modulus.py --problem {poisson|burgers|duffing} "
|
| 566 |
+
"--seeds 3 --out benchmarks/pinn/modulus_partial (CUDA GPU host with "
|
| 567 |
+
"`pip install nvidia-physicsnemo`); then --assemble picks up modulus_partial/"),
|
| 568 |
},
|
| 569 |
}
|
| 570 |
outp = Path(out_path)
|