Skip to content

Run the ML potentials and EMLE as torch forces, without Sire - #40

Open
JMorado wants to merge 4 commits into
mainfrom
feature/torch-forces
Open

JMorado wants to merge 4 commits into
mainfrom
feature/torch-forces

Conversation

@JMorado

@JMorado JMorado commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

The ML potentials and EMLE run as openmm-torch forces in OpenMM, without Sire. ANI-2x and EMLE replay CUDA graphs, so no Python runs at each step.

Replaces #39.

Needs emle-engine with PME (chemle/emle-engine#133). CI and environment.yaml pin the same commit of it until it is merged.

Changelog:

  • Changed: EMLEPotential runs as a torch force with PME, without Sire. Its lambda is a global parameter, so EMLE windows can share one Context.
  • Added: ANI and the combined ML and EMLE models run as torch forces, in CUDA graphs. PythonTorchForce can use torch.compile.
  • Added: OpenMM can share PyTorch's CUDA context (opt-in, FES_ML_SHARED_CUDA_CONTEXT).
  • Changed: ML terms are scaled without a CustomCVForce, and windows that share a Context reuse the torch energies.
  • Changed: type hints and NumPy docstrings for all code, checked by ruff and mypy. The commands are in a cli package.
  • Removed: the ChargeTransfer modification, the EMLE options of the Sire path, and code nothing used.

EMLEPotential is one openmm-torch force. With periodic boxes EMLE uses PME (emle-engine pull request 133, pinned). Lambda is a global parameter, so EMLE windows can share one Context.
ANI and the combined ML and EMLE models run as torch forces. ANI-2x and EMLE replay a CUDA graph, PythonTorchForce can use torch.compile, ML terms are scaled without a CustomCVForce, and windows that share a Context reuse the torch energies. OpenMM can share PyTorch's CUDA context (opt-in).
A PythonTorchForce replays its CUDA graph from C++ when OpenMM and PyTorch share the CUDA context. The torch forces live in one private package. Code nothing uses, the ChargeTransfer modification and the python mode are removed.
All code has type hints and NumPy docstrings, checked by ruff and mypy. The scaled MM terms are in ml_interpolation.py, with one loop for all force types. The commands are in a cli package.
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml
   __init__.py12283%28, 32
   analysis.py1304962%46, 51, 72, 97, 122, 143–146, 159, 191–196, 221, 224, 226–230, 244, 246, 250, 289, 292, 294, 296, 326, 331, 333–338, 365–377
   checkpoint.py51296%129, 150
   fes.py3562693%155–156, 160–163, 178, 437, 457, 471, 667, 669, 717, 722, 763–766, 802–805, 808, 850, 892, 898, 963
   log.py31584%59, 103–104, 107–108
   mts.py621379%70, 72, 75, 77, 123–129, 132, 158
   output.py61493%107–108, 111–112
   protocol.py3685585%190–191, 202–203, 257, 286, 322, 325, 424, 433, 462–463, 468, 470, 519, 544, 551, 563, 568–569, 572, 576, 585–586, 592, 599–600, 609, 611, 618, 621, 625, 627, 644, 684–686, 688, 757–758, 796, 816, 826, 904–921, 938–946
   provenance.py1221191%97, 102, 122, 161, 237–240, 343, 348, 367
   sampling.py129993%95–96, 103, 106, 131, 135, 163, 244–245
   utils.py481569%108–128
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml/_torch
   cuda.py18712832%91, 104–114, 132–164, 187–209, 219–226, 243–247, 268–271, 285–287, 309–314, 339, 368, 387–405, 418–427, 444–462
   force.py16912526%73, 83–90, 143–150, 154–160, 164–167, 171–174, 192–197, 215–234, 252–258, 276–304, 308–315, 342–361, 377–382, 404–410
   models.py1133866%61, 90–92, 125–127, 167–171, 191, 199, 207, 215, 223, 314–338, 358–360, 368, 376, 384, 392
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml/alchemical
   alchemical_factory.py32488%57, 63–64, 94
   alchemical_state.py31681%64, 66, 68, 70, 72, 74
   alchemist.py217399%127, 292, 515
   groups.py31294%93–94
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml/alchemical/modifications
   base_modification.py1131091%211, 260, 286–289, 320, 334, 351, 374, 418
   charge_scaling.py39392%85, 87–88
   custom_lj.py422736%78–148
   emle_potential.py135795%214, 216, 221, 231, 238, 243, 289
   intramolecular.py165995%105–111, 137, 262
   lj_softcore.py95397%82, 113, 198
   ml_base_modification.py462546%108–140
   ml_correction.py291355%61–81
   ml_interpolation.py1102577%76, 89–107, 131–133, 234, 238
   ml_potential.py1052180%45, 48–52, 100–101, 194–208, 262–263
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml/alchemical/strategies
   __init__.py9367%40–42
   base_strategy.py162796%72, 119, 209, 234–235, 247, 443
   openff_strategy.py2152150%3–666
   sire_strategy.py61789%63, 69, 90–94
/home/runner/micromamba/envs/gha-test-env/lib/python3.12/site-packages/fes_ml/cli
   analyse.py312519%29–52, 64–65, 69
   main.py49982%51, 69, 72, 92–96, 100
TOTAL356390675% 
Tests Skipped Failures Errors Time
354 17 💤 3 ❌ 0 🔥 4m 30s ⏱️

This branch has not been deployed

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