GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Shushant17711/hamiltonian-world-models: Action-conditioned Hamiltonian world models: pre-registered test of structure vs loss for energy conservation, OOD generalisation and control

BranchesTags
Open more actions menu

Latest commit

 

History

41 Commits
41 Commits

Folders and files

NameName
Last commit message
Last commit date
.kiro/specs/hamiltonian-world-models
.kiro/specs/hamiltonian-world-models
 
 
configs
configs
 
 
hwm
hwm
 
 
paper
paper
 
 
results
results
 
 
scripts
scripts
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
LIMITATIONS.md
LIMITATIONS.md
 
 
PLAN.md
PLAN.md
 
 
PREREGISTRATION.md
PREREGISTRATION.md
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 

Repository files navigation

hamiltonian-world-models

Action-conditioned world models whose structure (a learned Hamiltonian, port-Hamiltonian control and damping, and a symplectic integrator) guarantees energy conservation in the absence of control. They work from state vectors and from 64×64 pixels and are used for model-predictive control.

Question. Does building physics into a world model's structure beat learning it through a loss, on long-horizon accuracy, generalisation to unseen energies, and sample-efficient control? And where does the advantage stop on a chaotic system?

The hypotheses, metrics and decision rules were frozen in PREREGISTRATION.md before any model code existed; results/verdicts.md applies them mechanically. Read LIMITATIONS.md alongside the results.

Method

id model idea
A MLP residual next-state predictor
B PINN* A + residual against the true equations of motion (*privileged)
C latent Neural ODE RK4 latent dynamics + energy penalty: physics through the loss
D RSSM Dreamer-style recurrent state-space model
E Hamiltonian world model latent (q, p), H = ½ pᵀA(q)p + V(q) with A ≻ 0 by construction, input G(q)u and damping R(q) ⪰ 0, Strang splitting around a symplectic step: physics through the structure
E-ens 5 × E bootstrapped ensemble; its disagreement is penalised by the planner

Four ground-truth systems with exactly known energy, simulated with a 4th-order Gauss–Legendre integrator (relative energy drift < 1e-5 over 10k steps): pendulum (torque), cart-pole (force), acrobot (elbow torque, chaotic) and the planar two-body orbit (thrust). Models train on a low energy band and are tested in-band and on a disjoint higher band.

hypothesis pre-registered test
H1 E's true-energy drift over 10k passive steps is ≥ 10× lower than C's (CI lower bound > 3) on ≥ 2 of 3 systems
H2 E has lower out-of-band error at 100 steps than every baseline on ≥ 3 of 4 systems
H3 with pixels, MPC with E-ens reaches 80% task success with ≤ ½ the env steps of the RSSM on ≥ 2 of 3 tasks
H4 on the acrobot the advantage holds within one Lyapunov time and is gone beyond three

Results

None of the four pre-registered hypotheses is supported. 60 runs (5 models × 4 systems × 3 seeds); full tables with per-seed values and 95% bootstrap CIs in results/verdicts.md. Model E is the version after amendment 1 (stability fixes made before any verdict existed).

hypothesis verdict in one line
H1 energy drift ≥ 10× below C not supported (0 of 3 systems) pendulum and cart-pole fail on one bad seed of E each; on the orbit E drifts far more than C on every seed
H2 lower out-of-band error than every baseline not supported (0 of 4) E never beats all four baselines; on the acrobot every baseline beats it
H3 sample-efficient control (pixels) not supported (0 of 3 tasks) under the reduced protocol of amendment 2 neither E-ens nor the RSSM reaches 80% success on any task within 10k env steps (0% at every checkpoint, all 18 runs), so ∞ vs ∞ fails by the pre-registered rule
H4 advantage within 1 Lyapunov time, gone beyond 3 not confirmed on the acrobot E is worse than the best baseline at every horizon (advantage 0.01–0.3)

