Skip to content

Add export_symplectic_model for simulation engine integration#45

Draft
johannes-spies wants to merge 19 commits into
mainfrom
symplectic-export
Draft

Add export_symplectic_model for simulation engine integration#45
johannes-spies wants to merge 19 commits into
mainfrom
symplectic-export

Conversation

@johannes-spies

@johannes-spies johannes-spies commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces export_symplectic_model(), a utility that wraps a FlashMD model and a symplectic correction model into a single AtomisticModel that can be saved and loaded by LAMMPS via fix metatomic. This makes symplectic FlashMD available in simulation engines without any engine-side specialization — just load the exported .pt file like a regular FlashMD model.

How it works

The exported model runs a full symplectic step in its forward:

  1. Calls the FlashMD model for an initial guess of the next positions/momenta
  2. Refines it via an Anderson-accelerated midpoint fixed-point iteration, using the symplectic correction model at each midpoint estimate

Neighbor lists from the input system are reused at midpoint positions (valid as long as positional changes stay within the neighbor list skin — the same assumption LAMMPS already makes).

TorchScript compatibility

Several constraints arise from needing the module to be TorchScript-serializable:

  • AtomisticModel wrappers cannot be nested; the inner .module is stored directly
  • NeighborListOptions are not serializable; stored as three parallel primitive lists
  • Labels/TensorBlock/TensorMap cannot be constructed fresh in the forward graph; output metadata is reused from the inner model instead
  • The Anderson loop is inlined (TorchScript cannot take arbitrary Callable arguments); only the linear algebra step is shared via _anderson_update from fpi.py

Changes to fpi.py

Extracts _anderson_update() as a @torch.jit.script-decorated function containing the core Anderson step linear algebra. anderson_solver() now delegates to it, eliminating duplication between the Python-facing solver and the TorchScript forward pass.

Usage

from metatomic.torch import load_atomistic_model
from flashmd import export_symplectic_model

flashmd_model = load_atomistic_model("flashmd.pt")
symplectic_model = load_atomistic_model("symplectic-correction.pt")
exported = export_symplectic_model(flashmd_model, symplectic_model)
exported.save("symplectic-flashmd.pt")

Then in LAMMPS:

fix 0 all metatomic symplectic-flashmd.pt types 13

Notes

johannes-spies and others added 2 commits May 19, 2026 14:34
Pass model=(flashmd_model, (symplectic_model, config_dict)) to use the
fixed-point midpoint-rule integrator instead of plain FlashMD. The plain
single-model API is completely unchanged. Works in both i-PI and ASE
(VelocityVerlet, Bussi, Langevin).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduces export_symplectic_model() in src/flashmd/export.py, which
wraps a FlashMD model and a symplectic correction model into a single
AtomisticModel that can be saved and loaded by LAMMPS via fix metatomic.

The exported model runs the FlashMD initial guess followed by an
Anderson-accelerated midpoint fixed-point iteration (inlined for
TorchScript compatibility) using the symplectic correction model.

Also extracts _anderson_update() from fpi.py as a @torch.jit.script
function so the linear algebra is shared between the Python-facing
anderson_solver() and the TorchScript forward pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@johannes-spies johannes-spies changed the title Add export_symplectic_model for LAMMPS via fix metatomic Add export_symplectic_model for simulation engine integration May 19, 2026
@johannes-spies
johannes-spies marked this pull request as draft May 19, 2026 18:02
johannes-spies and others added 17 commits May 20, 2026 11:51
The `._nl.algorithm = "cell_list"` workaround guards against a vesin
CUDA bug with triclinic cells (vesin#157), but accesses a private
attribute. It was not present in the original PR#32 design, and
verified to be unnecessary on CPU (the only target for now).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allow passing the symplectic model directly as the second tuple element,
without wrapping it in a (model, config) pair. Defaults to empty config.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
VelocityVerlet assumed the symplectic model was always passed as
(model, config); passing just a plain model crashed with TypeError.

Also adds pytest filterwarnings for torch.jit and metatomic 0.1.12+
deprecations (renamed output names/quantities) that now surface with
newer dependency versions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extend get_pretrained() with symplectic=True to download and export
the symplectic FlashMD checkpoint from HuggingFace. Add tests covering
both the plain-model and (model, config) tuple API.

Metatrain is pinned to the git HEAD for now since
experimental.flashmd_symplectic is not yet in a released version.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pin metatrain to 2026.2.1 in pyproject.toml. In get_pretrained, check
the mtt export return code and give a helpful error if the
experimental.flashmd_symplectic architecture is missing. Override
metatrain with a pinned metatensor/metatrain commit in CI so the
symplectic tests can actually run the export.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
warp-lang>=1.14.0 deprecated warp.config.quiet, which is used by
nvalchemi-toolkit-ops==0.3.0. Suppress it so pytest's filterwarnings
error mode doesn't turn it into a failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The existing filter only matched APICLaunchParamRecord; warp-lang 1.14.0
triggers the same warning for other ctypes structures (e.g.
APICLaunchPtrLocation) on Python 3.14. Use .* to suppress all of them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Validate that the symplectic correction model's timestep matches the
FlashMD model's in SymplecticStepper, covering both the i-PI and ASE
paths. Add a test pairing mismatched-timestep models.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
metatrain 2026.3 ships the experimental.flashmd_symplectic architecture,
so the temporary measures for symplectic support are no longer needed:

- Pin metatrain==2026.3 and remove the git-override step in the tests CI.
- Drop the "install a compatible metatrain" fallbacks in get_pretrained;
  export failures now surface the real error directly.

The newer ASE pulled in by the bump deprecates MaxwellBoltzmannDistribution,
so migrate the README and tests to thermalize_momenta (ASE >= 3.29) and
filter the NumPy 2.5 shape-setting deprecation raised inside ASE.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The 2026.3.1 release includes the symplectic requested_inputs fix
(metatrain PR #1174), so test_symplectic.py now passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Base automatically changed from symplectic-minimal to main July 1, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant