fmlip-relay#

Persistent ML potential server for Fortran clients


fmlip-relay lets a Fortran code (MD, MC, geometry optimiser) evaluate machine-learned interatomic potentials that only exist as Python packages. The Fortran client spawns a Python server per instance and talks to it over a loopback TCP socket. The model is loaded once at server startup, so every later evaluation costs a socket round trip (about 1 ms) instead of a model reload.

  • A small Fortran module (fmlip_relay_client) with a handful of routines: init, compute, Hessian, ping, finalize

  • Backends for MACE (custom, MP, OFF, POLAR), UMA, NequIP, Allegro, DeepMD, SchNet, OpenMM, and any ASE calculator

  • Up to 16 independent server instances, callable from separate OpenMP threads or MPI ranks

  • A plain binary wire protocol in Å and eV, with no dependencies on the Fortran side beyond a C compiler

┌──────────────────────────────────────────────────────────────┐
│  Fortran driver (MD, MC, geometry optimiser, ...)            │
│  use fmlip_relay_client                                      │
│    mlip_init      → spawn fmlip-relay-server, wait for READY │
│    mlip_compute   → send coords, recv energy/forces/stress   │
│    mlip_ping      → liveness check                           │
│    mlip_finalize  → send QUIT, stop the process              │
└────────────────────────────┬─────────────────────────────────┘
                             │  127.0.0.1:PORT  (binary TCP)
                  ┌──────────┴──────────┐
                  │  fmlip-relay-server │
                  │  server.py          │  ← protocol + event loop
                  │  backends/*.py      │  ← model loaded once at startup
                  └─────────────────────┘

Quick start#

Install the Python server and build the Fortran/C client library:

pip install .                 # core: dummy and Lennard-Jones backends
pip install ".[mace]"         # or another backend extra, e.g. uma, nequip, deepmd

cmake -S . -B build -DBUILD_EXAMPLE=ON
cmake --build build
./build/example/run_example lj        # spawns servers, runs a few evaluations, shuts down

Check a backend without any Fortran code:

fmlip-relay-check                                      # which backends work in this environment
fmlip-relay-server --backend mace_mp --test mol.xyz    # one single-point evaluation, then exit

From Fortran, the whole life cycle is three calls:

use fmlip_relay_client

integer  :: ierr, pbc(3), atomic_numbers(64)
real(8)  :: pos(3,64), cell(3,3), energy, forces(3,64), stress(3,3)

!>-- spawn the server, blocks until the model is loaded
call mlip_init(1, 54321, &
    "fmlip-relay-server --port 54321 --backend mace --model /path/model.model", &
    60, ierr)

!>-- evaluate as often as needed (Å in, eV, eV/Å, eV/ų out)
pbc = [1, 1, 1]
call mlip_compute(1, 64, atomic_numbers, pos, cell, pbc, 1, &
                  energy=energy, forces=forces, stress=stress, ierr=ierr)

!>-- shut the server down
call mlip_finalize(1, ierr)

Where to go next#

  • Installation covers the Python package, the backend extras, and the Fortran/C library.

  • Fortran client documents the routines of fmlip_relay_client and how to run several instances in parallel.

  • Server describes fmlip-relay-server, its single-point test mode, and every command-line option.

  • Backends lists the supported models and what each one needs.

  • Wire protocol gives the byte layout, in case you want to write a client in another language.