What the runs show. E does what its structure promises — it conserves its own learned energy (learned-H drift 1e-5 to 1e-2 over 10,000 steps in 11 of 12 runs) — but conserving the learned energy is not conserving the true one. When a seed fits the system well, the true-energy drift is the lowest of any model: pendulum seeds 0 and 2 drift 0.002–0.006 (C: 0.15–0.27, and C's rollouts diverge on one seed), cart-pole seeds 0 and 1 drift 0.045 (baselines 0.6–2.9). When the learned H is off away from the data, the latent trajectory keeps H_θ fixed while sliding into regions that decode to states with the wrong energy: pendulum seed 1 (drift 58), cart-pole seed 2 (2,400), and all three orbit seeds (37 to 14,000). With three seeds the pre-registered CI lower bound is the worst seed, so one such seed fails a system. E also pays for its 2n-dimensional canonical bottleneck at short horizons: its one-step error is 10–1000× higher than the baselines' on every system (figure below), and it rarely wins that back later.

Sanity row: the friend's setting reproduces. On the two-body orbit, the energy-penalised latent ODE (C) drifts 0.21–0.37 over 10,000 passive steps against 256–393 for the plain MLP (A), and has lower 1000-step error (1.05–1.58 vs 1.8–6.1) — the qualitative result of Optimus2007/physics-informed-world-models holds here, with actions and three seeds. On this system the loss-based approach beats the structural one.

H3: a floor effect, not a comparison. All 18 pixel MBRL runs (3 tasks × 2 models × 3 seeds) reach 10k env steps with 0% success at every checkpoint. The verdict follows the rule as registered (a task where neither model learns is not evidence for E), but the experiment cannot rank the two models: with the budget and planner cut by amendment 2 to fit an RTX 4060 Laptop (~3 GPU-hours per E-ens run), neither learns the tasks. Whether E-ens would win under the original 50k-step protocol is unknown.

Exploratory (not pre-registered), mean MPC return over 10 evaluation episodes, mean over 3 seeds:

task model 1k 2k 5k 10k 10k per seed
pendulum E-ens −190.8 −115.5 −49.4 −52.6 −40.5, −81.1, −36.2
pendulum RSSM −196.4 −195.2 −194.1 −183.7 −172.8, −184.0, −194.2
cart-pole E-ens −12.1 −20.1 −12.5 −11.0 −16.9, −13.2, −3.0
cart-pole RSSM −12.3 −20.9 −12.6 −3.0 −2.4, −6.5, −0.2
orbit E-ens −176.4 −175.5 −180.5 −154.5 −163.3, −119.9, −180.3
orbit RSSM −202.9 −199.9 −272.5 −147.3 −215.6, −109.9, −116.2

On the pendulum every E-ens seed improves its return by ~4× while the RSSM stays near its random-policy level; on the cart-pole the RSSM ends ahead on every seed; the orbit is mixed. Three seeds and a measure chosen after the fact: a lead for a properly budgeted follow-up, not a result.

error vs horizon energy drift out-of-band error success vs env steps acrobot advantage vs Lyapunov time

Reproduce

uv sync
uv run pytest                                            # unit tests, CPU, < 2 min
uv run pytest -m slow                                    # 10k-step conservation checks

uv run python scripts/gen_data.py --config configs/data/{pendulum,cartpole,acrobot,orbit}.yaml
uv run python scripts/sweep.py configs/sweeps/state.yaml --shard 0/1   # H1, H2: 60 runs
uv run python scripts/lyapunov.py --env acrobot                         # H4
uv run python scripts/run_mbrl.py --config configs/model/ensemble.yaml env=pendulum obs_mode=pixels  # H3
uv run python scripts/make_figures.py                                   # verdicts.md + figures

One run: uv run python scripts/train.py --config configs/model/hamiltonian.yaml env=acrobot seed=1, then uv run python scripts/evaluate.py results/acrobot-hamiltonian-state-s1. Every run writes its resolved config, metrics and checkpoints under results/<env>-<model>-<obs>-s<seed>/ and resumes if interrupted. Hardware: one RTX 4060 Laptop GPU (8 GB); every model is under 5M parameters.

Layout

hwm/envs         simulators, rewards, success predicates, 64×64 SDF renderer
hwm/integrators  GL4 (ground truth), rk4 / leapfrog / implicit midpoint (models)
hwm/data         dataset generation (energy bands, OU actions), training windows
hwm/models       A-E, ensemble, shared contract
hwm/train        the shared trainer
hwm/planning     CEM, MPC, model-based RL loop
hwm/eval         rollout error, energy drift, statistics, calibration, Lyapunov, verdicts, figures
scripts/         gen_data, train, evaluate, sweep, run_mbrl, lyapunov, make_figures

License

MIT. See LICENSE. Copyright (c) 2026 Shushant Kumar Choudhary.

About

Action-conditioned Hamiltonian world models: pre-registered test of structure vs loss for energy conservation, OOD generalisation and control

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.