lj_2particle
MD · LAMMPS reference- particles
- 2
- energy drift
- Lagra 9.10e-02 · LAMMPS 1.19e-02 · ratio 7.63×
- throughput
- Lagra 2,447,473 steps/s · LAMMPS 4,058,580 steps/s · Lagra/LAMMPS = 0.60×
The case for one kernel over fifty special-purpose engines, plus the regression-suite shape: which reference engine each Lagra domain is checked against, how many scenes, and what the cross-domain coupling actually buys you.
Lifted from the paper (Lagra: A differentiable physics kernel for verifiable domain operations) — the same diagrams, with shorter captions for the web.
LagrangianNode variants. Six representative cases of the closed sum type the engine ships with — the full enumeration is roughly two dozen, covering harmonic bonds, Coulomb, Lennard-Jones, Yukawa, contact-floor, and global terms like uniform acceleration. Each variant declares its arity, parameter set, scalar Lagrangian density, and physical units.
LagrangianGraph. Four particles, six interaction terms drawn from the closed sum type. The Lagrangian is the sum across all edges — adding or removing a term means editing the graph, never the kernel. Interventions (user drag, agent tool call) enter through a typed channel and consolidate into the graph each step.
(state, forces) → (); adding a new physics term means adding an accumulate, never editing the loop.
@expect clauses play the role of Lean propositions; the kernel emits a numeric witness; a small, audited checker decides PASS in both cases. Same structural shape, different trust event — Lagra discharges a numerical obligation contingent on tolerance and integrator stability; Lean discharges a deductive one.
→ full paper: action-kernel/main.pdf · LaTeX source in paper/action-kernel/main.tex
The engine on the landing page would be three separate codebases anywhere else. Rigid bodies live in PhysX or Bullet. Molecular dynamics lives in LAMMPS or GROMACS. RNA folding lives in ViennaRNA or Rosetta. Fluids live in OpenFOAM or LiquidFun. None of them compose.
The split isn't accidental — it's the structure each tool optimised against. PhysX's contact solver assumes a contact graph, not pairwise potentials over 10⁵ particles. LAMMPS's neighbour list assumes short-cutoff non-bonded forces, not deformable continua. ViennaRNA's dynamic-programming kernel doesn't accept a force field at all. Each engine made a different cut for a different audience, and the cuts don't line up.
So adding fluids to MuJoCo means reimplementing fluids. Adding EM coupling to an RNA scene means rewriting ViennaRNA. Adding deformables to a PhysX game means swapping engines mid-pipeline. The cross-domain tax — porting, validating, re-tuning — usually exceeds the cost of the physics itself.
A Lagrangian doesn't care which subset you pick. HarmonicBond and LennardJones and QcdCoulomb are the same kind of node in the same kind of graph, evaluated by the same kernel. Choosing which terms run for a given scene becomes a scene-level declaration — not a tooling decision. The live 1000-block stack on the landing page runs on the same evaluator the LJ fluid and the pendulum chain run on. That's the whole pitch.
See the live 1000-block stack at index.html#demos — same evaluator, same scene file. uses newtonian.classical_mechanics.avbd; render "rigid_body".
.lagra files describe nodes in the graph. Like Lean for proofs, each file is a self-contained unit the compiler can check, optimise, and compose. Coarse-graining is a node choice, not an engine choice.
The scene below is the harmonic-oscillator demo from the landing page — verbatim, no shortened-for-the-website magic. Two particles, one bond, one declared invariant, one solver block:
scene solver_walkthrough_oscillator { uses newtonian.classical_mechanics description "Two-bead harmonic oscillator. Only the harmonic bond contributes nonzero force." wasm true // flag for the landing-page bundle entity { type: ball_small, position: [-1.35, 0, 0], mass: 1.0, size: 0.35 } entity { type: ball_small, position: [ 1.35, 0, 0], mass: 1.0, size: 0.35 } bond harmonic [0, 1] { k: 2.0, r0: 2.0, damping: 0.04 } @expect momentum_conservation // CI gate solver { dt: 0.002, steps_per_frame: 12 } }
The compiler checks before the kernel runs. Conservation invariants are derived from the active graph and inserted as runtime assertions — if the first step would violate them, the scene doesn't compile. Entity catalogs enforce scientific references: entity ball_small {…} in configs/entities/classical.lagra carries the citation alongside the mass, size, and color, and custom entities go through LagraDef validation against those catalogs.
Each node also owns its own optimisation hints. Pairwise terms can request a cell list; bonded terms can request a neighbour list; whole subgraphs can target a GPU compute pass. The planner reads the hints and composes the dispatch — the kernel's shape is fixed but the dispatch is per-scene.
Five independent trajectories per engine on a 256-particle Lennard-Jones liquid at ρ*=0.80, T*=1.5, run from identical Maxwell-Boltzmann initial conditions with the same dt = 0.005τLJ. Both engines run symplectic integrators (Lagra: discrete-action variational; LAMMPS: velocity-Verlet). The radial distribution function — the canonical liquid-structure observable — matches across the full r range.
Pipeline: benchmarks/qualitative_recovery/scripts/{generate_initial_conditions, run_lagra, analyze_rdf, compare_lj}.py. Raw outputs and aggregated JSON in the same directory.
22 scenes from the LAMMPS regression suite. Each row plays the actual engine output side by side — Lagra on the left, LAMMPS on the right, both at the same scene parameters. Note: the per-scene drift numbers below use the legacy bench scenes (ε=0.001 reduced-LJ units) rather than the aligned ε=1.0 set above; they're reported as raw drift, not as a parity claim. The aligned LJ result is the headline.
24 scenes from the ViennaRNA benchmark set. Vienna predicts a secondary structure via dynamic programming on the Turner-2004 free-energy table; Lagra simulates the same nucleotide system as MD with first-principles charged-base potentials. Outputs are not directly comparable (structure-prediction vs trajectory); each card shows what each engine produces. Vienna's own predictions are parameter-sensitive — the dangles sweep shows how much.
((((...)))) · MFE -3.8 kcal/mol(((...))) · MFE -1.2 kcal/mol((((....)))) · MFE -5.4 kcal/mol((((....)))) · MFE -6.4 kcal/mol.......... · MFE 0.0 kcal/mol.... · MFE 0.0 kcal/mol.... · MFE 0.0 kcal/mol.................... · MFE 0.0 kcal/mol(((....))) · MFE -2.6 kcal/mol((((...)))) · MFE -4.6 kcal/mol(((...))).((((((((....)))))))) · MFE -12.3 kcal/mol(((.((((((.(((((((....)))))))...))))))))) · MFE -23.9 kcal/mol.....((((....)))) · MFE -4.7 kcal/mol(((((((((......))))..))))).... · MFE -8.8 kcal/mol.(((((((((...((((((((((.....))))))))))...))))))))) · MFE -43.8 kcal/mol........(((..((((((....))))))..)))................. · MFE -1.7 kcal/mol((((((((((((((...)))).(((...))).((((((((((...((.((...(((..((...))..)))...)))).))))))))))..(((.(((....))))))..)))))))))). · MFE -50.9 kcal/mol(((((((..((((........)))).(((((.......))))).....(((((.......)))))))))))).... · MFE -22.4 kcal/mol((((.((((....))))..))))((.(((((.(((((((.....((((..((((..((((........))))..)))).)))).....))))))).))))).)). · MFE -34.4 kcal/mol(((((((((......))))..))))).(((((..(((((...)))))..)))))..((((...((((((....)))))).......))))...((((.((.((((((((((....)))))).)))).)).))))........... · MFE -51.3 kcal/mol(((....)))........ · MFE -3.3 kcal/mol((((((....(((....)))..))).))). · MFE -7.2 kcal/mol.......((.((((((((........)))))))).))...(((((.((((..((((((.(.(((..((.((.((((((((((....))))))).))).....)).))..))).)..)).)))).))))...)))))(((((...(.((.((.((((((....)))))).))...)).)....))))).....((......)). · MFE -50.9 kcal/mol..(((((((...(((((((....((((.((((((((.(((((((((....))))))))).(((((....))))).)))).....))))))))...)))))))..)).)))))....((((...(((((((((...)))))))))..))))(((..((((.(((((..((((.....(((((((.....)))))))....)))))))))......(((((....)))))............)))))))..... · MFE -80.1 kcal/mol20 scenes from the Rosetta benchmark set. Rosetta scores a single input pose with the REF2015 statistical energy function; Lagra runs MD on the same structure with physical force terms. Per-residue score reconstruction from Lagra's force-graph (the comparable apples-to-apples metric) is future work.



















