Design notes

These notes record the design decisions taken before implementation.

Execution model

Each task runs its unmodified ASE code in its own worker thread, with a proxy calculator attached to every structure it evaluates. When the task requests energies or forces for a state that has no current result, the proxy submits a request and blocks. The scheduler waits until every running task is blocked or finished, evaluates all pending requests in one batched call per model, delivers the results, and resumes the tasks.

This handles algorithms that evaluate more than once per step: line-search optimizers, velocity-Verlet and Langevin integrators that request forces at the new positions inside step(), and NEB options that move images while computing forces. A lockstep design that evaluates only between steps, as in the Symmetrix relax_batch and neb_batch prototypes and MatterSim’s BatchRelaxer, rejects those cases.

Python step logic runs under the GIL, but it is short compared with the batched evaluation. Its per-structure cost (a fraction of a millisecond per step) sets a floor that matters for structures of a few tens of atoms on a GPU and must be measured.

Batched workflows

A task blocks on one request at a time, so a workflow that evaluates its structures one after another contributes one structure per round. Workflows whose evaluations are independent of each other (displaced supercells for force constants, scaled cells for an equation of state, trial configurations of Monte Carlo replicas) instead submit them together with TaskContext.evaluate, which places all structures in one request. A single workflow then fills a batch on its own, and several such workflows share rounds as before.

Swap Monte Carlo evaluates one trial swap per replica per step, so the batch size equals the number of temperatures. Proposals are uniform over unlike pairs of sites, which is symmetric at fixed composition, and the Metropolis and replica-exchange tests use energies only. Positions stay on the input lattice. Relaxed-lattice sampling would need one relaxation per trial and is not implemented.

Scheduling

  • A per-model budget in atoms or edges bounds each batched call; requests beyond the budget wait for the next round.

  • Finished tasks are replaced from the submission queue, so batches stay full instead of shrinking as relaxations converge.

  • Tasks can be submitted from any thread while run is active, and run(until=..., on_result=...) serves a stream of submissions and reports each result as its task finishes.

  • A round waits until every running task has a pending request, which maximizes the batch but lets Python work in one task delay the others. round_timeout starts a round once its first request has waited that long, and later rounds skip the tasks that missed it until they submit again; waiting_on() reports the tasks a round waits for.

  • The context holds its calculators weakly, and the scheduler drops a task’s Sources when it finishes, so per-trajectory backend state is released as soon as nothing uses it. batch_log keeps a bounded number of recent calls and batch_totals counts all of them.

  • Results equal those of independent runs to rounding, because every request is evaluated exactly at the state the task asked for (see Reproducibility).

Backends

A backend maps a list of ASE Atoms to a list of results (energy, forces, and optionally stress, energies). Requests are grouped by model, because one batched call evaluates one set of weights.

  • Symmetrix: one disconnected neighbor graph per call. atombatch.symmetrix builds the joined graph and calls the evaluator directly, using only evaluator calls present in Symmetrix-XL 0.1.1, and reduces per-structure stresses natively where the evaluator can, otherwise from the pair forces in NumPy. Requests carry the identity of the calculator that made them (Atoms.info['atombatch_source']), and the graph path keeps one Symmetrix neighbor cache per source, so that neighbor lists are rebuilt only when atoms move beyond the neighbor skin, as in the Symmetrix ASE calculator. Symmetrix-XL 0.2 uses these source keys to combine the trajectories into one prepared segment group: positions are streamed to the device, and the edge geometry and the force and stress reductions stay there. Trajectories on a shared calculator then get a wider candidate graph (joined_neighbor_skin, at least 1 Å), which does not change the model cutoff. Results agree with the Symmetrix ASE calculator to rounding, and bit for bit with a calculator that uses the same neighbor skin. Symmetrix.calculate_batch, which no Symmetrix-XL release provides, is used only for calculators without the evaluator interface. Only families whose energy is a sum over local graphs (GRAPH_FAMILIES: standard MACE and MACE-MH-1) are joined. Long-range families (MACE-POLAR-1, MACELES), field-coupled models, and calculators with dispersion corrections are not joined, because a joined graph would evaluate them wrongly. MACE-POLAR-1 requests go to Symmetrix.calculate_polar_batch where Symmetrix provides it, which evaluates each structure with its own long-range program inside shared native calls; the others fall back to sequential evaluation. Properties beyond energy, forces, and stress, such as the MACE-POLAR-1 dipole, are passed to the backend, and graph-level inputs in Atoms.info (total_charge, total_spin, fermi_level, electric_field) are part of a request’s state.

  • TorchSim: one ModelInterface call on a SimState joined from the structures, with energies, forces, and 3x3 stresses split back per structure and stresses converted to Voigt order. TorchSim maintains batched interfaces for MACE, fairchem, SevenNet, ORB, MatterSim, NequIP, Nequix, and metatomic, so one adapter covers those packages. Its stress follows the ASE sign convention. The model must be constructed with compute_stress=True for tasks that read stress.

  • Function: a user callable with the backend signature, for models whose batched inference TorchSim does not wrap.

  • Generic ASE calculator: sequential evaluation behind the same interface. It provides scheduling and refill but no batching speedup. The ASE Calculator interface evaluates one Atoms per call, and periodic structures with different cells cannot be joined into one Atoms, so batching requires access below the calculator to the model’s own batched input.

  • Further native backends (bypassing TorchSim) are added one at a time, each validated against that model’s own ASE calculator.

Reproducibility

Batched results agree with independent runs to floating-point rounding, and bit for bit when the model itself evaluates deterministically. The last bits of a model’s forces vary from call to call when it reduces them in parallel: Symmetrix-XL with several OpenMP threads or on a GPU accumulates edge contributions in an order that changes between calls, also for its own ASE calculator. A structure’s forces can then differ in their last bits (typically 1e-15 to 1e-14 eV/Å in FP64) with the other structures in its batch, so a batched MD trajectory is replayed bit for bit only with the same batch-mates, and in general not even then. The atomic energies are not affected.

Measured in FP64 on 135-atom SrTiO3 cells, one structure alone against the same structure inside a batch of 32, with MACE-MP-0b medium for Symmetrix-XL 0.1.1 on CPUs and MACE-OMat-0 medium otherwise:

Symmetrix-XL build

alone vs in batch

alone, call to call

Linux CPU, 0.1.1, OMP_NUM_THREADS=1

bitwise equal

bitwise equal

Linux CPU, 0.1.1, 16 threads

up to 9e-15 eV/Å

varies

macOS CPU (M1 Max), 0.1.1 and 0.2

bitwise equal

bitwise equal

NVIDIA RTX 4090, 0.1.1 and 0.2

up to 2.4e-14 eV/Å

up to 5e-15 eV/Å

For bitwise reproducible trajectories, run the model deterministically, for example Symmetrix on a CPU with OMP_NUM_THREADS=1; batched results are then bitwise independent of the batch-mates.

Validation

  • Every task type is compared with an independent ASE run of the same algorithm: identical step counts and positions to rounding in FP64.

  • Mixed batches (relaxation, NEB, MD, single points in one run), refill, budgets, and error propagation from a failing task are tested with ASE’s EMT calculator, which needs no MLIP.

  • Workflows are compared with sequential evaluation of the same structures (force constants from phonopy and phono3py, EOS fits). Swap Monte Carlo is checked against exact Boltzmann populations of a lattice model small enough to enumerate.

  • Performance is reported in us/atom against batch size, with atom counts, model cutoff, and edge counts.