{"slug": "show-hn-physics-written-into-the-architecture-learned-hamiltonian", "title": "Show HN: Physics written into the architecture (learned Hamiltonian)", "summary": "A Show HN project called awareliquid_physics released a physics-informed machine learning model that writes a learned Hamiltonian advanced by a symplectic integrator directly into its architecture, conserving energy by construction with bounded O(dt²) drift. In benchmarks, the hard-constraint Hamiltonian head cut 150-step spring energy drift to 0.012 versus 0.036 for an MLP-field Euler control (3.0×) and 100-step orbit energy drift to 6.2 versus 37.8 (6.0×), with orbit rollout MSE of 2.8e-3 versus 6.6e-2 (23.8×). The coupling experiment on a family of oscillators with hidden per-trajectory stiffness showed liquid_ham (liquid core plus Hamiltonian) reaching 4.12 rollout MSE versus 7.24 for a GRU control, while static_ham drifted least at 0.18, which the author reports as a real adaptation/conservation trade-off.", "body_md": "A complete model with **physics computation written into the architecture** — not\nbolted on as a loss term.\n\nThe core idea: a continuous-time **liquid (LTC) recurrence** is the substrate, and\nphysical structure (a learned Hamiltonian advanced by a **symplectic integrator**)\nis a hard architectural constraint on top of it. Energy is conserved *by\nconstruction* — bounded O(dt²) drift, exactly time-reversible — for whatever\nenergy function the network learns. This is the hard-constraint route to\nphysics-informed ML (Hamiltonian NNs, Greydanus 2019), chosen over soft\nPDE-residual losses after an adversarial review of the PINN literature.\n\n```\nobserved trajectory prefix\n        │\n        ▼\n  LiquidCore (LTC)          multi-timescale gated linear recurrence,\n        │                   trained via Blelloch parallel scan (O(log T))\n        ▼\n  context vector            system identification: infers per-trajectory\n        │                   hidden parameters (e.g. a spring's stiffness)\n        ▼\n  HamiltonianHead           separable H(q,p) = T(p) + V(q | context)\n        │\n        ▼\n  symplectic rollout        velocity-Verlet; energy conserved by construction\n```\n\n- **`awareliquid_physics/liquid_core.py`** — the LTC \"liquid\" recurrence: each\ntimescale is a leaky integrator with a learned time constant; scales are blended\nby an input-dependent gate. Runs in O(log T) depth via`parallel_scan.py` .\n- **`awareliquid_physics/hamiltonian.py`** —` HamiltonianHead` (hard-constraint,\nsymplectic) and`MLPFieldHead` (the honest unstructured control: plain Euler,\nno conservation).\n- **`awareliquid_physics/model.py`** —` LiquidHamiltonianModel` , the integration\nthe project is about: liquid core reads the prefix → conditions the Hamiltonian's\npotential → symplectic rollout predicts the future. One fixed learned potential\ncannot fit a*family* of systems; the liquid context makes the same model adapt\nits energy landscape per trajectory.\n- **`awareliquid_physics/physics_ops.py`** — a zero-parameter, deterministic\nNewtonian operator layer (symplectic Euler integration, N-body gravity,\ncollisions, energy/momentum diagnostics). The ground-truth engine the learned\nmodels are benchmarked against:*compute, don't memorise* .\n\n`benchmarks/physics_rollout_eval.py` — free-standing head, matched 1-step fit\n(~5e-6 loss both), scored on physics metrics only:\n\n| system | metric | Hamiltonian (hard-constraint) | MLP-field control | advantage | \n|---|---|---|---|---|\n| spring | 150-step energy drift | **0.012** | 0.036 | 3.0× | \n| orbit | 100-step energy drift | **6.2** | 37.8 | 6.0× | \n| orbit | 100-step rollout MSE | **2.8e-3** | 6.6e-2 | 23.8× | \n\n`benchmarks/liquid_physics_eval.py` — the coupling experiment: a *family* of\noscillators with hidden per-trajectory stiffness, prefix → 100-step rollout:\n\n| model | rollout MSE | final energy drift | params | \n|---|---|---|---|\n| **liquid_ham** (liquid + Hamiltonian) | **4.12** | 0.70 | 8.7k | \n| static_ham (Hamiltonian, no context) | 4.41 | **0.18** | 5.0k | \n| gru_seq (unstructured control) | 7.24 | 2.96 | 10.0k | \n\nHonest reading: the physics structure is what buys long-horizon stability over the GRU baseline (2.9× lower rollout error, 4× lower drift); the liquid context buys adaptation to the hidden parameter (better rollout MSE than the static head). The static head drifts least because its one fixed potential is more rigid — the adaptation/conservation trade-off is real and reported as measured.\n\nContinuous-state trajectory prediction, validated on **physics metrics** (k-step\nrollout MSE, energy drift) — never perplexity. This is not a language model and\nmakes no hallucination claim.\n\n```\npip install -e \".[dev]\"\npython -m pytest tests/ -q                          # 13 tests\n\n# free-standing head: symplectic vs Euler control\npython benchmarks/physics_rollout_eval.py --system spring\npython benchmarks/physics_rollout_eval.py --system orbit\n\n# the coupling experiment: liquid_ham vs static_ham vs gru_seq\npython benchmarks/liquid_physics_eval.py --train_steps 500\n```\n\nAll benchmarks are CPU-runnable.\n\n- Richer system families (2-body orbits, contacts/collisions via `physics_ops` )\nfor the coupling experiment\n- Non-separable Hamiltonians (magnetic / velocity-dependent forces)\n- Scale the liquid substrate; longer-horizon rollouts\n- Close the adaptation/conservation gap (context-conditioned kinetic term, drift-penalised training)\n\n*Note: this repository previously hosted a Kaggle competition entry (Nemotron\nreasoning challenge); that content lives in the git history before v0.1.0.*", "url": "https://wpnews.pro/news/show-hn-physics-written-into-the-architecture-learned-hamiltonian", "canonical_source": "https://github.com/AwareLiquid/AwareLiquid-Physic", "published_at": "2026-10-09 10:30:29+00:00", "updated_at": "2026-10-09 10:54:09.643342+00:00", "lang": "en", "topics": ["machine-learning", "ai-research", "neural-networks", "ai-tools"], "entities": ["awareliquid_physics", "LiquidHamiltonianModel", "LiquidCore", "HamiltonianHead", "MLPFieldHead", "Greydanus"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/show-hn-physics-written-into-the-architecture-learned-hamiltonian", "markdown": "https://wpnews.pro/news/show-hn-physics-written-into-the-architecture-learned-hamiltonian.md", "text": "https://wpnews.pro/news/show-hn-physics-written-into-the-architecture-learned-hamiltonian.txt", "jsonld": "https://wpnews.pro/news/show-hn-physics-written-into-the-architecture-learned-hamiltonian.jsonld"}}