Hamiltonian Neural Network Symplectic Engine
an AI model for accurate physics simulations
2 min read
This model simulates continuous dynamical systems while strictly obeying the laws of physics. Standard neural differential equations tend to lose or artificially gain energy over time, distorting trajectories. Built as an HNN (Hamiltonian Neural Network, which predicts a system's total energy instead of direct velocities), it computes the evolution of coordinates and momenta using a symplectic matrix, guaranteeing both energy and phase-space volume conservation. Released by At1uri, the model has a tiny footprint—just three fully connected layers of 64 neurons each with tanh activations. It is built for researchers, physicists, and engineers who need long-horizon simulations of mechanical and orbital systems without numerical drift.
Key features
- Takes 4 inputs (generalized coordinates and momenta for 2 degrees of freedom), runs through 3 hidden layers of 64 units each, and outputs a single scalar Hamiltonian energy value.
- Mathematically guarantees zero total energy drift and preserves phase-space volume according to Liouville's theorem.
- Ships in
model.safetensorsformat and runs inference in pure Python using only NumPy and Safetensors, no heavy deep learning frameworks required.
What you can do
- Simulate complex orbital trajectories, including the Hénon–Heiles galactic system and Kepler central-force problems, without losing angular momentum.
- Model nonlinear mechanical oscillations—such as a double pendulum or a bistable Duffing oscillator—across hundreds of time steps.
- Drop a lightweight, NumPy-based physics solver directly into scientific scripts or educational dynamical-system simulators.
Example
import numpy as np
from hnn_model import HamiltonianNeuralNetwork
model = HamiltonianNeuralNetwork.from_pretrained(".")
z0 = np.array([0.25, 0.15, 0.10, -0.05], dtype=np.float32)
energy = model.energy(z0)
trajectory, energies = model.simulate(z0, steps=500, dt=0.02, method="rk4")
Read more
DetailsMean relative energy drift: less than 0.0001% (3.69e-7).
Maximum relative drift over 500 steps: 1.50e-6.
Liouville divergence: 3.35e-4.
Tested on the At1uri/hamiltonian-phase-space-benchmarks suite (double pendulum, Hénon–Heiles system, Kepler problem, Duffing oscillator).










Comments