Abstract
We introduce TorchSim, an open-source atomistic simulation engine tailored for the Machine Learned Interatomic Potential (MLIP) era. By rewriting core atomistic simulation primitives in PyTorch, TorchSim can achieve orders of magnitude acceleration for popular MLIPs. Unlike existing molecular dynamics packages, which simulate one system at a time, TorchSim performs batched simulations that efficiently utilize modern GPUs by evolving multiple systems concurrently. TorchSim supports molecular dynamics integrators, structural relaxation optimizers, both machine-learned and classical interatomic potentials (such as Lennard-Jones, Morse, soft-sphere), batching with automatic memory management, differentiable simulation, and integration with popular materials informatics tools.
Introduction
In computational materials science, molecular dynamics (MD) and structural relaxation are essential for simulating atomic interactions. While Machine Learned Interatomic Potentials (MLIPs) have revolutionized the field by providing near-quantum accuracy at low cost, they face a significant hardware-software mismatch. Traditional simulation packages like LAMMPS or ASE were designed for serial CPU execution. When running modern MLIPs on small systems (e.g., dozens of atoms) using these tools, high-performance GPUs like the NVIDIA H100 remain largely idle, often utilizing less than 1% of their compute capacity. TorchSim addresses this by enabling concurrent simulation of hundreds of systems.
Methods: Native PyTorch Implementation and AutoBatching
TorchSim achieves high hardware utilization by rewriting core atomistic simulation primitives natively in PyTorch. The central innovation is AutoBatching, which allows the engine to evolve multiple independent molecular systems simultaneously.
Because MLIP memory consumption varies unpredictably based on atom counts and neighbor lists, TorchSim employs an empirical memory management strategy. It iteratively tests larger batches to find the hardware's Out-Of-Memory (OOM) limit dynamically.
Two primary batching strategies are supported:
- BinningAutobatcher: Groups systems for fixed-length simulations using a 1D bin-packing algorithm.
- InFlightAutobatcher: Dynamically manages variable-length simulations (e.g., geometry relaxation) by swapping in new systems from a queue as others converge, maintaining peak GPU saturation.
Key Results
Benchmarking against the Atomic Simulation Environment (ASE) demonstrates that TorchSim provides massive performance gains, particularly for small-to-medium systems. For the MACE model, TorchSim achieved up to a 100x speedup over serial execution.
As individual system sizes increase to fill the GPU memory, TorchSim's performance naturally converges with traditional serial tools, indicating minimal overhead. Furthermore, TorchSim successfully saturated high-end hardware, packing up to 22,000 atoms into single batches for models like MatterSim.
Differentiability and Future Outlook
By building entirely within PyTorch, TorchSim makes the entire simulation trajectory fully differentiable. This enables new training paradigms where MLIPs can be optimized directly against macroscopic physical observables via backpropagation through the simulation. Future development will focus on multi-GPU support, deeper integration with advanced workflows like Nudged Elastic Band (NEB), and leveraging torch.compile for further performance optimization.
Summary updated