When a robot's simulator is wrong, the usual fix is to collect some real trajectories and learn a correction, either by tuning the simulator's parameters or by training a neural network that adds a "residual" force to the simulated equations of motion. These real trajectories almost never cover the conditions the model will later face. Safety limits keep real data inside a narrow, gentle range of motion, such as hovering or small oscillations. The model is then used for aggressive maneuvers, large swings and high speeds. Training and deployment data are therefore not drawn from the same distribution, and the shift is guaranteed by how the data were collected. An unconstrained residual network trained inside the gentle range can do anything outside it, including inventing energy that the real system does not have. When that happens, simulated rollouts blow up and any controller that plans through the model is misled.
We propose to restrict the learned correction to a physically safe form. The corrected model keeps the simulator's own energy function, and the residual may add only three things: extra dissipation (friction, damping, hysteresis-like losses), energy-conserving coupling between states, and extra input channels. Far from the data, the residual shrinks back toward the uncorrected simulator. A residual built this way cannot create energy spontaneously anywhere in state space. Inside the data it fits the real system; outside the data its worst failure is excess damping, not divergence. The central claim is testable: when real data come from a narrow operating envelope, this passive, coverage-shrinking residual will give lower long-horizon prediction error and better downstream control outside the envelope than parameter tuning, unconstrained residuals, or fully learned physics models, at equal data.
Why this is the right gap
Four lines of work each hold part of the problem. The first is sim-to-real identification by parameter search. TuneNet predicts parameter corrections from a single rollout, and EASI searches parameters with an evolutionary strategy against a transition discriminator. Both assume the simulator's equations are structurally correct, so a missing friction or hysteresis term cannot be absorbed. The second line fixes that assumption: learned residual physics for soft robots adds a neural residual force to a differentiable simulator and reports up to a 60.3% trajectory-error reduction over traditional identification. That residual is unconstrained and was trained and tested on data from the same regime. It motivates our method, and it is the baseline our out-of-envelope test targets.
The third line, physics-structured models, supplies the method. The port-Hamiltonian form writes dynamics as $\dot x = (J - R)\nabla H + Gu$, where $H$ is an energy function, $J$ is skew-symmetric (it moves energy between states without changing the total), $R$ is positive semidefinite (it only removes energy), and $G$ routes inputs. GP-PHS places Gaussian-process priors on $H$ and learns from a single noisy trajectory. Stable port-Hamiltonian networks build stability into the architecture and stay well-behaved under 25% noise, where plain neural ODEs diverged. Both learn the whole system from data and do not use an existing simulator as a prior. We keep the simulator's energy function and learn only a structured correction to $J$, $R$ and $G$, which needs far less data than learning $H$ from scratch.
The fourth line concerns the distribution shift itself and constrains the design. SwaNNFlight shows that fine-tuning a quadrotor policy on real data confined to hovering destroys agile behaviors, and it fixes this by anchoring to a frozen simulation-trained critic. It anchors the policy; we apply the same idea to the dynamics model, where the anchor is the simulator itself. Robust system identification shows that worst-case robustness over an uncertainty set is equivalent to a norm penalty on the identified matrix. It also shows that generic Wasserstein robustness has error decaying as $T^{-2/n}$ in state dimension $n$, which is hopeless for the short trajectories here. We borrow the lesson that a well-chosen penalty buys robustness cheaply, and we make that penalty depend on how far a state is from the data.
Core construction
Let $f_{\text{sim}}(x,u)$ be the simulator's dynamics and $H_{\text{sim}}(x)$ its total mechanical energy, which is kinetic plus potential energy and is available for any rigid-body or finite-element simulator. The corrected model is
$$\dot x = f_{\text{sim}}(x,u) + \big(J_\phi(x) - R_\phi(x)\big)\nabla H_{\text{sim}}(x) + G_\phi(x)\,u,$$
where $J_\phi$ is built skew-symmetric, $R_\phi = L_\phi L_\phi^\top$ is positive semidefinite by construction, and $G_\phi$ is an unconstrained input map, all output by small networks with parameters $\phi$. Along any trajectory, the residual's contribution to the rate of energy change is $-\nabla H_{\text{sim}}^\top R_\phi \nabla H_{\text{sim}} + \nabla H_{\text{sim}}^\top G_\phi u$. This is non-positive except through the actuated input. The guarantee holds everywhere in state space, not only where data exist.
The second ingredient is shrinkage toward the simulator away from the data. We give each residual factor a distance-aware parameterization, for example random Fourier features over state-action inputs with a zero-mean prior, or equivalently a sparse Gaussian process. Each factor therefore reverts to zero as states move away from the training envelope. The training loss is multi-step prediction error on the few short real snippets, following the prediction-error-over-disjoint-snippets approach of Simpson et al. so unknown initial states are handled. A nuclear-norm penalty on the factor weights is added, following the regularization-as-robustness equivalence above.
Research Program
The work has three parts. First, we will build the model with a differentiable simulator backend and fit it to snippets of a few seconds each. We will confirm that inside the envelope it matches an unconstrained residual; if it fits worse there, the structural constraint is too restrictive and the claim fails early. Second, we will build a sim-to-sim testbed with controlled structural gaps. The "real" system is a simulator with added terms absent from the nominal one. Some added terms are passive, such as Coulomb friction, Bouc-Wen hysteresis and nonlinear damping. Others are deliberately non-passive, such as actuator latency and a destabilizing aerodynamic term. Real data come only from low-energy regions: small pole angles for cartpole, small joint excursions for the Ant robot, low-amplitude excitation for Bouc-Wen. Testing uses high-energy regions. This lets us measure error as a function of how far test states lie from the training envelope. Third, we will validate on hardware using the real-world cartpole setup from EASI, with real data collected only near the balance point and swing-up as the test task.
Non-passive gaps are the honest risk. Latency can inject energy, and our model can represent energy injection only through the input channel $G_\phi u$. Latency may be partly representable that way, because its effect scales with the commanded input. A destabilizing term with no input dependence is not representable. We will report both cases separately and not average them into a single number.
Baselines
The naive reference is the uncorrected nominal simulator, with no real data used. Every method must beat it out of the envelope, and an unconstrained residual may fail to.
The parameter-search baselines are TuneNet and EASI. EASI is the strongest parameter-only method in the file: on real-world cartpole it reports roughly 37% lower pole-angle error and 25% lower cart-velocity error than uniform domain randomization (EASI). We will run EASI's released search on the same single-envelope trajectories, with the same number of real transitions and a search budget matched in wall-clock time. Beating it means lower out-of-envelope error when the gap is structural. We expect parity when the gap is purely parametric, and parity there is an informative control.
The residual-physics baseline follows the soft-robot residual approach (learned residual physics). It is an unconstrained network adding force to $f_{\text{sim}}$, given the same architecture width, weight decay tuned on a held-out in-envelope split, and the same data. Its reported number, the 60.3% reduction versus identification, is in-distribution and on different hardware, so it is not directly comparable; we reimplement it.
The strongest simple competitor is a Gaussian-process residual with the simulator as prior mean. It reverts to the simulator away from data just as our model does, but it has no passivity structure. Two fully learned physics models test whether keeping the simulator matters. One is GP-PHS, for which no reported numeric result was found on Lacuna for its inductor benchmark. The other is the meta-learned constrained state-space model of Meta-Learning for Physically-Constrained Neural System Identification, which reports a Bouc-Wen target RMSE of $2.53 \times 10^{-5}$ against $8.41 \times 10^{-5}$ for target-data-only training. That number comes from an in-distribution protocol; we rerun the method under our envelope split.
Two ablations isolate the ingredients. Passivity without shrinkage separates the effect of energy structure from the effect of data-distance reversion. Shrinkage without passivity is exactly the GP-residual baseline. Every method gets the same real snippets, the same hyperparameter-search budget (a fixed number of trials on an in-envelope validation split, never on out-of-envelope data), and the same rollout horizon. Our method counts as better if it significantly beats the best baseline on out-of-envelope rollout error, across seeds, in the passive-gap settings, while not being worse in-envelope.
Why not just…?
Why not just use domain randomization? Randomizing parameters cannot represent a missing hysteresis term. It also cannot reach targets outside the chosen ranges, and EASI's cartpole result shows identification beating it on real hardware. We still include domain randomization in the control-task comparison, because a conservative controller might happen to handle extrapolation well. If it matches our swing-up success, the modeling gain has no practical value for control, and we would report that.
Why not just use a Gaussian-process residual on the simulator, which already reverts to the simulator away from data? This is the real threat. The difference appears in the transition zone near the envelope's edge, where the process is still confident but extrapolating. There, nothing stops it from predicting energy gain, so rollouts that start inside the envelope and leave it can be pushed into divergence. The "shrinkage without passivity" ablation settles this directly. If it matches the full model on long-horizon out-of-envelope error, the passivity structure is unnecessary and the contribution reduces to "use a GP residual." We would then say so.
Why not just do test-time training with a physics-invariant objective, as the gap analysis suggests? In vision, test-time training needs an auxiliary self-supervised task because labels are missing (TTT). In dynamics, the next observed state is the label, so online prediction-error fitting is already available and strictly more informative than an invariant-violation loss. An invariant-matching objective would also wrongly penalize the real dissipation we are trying to learn. We include online fine-tuning of the unconstrained residual as a check. SwaNNFlight's evidence predicts it will overfit the envelope, as naive fine-tuning did for the policy.
Decisive checks
The main plot is out-of-envelope rollout error against normalized energy distance from the training envelope. The prediction is that unconstrained residuals degrade faster than the nominal simulator beyond some distance, and that our model never falls below the simulator. That prediction follows from the energy bound, because excess dissipation limits how far errors can grow. Secondary metrics are the fraction of rollouts showing spurious energy gain, and swing-up success when the model is used inside model-predictive control on sim-to-sim and real cartpole. The non-passive-gap experiments are a pre-registered failure test. If our model underperforms the unconstrained residual on the latency gap, that marks the method's boundary and does not refute the passive-gap claim. The paper's scope would then be stated as dissipative structural gaps.
References
- TuneNet: One-Shot Residual Tuning for System Identification and Sim-to-Real Robot Task Transfer
- EASI: Evolutionary Adversarial Simulator Identification for Sim-to-Real Transfer
- Sim-to-Real of Soft Robots With Learned Residual Physics
- Gaussian Process Port-Hamiltonian Systems: Bayesian Learning with Physics Prior
- Stable Port-Hamiltonian Neural Networks
- The SwaNNFlight System: On-the-Fly Sim-to-Real Adaptation via Anchored Learning
- Robust System Identification: Finite-sample Guarantees and Connection to Regularization
- Parallelizable Parametric Nonlinear System Identification via tuning of a Moving Horizon State Estimator
- Meta-learning for physically-constrained neural system identification
- Test-Time Training with Self-Supervision for Generalization under Distribution Shifts