Charge-Preserving Port-Hamiltonian Networks: Certified Learning of Systems That Remember

Many physical systems do not settle to a single resting state. A closed set of water tanks with leaky internal valves relaxes to level heights fixed by how much water it started with. A chain of masses with friction between neighbours stops vibrating but keeps drifting at whatever total momentum it had. In both cases friction removes energy while leaving some conserved quantity, a "charge", untouched, so the final state depends on the initial charge. The best current way to learn stable dynamics from data, Stable Port-Hamiltonian Neural Networks, builds its guarantee on a convex energy function, which forces a single global resting point. These networks therefore cannot represent such systems. They either converge to the wrong place or give up the guarantee.

Quantum physicists have a precise language for this situation. In open quantum systems, a "weak" symmetry means only the overall evolution respects the symmetry. A "strong" symmetry means every individual dissipation channel respects it as well. Only strong symmetry produces a family of protected resting states that dissipation cannot erase. We propose to carry this distinction into learned classical dynamics. The resulting neural model has a provable Lyapunov certificate, meaning an energy-like function that never increases along trajectories. It also has a resting set whose dimension equals the number of charges that friction preserves, and it learns from data which symmetries are strong and which are merely weak.

Core Claim

The model has the port-Hamiltonian form, meaning an energy function $H$ whose gradient drives motion through two matrices. One is a skew-symmetric matrix $J(x)$ that moves energy around without losing it. The other is a positive semidefinite matrix $R(x)$ that removes energy:

$$\dot{x} = [J(x) - R(x)]\,\nabla H(x) + G(x)u.$$

This is the structure used by Stable Port-Hamiltonian Neural Networks. That work parameterizes $H$ with a fully input-convex network (a network whose output is convex in its input) and obtains global stability to a unique equilibrium. Our change is to add learned charges $c(x) \in \mathbb{R}^k$ and require

$$R(x)\,\nabla c_i(x) = 0, \qquad \nabla c_i(x)^\top J(x)\, \nabla H(x) = 0 \quad \text{for } i = 1,\dots,k.$$

The first condition is the classical analogue of the strong-symmetry condition in Symmetry Breaking and Error Correction in Open Quantum Systems. That condition requires every jump operator to commute with the symmetry, which is what keeps the conserved charge alive under dissipation. Here, dissipation cannot act along the direction that changes a charge. The second condition makes the energy-conserving part preserve the charges too, so that $\dot c = 0$ exactly.

The key design choice is where convexity is imposed. We require $H$ to be convex only along each level set of $c$, not globally. Under that requirement each charge sector has exactly one minimum. The resting set is then a $k$-dimensional manifold parameterized by the charges, and $H$ restricted to a sector is a Lyapunov certificate for convergence to that sector's minimum.

Two regimes differ in how much the guarantee needs. In the linear-charge regime, $c = Ax$, a jointly convex $H$ together with projected matrices $J = PJ_0P$ and $R = PR_0P$ suffices, where $P$ is the projector onto the null space of $A$. The guarantee is then exact and simple. In the nonlinear-charge regime, a learned invertible map sends $x$ to coordinates $(q, c)$. $H$ is then parameterized as convex in $q$ but otherwise unconstrained in $c$, using a partially input-convex network.

Setting $k=0$ recovers the original stable port-Hamiltonian network. Enforcing the charges' symmetry only on $H$ while leaving $R$ free gives the "weak" variant. Under the weak variant the charges leak, and the model predicts the wrong resting state.

Research Program

The first part is theoretical. We prove convergence of every trajectory to its sector's minimum in both regimes. We also prove the controlled counterpart: with inputs, the charges evolve only through $\nabla c^\top G u$, so a planner using the model knows exactly which setpoints are reachable from a given initial charge.

We also address what happens when the symmetry is only approximate, which is the classical version of the finite-size and symmetry-violating-noise problems flagged by Lieu et al.. We add a small unconstrained dissipation term $\epsilon R_b(x)$. The charge then drifts at a rate bounded by $\epsilon \|\nabla c\|\,\|R_b\|\,\|\nabla H\|$, which follows directly from differentiating $c$ along the flow. This gives a certified protection time on the order of $1/\epsilon$ that the model can report.

The second part is learning which charges exist. The number of charges $k$ and the charge maps themselves are learned. A sparsity penalty on the magnitude of $\epsilon R_b$ decides whether an apparent symmetry is strong (it survives dissipation) or weak (the data require charge leakage). We select $k$ by held-out long-horizon error.

The third part is to say plainly what this does not cover. When a sector is compact, as for a free damped rigid body, whose sphere of fixed angular momentum carries two minima, per-sector convexity is impossible. The same holds for discrete symmetries such as a double-well oscillator. We include the rigid body as a stress test and report the failure rather than hide it. The analogy to covariant codes in Continuous Symmetries and Approximate Quantum Error Correction is motivational only. We borrow the idea that symmetry dictates which errors are correctable, not its theorems.

