Skip to content

metatomic: run models through metatomic-core - #3

Closed
EricBoittier wants to merge 9 commits into
masterfrom
plumed/core-review
Closed

EricBoittier wants to merge 9 commits into
masterfrom
plumed/core-review

Conversation

@EricBoittier

Copy link
Copy Markdown
Owner

This PR ports the METATOMIC action to metatomic-core, the new C API of metatomic. It is the cleaned-up history of plumed#1510 (left untouched), plus the per-atom gradient tests and legacy-model loading from fork PRs #1 and #2. It is rebased on current upstream master (c2a5cd1).

Commit What it does
b945c03 Split the action into a front-end and two backends: TorchBackend (the existing code) and CoreBackend (metatomic-core plugins: DLPack system, vesin pair lists, feature with explicit position/strain gradients → forces and virial, units, float32, SELECTED_ATOMS, CHECK_CONSISTENCY). Plus module.md
e1e56f9 --enable-libmetatomic-core configure check and a plugin-model regtest (rt-core)
22e762d Include <metatensor.hpp> / <metatomic.hpp> instead of the torch bindings. Rename metatomic.cpp → MetatomicAction.cpp so the header has a matching source (plumedcheck)
6541fd2 Value-initialise VesinOptions
d641a3a Test per-atom gradients; fix sample label iteration
cc4d525 Load legacy models through metatomic-core and share one Python runtime; focused Linux job (CPU wheels, shared-runtime check)

History cleanup

  • The "breaking change" commit is reworded, and its whitespace-only edit to src/tools/LinkCells.cpp is dropped.
  • The codecheck commit (just the rename) is folded into it.
  • The two CI follow-ups are folded into the legacy-model commit.
  • The merge commit is gone.
  • No Co-Authored-By trailers remain.

Diff check against the pre-rebase branch (backup/core-review):

  • In the files this branch touches, the only difference is LinkCells.cpp, plus upstream's own changes to configure, configure.ac and linuxWF.yml. This branch's added and removed lines in linuxWF.yml are unchanged.
  • Outside those files, the tree equals upstream master.

The fork's master was fast-forwarded to upstream first, so this diff shows only these commits. Not built locally: fork CI covers it.

EricBoittier and others added 6 commits October 26, 2026 10:05
Split the METATOMIC action into a front-end (MetatomicAction.h) and two
backends. The existing TorchScript code moves into TorchBackend, and the
new CoreBackend (metatomic_core.cpp) runs models through the C++ API of
metatomic-core, without torch.

CoreBackend is used as soon as PLUGIN_LIBRARY or PLUGIN is given. It
registers the plugin libraries, loads MODEL through the requested plugin,
builds a metatomic System sharing PLUMED's positions and cell through
DLPack, adds the pair lists requested by the model (computed with vesin),
and requests the `feature` output (or `feature/<VARIANT>`) with explicit
positions and strain gradients, which give the forces and the virial.
It also handles unit conversion, float32 models, SELECTED_ATOMS, per-atom
outputs and CHECK_CONSISTENCY, and rejects options it does not support
yet (extra inputs, DEVICE, EXTENSIONS_DIRECTORY).

module.md documents plugin models and how to configure PLUMED for them.
Add the --enable-libmetatomic-core configure option, which probes the
metatomic-core C++ API (metatomic::load_model / metatomic::execute_model)
and links libmetatomic and libmetatensor without requiring libtorch. It
defines __PLUMED_HAS_LIBMETATOMIC_CORE and the libmetatomic_core config key.

Add regtest/metatomic/rt-core, a two-atom distance model written as a
metatomic.NumpyModel Python script and loaded through metatomic's Python
plugin, with explicit positions and strain gradients. The second frame
crosses the periodic boundary.

Document plugin models in the METATOMIC action and the module page,
recommending Python NumpyModel scripts and linking PLUMED against the
libmetatomic shipped in the metatomic-core Python package.
…ndings

Stop including the libtorch, metatensor-torch and metatomic-torch headers
in the METATOMIC action, and include <metatensor.hpp> and <metatomic.hpp>
instead.

Rename metatomic.cpp to MetatomicAction.cpp, so that MetatomicAction.h has
a matching source file as required by plumedcheck.
`sorted` was never set, so vesin read an uninitialised bool (cppcheck
uninitvar).
Comment thread src/metatomic/MetatomicAction.cpp Fixed
Comment thread src/metatomic/MetatomicAction.cpp Fixed
EricBoittier and others added 3 commits October 26, 2026 11:14
Add the --enable-libmetatomic-core configure option, which probes the
metatomic-core C++ API (metatomic::load_model / metatomic::execute_model)
and links libmetatomic and libmetatensor without requiring libtorch. It
defines __PLUMED_HAS_LIBMETATOMIC_CORE and the libmetatomic_core config key.

Add regtest/metatomic/rt-core, a two-atom distance model written as a
metatomic.NumpyModel Python script and loaded through metatomic's Python
plugin, with explicit positions and strain gradients. The second frame
crosses the periodic boundary.

Document plugin models in the METATOMIC action and the module page,
recommending Python NumpyModel scripts and linking PLUMED against the
libmetatomic shipped in the metatomic-core Python package.

metatomic: include the metatomic-core headers instead of the torch bindings

Stop including the libtorch, metatensor-torch and metatomic-torch headers
in the METATOMIC action, and include <metatensor.hpp> and <metatomic.hpp>
instead.

Rename metatomic.cpp to MetatomicAction.cpp, so that MetatomicAction.h has
a matching source file as required by plumedcheck.

metatomic: value-initialise VesinOptions

`sorted` was never set, so vesin read an uninitialised bool (cppcheck
uninitvar).

Test per-atom gradients and fix sample label iteration

Load legacy models through metatomic-core and share one Python runtime

type mismatches in MetatomicAction.cpp, found by bot, constructor cast added as fix.
@EricBoittier

Copy link
Copy Markdown
Owner Author

Closing: staging PR, the work continues in plumed#1510.

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.

2 participants