Skip to content

Add export_symplectic_model for simulation engine integration#45

Draft
johannes-spies wants to merge 1 commit into
symplectic-minimalfrom
symplectic-export
Draft

Add export_symplectic_model for simulation engine integration#45
johannes-spies wants to merge 1 commit into
symplectic-minimalfrom
symplectic-export

Conversation

@johannes-spies

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

Copy link
Copy Markdown

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

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
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