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|
| 2 |
+
|
| 3 |
+
> **A neural layer class whose invariants hold *exactly, per layer, to machine
|
| 4 |
+
> precision* — the discrete, learnable form of GENERIC dynamics, built for
|
| 5 |
+
> physical AI: models that must roll out learned dynamics for long horizons
|
| 6 |
+
> without their physics unraveling.**
|
| 7 |
+
|
| 8 |
+
Continuous-time metriplectic networks learn vector fields whose invariants
|
| 9 |
+
hold in the continuous limit — and any integrator used in deployment
|
| 10 |
+
introduces drift. **MetriplecticLayer** makes the invariant *algebraic*: one
|
| 11 |
+
forward pass is one step of a metriplectic flow, and each channel's invariant
|
| 12 |
+
holds for every parameter value, at every step, after any amount of training,
|
| 13 |
+
because it is a property of the map itself.
|
| 14 |
+
|
| 15 |
+
**Paper:** [manuscript.pdf](manuscript.pdf) (Nature Machine Intelligence
|
| 16 |
+
format). Every number in the paper reads from a committed JSON under
|
| 17 |
+
`results/` — never hand-typed. Figures and `results/summary.tex` (the macro
|
| 18 |
+
file the manuscript is typeset from) regenerate with one script.
|
| 19 |
+
|
| 20 |
+
**Live:** project site on GitHub Pages
|
| 21 |
+
(https://sehajr-singhs.github.io/metriplex/); the committed
|
| 22 |
+
results on Kaggle
|
| 23 |
+
(https://www.kaggle.com/datasets/sehajrsingh/metriplectic-layers-results);
|
| 24 |
+
trained checkpoints (safetensors + model cards + zero-install `usage.py`)
|
| 25 |
+
and the papers on a Hugging Face model repo
|
| 26 |
+
(https://huggingface.co/Sejibeji/Metriplex); a mirror of the site
|
| 27 |
+
on Hugging Face Spaces
|
| 28 |
+
(https://sejibeji-metriplex.static.hf.space).
|
| 29 |
+
|
| 30 |
+
## The layer
|
| 31 |
+
|
| 32 |
+
One discrete metriplectic step, three channels:
|
| 33 |
+
|
| 34 |
+
```text
|
| 35 |
+
h' = h + Δt·Φ(h) − Δt·γ·F(h) [+ R(h), optional]
|
| 36 |
+
|
| 37 |
+
Φ(h) flux: h + W·φ(h) with 𝟙ᵀW = 0 → Σh' = Σh, exact, any φ
|
| 38 |
+
F(h) friction: Cayley transform of BBᵀ ⪰ 0 → ‖h'‖ ≤ ‖h‖, exact
|
| 39 |
+
R(h) rotation: Cayley transform of S = −Sᵀ → ‖h'‖ = ‖h‖, exact
|
| 40 |
+
γ gate: learnable, starts closed (σ ≈ 0); must be opened to
|
| 41 |
+
represent dissipation
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
- **Balanced flux** is the discrete-divergence form of a conservation law:
|
| 45 |
+
the residual of the channel is an exchange, never a source or sink — the
|
| 46 |
+
exact, learnable counterpart of divergence-free (Hamiltonian) flows.
|
| 47 |
+
- **Metric friction** is the second law as a structural fact: the map cannot
|
| 48 |
+
create "energy" out of nothing; the learned subspace `B` decides *where*
|
| 49 |
+
energy is dissipated, the sign is not learned.
|
| 50 |
+
- **The gate forces the model to decide, from data, whether its world is
|
| 51 |
+
open.** Conservative systems leave it closed; dissipative systems open it.
|
| 52 |
+
|
| 53 |
+
The same class instantiates as an MLP (depth is integration time), an RNN
|
| 54 |
+
(the layer is the cell, applied every rollout step), and a GNN (flux message
|
| 55 |
+
passing on a mesh — the *predicted field* conserves mass).
|
| 56 |
+
|
| 57 |
+
## What survived contact with the mathematics
|
| 58 |
+
|
| 59 |
+
1. **Exactness survives training and deployment.** Latent drift sits at the
|
| 60 |
+
machine-precision floor for every metriplectic model — ~10⁻¹³ in
|
| 61 |
+
structural float64 measurement, ~10⁻⁷ in float32 deployment. Baselines
|
| 62 |
+
have no conserved quantity by construction, so there is nothing to
|
| 63 |
+
measure on their side: that is the point. On advection–diffusion the
|
| 64 |
+
invariant is *physical*: the metriplectic GNN conserves the predicted
|
| 65 |
+
field's mass to ~10⁻¹³ while the plain GNN with identical data and
|
| 66 |
+
parameters leaks a substantial fraction of it.
|
| 67 |
+
2. **Structure shows in the shape of the error curve, not its height.**
|
| 68 |
+
NeuralODE, a continuous-time map in the raw state space, is the tightest
|
| 69 |
+
one-step fitter on these smooth small-state ODE benchmarks; the
|
| 70 |
+
metriplectic model sits in the MLP-family band. On the spring its
|
| 71 |
+
horizon growth ratio is far below NeuralODE, LSTM, and HNN and
|
| 72 |
+
of the same order as ResMLP; on damped spring the error is essentially
|
| 73 |
+
flat with horizon (metriplectic ≈ ResMLP ≈ NeuralODE), while the LSTM
|
| 74 |
+
compounds.
|
| 75 |
+
3. **Channel choice is the physics of the target system.** The exact
|
| 76 |
+
ablation isolates it: on the spring, the channel that matches the physics wins: circulation
|
| 77 |
+
(conserving the energy-like ‖h‖) fits measurably better than flux (0.457
|
| 78 |
+
vs 0.585); on Kepler the same switch *hurts* (1.373 vs 0.396), because
|
| 79 |
+
circulation conserves the wrong quantity there. Structure matters
|
| 80 |
+
exactly when it matches — and measurably when it does not.
|
| 81 |
+
4. **The friction gate is born closed and stays closed on these data.** The
|
| 82 |
+
measured gates end at σ(γ) ≈ 0.003 even on the damped spring: the flux
|
| 83 |
+
channel alone suffices to fit the transitions. The guarantee that
|
| 84 |
+
survives is the sign of the channel — the friction map is a contraction
|
| 85 |
+
wherever the gate sits, so the model can never represent a growing latent
|
| 86 |
+
norm.
|
| 87 |
+
5. **Recurrent long-horizon stability.** The metriplectic RNN (reversible
|
| 88 |
+
channel as the cell, skew generator conditioned on the physical
|
| 89 |
+
parameters) conserves its latent norm step after step over 2× the
|
| 90 |
+
training horizon (~3.8×10⁻¹⁶): the Cayley map is orthogonal for every
|
| 91 |
+
parameter value, so the state is bounded forever by construction. The
|
| 92 |
+
LSTM fits the transitions more tightly on this benchmark (0.44 vs 0.95
|
| 93 |
+
final error), but its latent carries no conserved quantity — nothing
|
| 94 |
+
about its long-horizon behavior is guaranteed.
|
| 95 |
+
|
| 96 |
+
## Measured results (nothing extrapolated; medians over 5 seeds, per-seed values committed)
|
| 97 |
+
|
| 98 |
+
| Claim | Where |
|
| 99 |
+
|---|---|
|
| 100 |
+
| Latent drift, structural (float64) | ~10⁻¹³, all metriplectic models |
|
| 101 |
+
| Field mass drift, metriplectic GNN vs plain GNN | ~10⁻¹³ vs ~10⁻¹ on advection–diffusion |
|
| 102 |
+
| One-step fidelity | NeuralODE is tightest; metriplectic in the MLP band (reported plainly) |
|
| 103 |
+
| Horizon growth ratio (spring) | far below NeuralODE/LSTM/HNN, comparable to ResMLP |
|
| 104 |
+
| Channel choice | circulation matches the spring's energy-like invariant (0.457 vs 0.585); hurts on Kepler (1.373 vs 0.396) |
|
| 105 |
+
| Friction gate | born closed; measured ≈ 0.003 on damped spring |
|
| 106 |
+
| RNN over 2× horizon | metriplectic: norm exact (~3.8×10⁻¹⁶), bounded by construction; LSTM fits tighter (0.44 vs 0.95) but no conserved quantity |
|
| 107 |
+
| Data efficiency | invariant exact at every budget (25/50/100%) |
|
| 108 |
+
| Higher-dimensional payoff | tightest MLP-family baseline on 6-D coupled springs (HNN included); lowest horizon growth on the chaotic double pendulum (3.9 vs 5.8 NeuralODE / 8.3 HNN) |
|
| 109 |
+
|
| 110 |
+
## Repo layout
|
| 111 |
+
|
| 112 |
+
```
|
| 113 |
+
manuscript.tex / .pdf the paper (NMI format)
|
| 114 |
+
ieee_paper.tex / .pdf the paper (IEEE format)
|
| 115 |
+
supplementary_information.tex / .pdf
|
| 116 |
+
index.html the project website
|
| 117 |
+
src/metnet/ layers.py (the class + theorems), models.py,
|
| 118 |
+
benchmarks.py, train.py, test_metnet.py
|
| 119 |
+
scripts/ run_experiments.py, make_figs.py,
|
| 120 |
+
train_lightning.py (PyTorch Lightning training),
|
| 121 |
+
export_models.py (train + export the headline
|
| 122 |
+
models to safetensors)
|
| 123 |
+
export/ trained checkpoints: model.safetensors + config.json
|
| 124 |
+
+ per-model cards + usage.py (zero-install demo)
|
| 125 |
+
results/ committed result JSONs + manifest + summary.tex
|
| 126 |
+
tests/ the invariant theorems, float64 + float32 floor
|
| 127 |
+
figs/ regenerated by scripts/make_figs.py
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## Reproduce
|
| 131 |
+
|
| 132 |
+
```bash
|
| 133 |
+
pip install -r requirements.txt
|
| 134 |
+
python -m unittest tests.test_metnet # 17 tests: the theorems, pinned
|
| 135 |
+
python scripts/run_experiments.py --seeds 3 # all benchmarks, ablations,
|
| 136 |
+
# data efficiency, RNN stress
|
| 137 |
+
python scripts/make_figs.py # figures + results/summary.tex
|
| 138 |
+
cd .. && pdflatex manuscript.tex # the paper
|
| 139 |
+
|
| 140 |
+
# the same protocol on PyTorch Lightning (CPU / GPU / distributed with one flag):
|
| 141 |
+
python scripts/train_lightning.py --bench spring --seeds 3 --epochs 100
|
| 142 |
+
|
| 143 |
+
# train + export the headline models to safetensors (also on Hugging Face):
|
| 144 |
+
python scripts/export_models.py
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Honest gaps
|
| 148 |
+
|
| 149 |
+
The friction channel contracts the state norm — the right structure for
|
| 150 |
+
these benchmarks, but not the full GENERIC degeneracy. The conserved quantity
|
| 151 |
+
is a *learned* latent invariant: the layer guarantees that *some* quantity is
|
| 152 |
+
conserved exactly, and the network must discover the physically meaningful
|
| 153 |
+
one (the field GNN is the case where the invariant lives in the predicted
|
| 154 |
+
state and is therefore physically exact). Extending exactness from latent
|
| 155 |
+
structure to named physical invariants is the central open problem.
|
| 156 |
+
|
| 157 |
+
## License
|
| 158 |
+
|
| 159 |
+
MIT — see [LICENSE](LICENSE).
|