An Invariant Compiler for Neural ODEs in AI-Accelerated Scientific Simulation
Organizations: Virginia Tech, VA, USA
Abstract
Neural ODEs are increasingly used as continuous-time models for scientific and sensor data, but unconstrained neural ODEs can drift and violate domain invariants (e.g., conservation laws), yielding physically implausible solutions. In turn, this can compound error in long-horizon prediction and surrogate simulation. Existing solutions typically aim to enforce invariance by soft penalties or other forms of regularization, which can reduce overall error but do not guarantee that trajectories will not leave the constraint manifold. We introduce the invariant compiler, a framework that enforces invariants by construction: it treats invariants as first-class types and uses an LLM-driven compilation workflow to translate a generic neural ODE specification into a structure-preserving architecture whose trajectories remain on the admissible manifold in continuous time (and up to numerical integration error in practice). This compiler view cleanly separates what must be preserved (scientific structure) from what is learned from data (dynamics within that structure). It provides a systematic design pattern for invariant-respecting neural surrogates across scientific domains.
Figures & tables
| Invariant Type | Constraint | Geometric IR | Enforcement Mechanism | Applications | Key Refs. | App. |
|---|---|---|---|---|---|---|
| Simplex / Norm | , | Unit sphere via map | Skew-sym. dynamics: , ; | Epidemiology, market share, pop. genetics | [ 40 , 41 ] | A |
| Lorentz Cone | Lorentz cone | Tangent-cone proj.: | Relativity, robust opt., signal proc. | [ 45 , 42 , 49 ] | B | |
| PSD Cone | Cholesky manifold | Cholesky param.: , evolve | Covariance dynamics, Kalman filtering | [ 47 , 48 ] | C | |
| Center of Mass | , | Null space of mass-weighted sum | Mean subtraction: , | -body, molecular dynamics | [ 50 , 51 ] | D |
| Stoichiometric | Null space of molecular matrix | Null-space proj.: , | Chemical kinetics, metabolic networks | [ 21 , 20 ] | E | |
| Hamiltonian | , Jacobi identity | Symplectic / Poisson manifold | Latent canonical coords via INN: | Pendulum, Lotka-Volterra, rigid body | [ 52 ] | F |
| System | Dim. | Invariant type | Architecture | Key challenge |
|---|---|---|---|---|
| SIR epidemiological model | 3 | Simplex ( ) | Skew-symmetric | Population conservation |
| NOx reaction network | 5 | Stoichiometric ( ) | Null-space | Nonlinear kinetics, product inhibition |
| Chemical reaction network | 6 | Stoichiometric ( ) | Null-space | Element conservation (C, H, O) |
| Lorentz cone spiral | 3 | Cone ( ) | Projection | Boundary dynamics |
| Coupled radial-angular dynamics | 3 | Cone ( ) | Projection | Nonlinear radial-angular coupling |
| Replicator-mutator ( ) | 5 | Simplex ( ) | Skew-symmetric | Diverse dynamical regimes |
| Metric | Unconst. | Penalty | Ours | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | ||||
| MSE (Total) | ||||
| Elem. Dev. |
| Metric | Unconst. | Penalty | Ours | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | ||||
| MSE (Total) | ||||
| Viol. (Mean) | — |
| Metric | Model | IF ( ) | |||
|---|---|---|---|---|---|
| MSE (Train) | Unconst. | 2.91e-06 | 2.91e-06 | 2.91e-06 | |
| PINNs | 2.56e-06 | 2.56e-06 | 2.56e-06 | ||
| Ours | 1.16e-06 | 1.16e-06 | 1.16e-06 | ||
| MSE (Extrap) | Unconst. | 2.41e-05 | 1.40e-04 | 2.33e-04 | |
| PINNs | 2.16e-06 | 6.75e-06 | 1.12e-05 | ||
| Ours | 7.21e-07 | 8.47e-07 | 9.77e-07 |
| Metric | Model | IF ( ) | |||
|---|---|---|---|---|---|
| MSE (Train) | Unconst. | 4.39e-06 | 4.39e-06 | 4.39e-06 | |
| PINNs | 7.54e-06 | 7.54e-06 | 7.54e-06 | ||
| Ours | 7.61e-07 | 7.61e-07 | 7.61e-07 | ||
| MSE (Extrap) | Unconst. | 7.38e-05 | 1.08e-03 | 1.15e-02 | |
| PINNs | 6.03e-05 | 1.66e-04 | 3.47e-04 | ||
| Ours | 2.25e-06 | 1.11e-05 | 4.76e-05 |
| Metric | Unconst. | Penalty | Ours | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | ||||
| MSE (Total) | ||||
| Viol. (Mean) |
| Metric | Unconst. | PINNs | Ours | IF |
|---|---|---|---|---|
| MSE (Total) | 2.01e-05 1.79e-05 | 6.75e-05 9.91e-05 | 2.92e-06 1.62e-06 | |
| Energy Dev. | 2.94e-04 2.49e-04 | 4.84e-04 3.04e-04 | 1.81e-04 9.11e-05 | |
| Momentum Dev. | 1.77e-04 6.89e-05 | 5.18e-04 2.51e-04 | 2.42e-07 1.16e-07 | |
| Ang-Mom Dev. | 4.86e-04 4.61e-04 | 7.07e-04 4.95e-04 | 2.75e-04 1.78e-04 |
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
| Metric | Unconst | Penalty | Ours | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | ||||
| MSE (Total) | ||||
| Viol. (Mean) |
| Metric | Unconstrained | Penalty | Null-Space (Ours) | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | ||||
| MSE (Total) | ||||
| Viol. (Mean) |
| Metric | Unconst. | Penalty | Ours | IF |
|---|---|---|---|---|
| MSE (Train) | ||||
| MSE (Extrap) | — | |||
| MSE (Total) | — | |||
| Viol. (Mean) |
| Metric | Model | IF ( ) | |||
|---|---|---|---|---|---|
| MSE (Train) | Unconst. | 2.81e-06 | 2.81e-06 | 2.81e-06 | |
| PINNs | 8.18e-06 | 8.18e-06 | 8.18e-06 | ||
| Ours | 3.12e-07 | 3.12e-07 | 3.12e-07 | ||
| MSE (Extrap) | Unconst. | 8.65e-07 | 2.52e-07 | 1.30e-07 | |
| PINNs | 6.97e-06 | 1.95e-06 | 9.35e-07 | ||
| Ours | 2.50e-07 | 1.45e-07 | 1.25e-07 |
| Metric | Model | IF ( ) | |||
|---|---|---|---|---|---|
| MSE (Train) | Unconst. | 1.68e-07 | 1.68e-07 | 1.68e-07 | |
| PINNs | 1.32e-05 | 1.32e-05 | 1.32e-05 | ||
| Ours | 9.71e-08 | 9.71e-08 | 9.71e-08 | ||
| MSE (Extrap) | Unconst. | 2.91e-06 | 3.30e-05 | 1.29e-04 | |
| PINNs | 1.13e-04 | 2.19e-03 | 5.68e-02 | ||
| Ours | 5.15e-07 | 1.62e-06 | 3.23e-06 |
| Invariant Type | Prompt Specification | Compiler Rewrite |
|---|---|---|
| Simplex / Norm | State lives on a simplex (mass conservation + non-negativity). Require exact preservation without penalties, normalization, or clamping. | Compile to a norm-preserving latent representation (e.g., embedding) and enforce tangency via skew-symmetric generators; recover physical states by squaring. |
| Lorentz Cone | State must remain in a Lorentz/convex cone for all (forward invariance). | Enforce viability by projecting the vector field onto the tangent cone at the current state (closed-form cases for interior/boundary/apex). |
| PSD Cone | Matrix-valued state must remain positive semidefinite ( ) throughout evolution. | Reparameterize using a Cholesky factorization and evolve ; PSD is guaranteed by construction of . |
| Center of Mass | Center-of-mass position and total momentum must remain zero (mass-weighted constraints). | Project out the center-of-mass components by mean subtraction (mass-weighted) in both velocity and acceleration updates. |
| Stoichiometric | Linear conservation laws must hold (e.g., elemental/mass balances encoded by a matrix). | Restrict dynamics to the null space of the conservation matrix via with , guaranteeing conservation for any . |
| Hamiltonian | Preserve energy and Poisson structure (Jacobi identity). | Compile into canonical latent coordinates and impose structured Hamiltonian/Poisson dynamics (canonical ); induce the physical Poisson tensor via coordinate transformation. |