Add export_symplectic_model for simulation engine integration#45
Draft
johannes-spies wants to merge 1 commit into
Draft
Add export_symplectic_model for simulation engine integration#45johannes-spies wants to merge 1 commit into
johannes-spies wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
export_symplectic_model(), a utility that wraps a FlashMD model and a symplectic correction model into a singleAtomisticModelthat can be saved and loaded by LAMMPS viafix metatomic. This makes symplectic FlashMD available in simulation engines without any engine-side specialization — just load the exported.ptfile like a regular FlashMD model.How it works
The exported model runs a full symplectic step in its
forward: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:
AtomisticModelwrappers cannot be nested; the inner.moduleis stored directlyNeighborListOptionsare not serializable; stored as three parallel primitive listsLabels/TensorBlock/TensorMapcannot be constructed fresh in the forward graph; output metadata is reused from the inner model insteadCallablearguments); only the linear algebra step is shared via_anderson_updatefromfpi.pyChanges to
fpi.pyExtracts
_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
Then in LAMMPS:
Notes
metatraindependency updated to git main with a TODO to re-pin onceexperimental.flashmd_symplecticlands in a PyPI release (same approach as Add Al example for symplectic integrator #44)