Baselines

The naive reference point is an unconstrained neural ODE, a network that directly outputs $\dot x$. Stable Port-Hamiltonian Neural Networks reports that this model gains energy spontaneously or fails to reach equilibrium when extrapolating.

The strongest existing method is the stable port-Hamiltonian network itself, with a globally convex $H$. It is the only baseline in the file with a built-in stability guarantee on nonlinear identification, so it is the right bar. That paper reports its cascaded-tanks and thermal RMSE only graphically. The only textual claim is that it "maintained low error rates while other models became unstable" under 25% noise. We found no reported scalar result on Lacuna for either benchmark, so we will rerun it ourselves.

The key ablation is the weak variant described above, in which $H$ is symmetric but $R$ is unconstrained. It isolates the strong-symmetry condition from symmetry-aware energy design. We also include a soft-constraint variant: an unconstrained neural ODE with a charge-conservation penalty in the loss. Finally, an oracle variant receives the true charges and serves as an upper bound for the charge-learning step.

For fairness, all models share the same training trajectories, the same network widths, the same integrator and step size, and the same hyperparameter search budget of 30 trials each, scored on the same validation split. Our model beats the strongest baseline if it meets three conditions on held-out initial conditions from unseen charge values. It must reduce steady-state error by a clear margin, and we will report the ratio against a stated threshold of 2×. It must keep the long-horizon trajectory error at least as low. It must also match the true resting-set dimension, which neither baseline can do by construction.

Why not just…?

Why not just feed a stable port-Hamiltonian network with symmetry-invariant features? This is the most serious alternative. Making $H$ a convex function of invariant features does produce a manifold of minima. It is exactly the weak variant in our ablation. With $R$ unconstrained, nothing stops dissipation from draining the charge, so the model can learn a resting set of the right shape but land at the wrong point on it. The closed-tank and momentum-chain experiments measure this directly as charge drift over long rollouts. If the weak variant learns $R\nabla c \approx 0$ on its own and matches our model, we will conclude that the hard constraint adds only guarantees, not accuracy, and report that.

Why not just penalize charge drift in the loss of an ordinary neural ODE? A penalty controls drift only near the training data and gives no certificate. The evidence in Stable Port-Hamiltonian Neural Networks is that unconstrained models fail precisely in extrapolation. Our tests hold out whole charge ranges and horizons 10× longer than training, where soft penalties have no reason to hold.

Why not just hold the charge with active feedback, for example a contraction-metric controller? Learning Certified Control Using Contraction Metric certifies tracking of a reference by active actuation, running at about 0.4 ms per step. The problem studied here is modeling what a system does passively, and a feedback law does not answer it. Our model can, however, serve as the prediction model that tells such a controller which references are reachable at all.

Why not just hard-code the known conserved quantities? When charges are known, one should, and the oracle baseline does exactly this. Our contribution is to learn them and their strong-or-weak status when they are unknown. Success means approaching the oracle's error.

Proposed Experiments

The first benchmark is a closed variant of the cascaded-tanks system used by Stable Port-Hamiltonian Neural Networks. Outflow is removed, so total volume is conserved, which gives a linear charge and a known resting level set. The second is a mass chain with neighbour-to-neighbour friction, which conserves total momentum. We run both with the 25% measurement-noise protocol from that paper. The third is a nonlinear-charge system: a ring of coupled rotors with internal friction that conserves total angular momentum, handled through the learned-coordinates regime. The fourth is the damped free rigid body, run as the declared failure case.

For each benchmark we measure four things: long-horizon trajectory RMSE, steady-state error as a function of initial charge, charge drift per unit time, and the fraction of held-out trajectories that end in the correct charge sector.

The decisive check has three parts, each on the momentum chain. First, the true system is strongly symmetric: the weak variant should show charge drift that grows with horizon, while ours stays flat. Second, we add a known symmetry-breaking friction of strength $\epsilon$ to the true system. Our model should recover a leak term whose fitted drift rate scales linearly with $\epsilon$, as the drift bound predicts. Third, we remove the symmetry altogether. Here our model should select $k=0$ and match the stable port-Hamiltonian network, showing that the extra structure is not imposed where the data do not support it.

The closed-loop check uses each learned tank model inside a receding-horizon planner with volume-changing inflow as the input. We count how often the planner commands setpoints that are unreachable from the current volume, and measure the resulting tracking error. We compare against regularized data-enabled predictive control as in Regularized and Distributionally Robust Data-Enabled Predictive Control. That method predicts future trajectories as linear combinations of recorded past ones, and we tune it over the same trial budget.