TorchSpin: Differentiable Electron Paramagnetic Resonance Simulation in PyTorch

summary

Video file (mp4)

The gist

The gist: TorchSpin presents an open-source PyTorch framework that ports EasySpin's organization into a differentiable tensor-based environment, enabling rapid learned inference and

In short

TorchSpin is an open-source PyTorch framework that converts established EasySpin electron paramagnetic resonance (EPR) simulations into a differentiable, tensor-based format. This allows physical calculations to be used directly in machine learning workflows for rapid inference and parameter-label-free training of models, enabling spectral refinement without needing pre-labeled data.

Key concepts

TorchSpin
An open-source PyTorch framework that ports the organization and numerical conventions of the EasySpin simulation software into a tensor environment. It allows physical EPR calculations to be integrated directly with automatic differentiation for machine learning applications.
Differentiable Spectral Feedback
A method where the output of a forward physical simulation (like an EPR calculation) is used as input for a neural network's loss function. If the reconstructed spectrum doesn't match the measured one, this feedback guides both parameter estimation and model training to improve accuracy.
Parameter-Label-Free Training
The ability to train machine learning models that predict EPR parameters (like g-tensors) using only noisy experimental spectra without needing corresponding ground truth labels. TorchSpin provides the necessary spectral gradients from physical simulations to enable this type of self-supervised learning.
Cross-Engine Library Transfer
TorchSpin enables the transfer of machine learning models trained on one set of simulated EPR data (generated by TorchSpin) to work effectively with independently generated spectra from another simulation engine (like EasySpin). This shows the learned model is robust and generalizable.

Terminology used across episodes

This episode discusses

The paper

TorchSpin: Differentiable Electron Paramagnetic Resonance Simulation in PyTorch · Read on arXiv

Alec H. Follmer

Department of Chemistry, University of California, Davis · Linac Coherent Light Source, SLAC National Accelerator Laboratory

Interpreting electron paramagnetic resonance (EPR) spectra commonly requires repeated forward simulation and optimization of spin Hamiltonian parameters. Established software provides mature simulation and fitting methods, but these calculations are not generally available as differentiable components within machine-learning workflows. We present TorchSpin, an open-source PyTorch framework that ports the organization and numerical conventions of EasySpin into a tensor-based computational environment. Representative calculations spanning continuous-wave EPR, ENDOR, pulse EPR, spin dynamics, trajectory simulation, and magnetometry closely reproduced corresponding EasySpin results. In matched benchmarks, TorchSpin CPU execution was faster than EasySpin for six of nine workloads although performance depended strongly on the calculation. We therefore focused on the capabilities enabled by automatic differentiation in PyTorch. In a Cu(II) powder-spectrum demonstration, feedback propagated through TorchSpin improved the quality of a supervised convolutional neural network (CNN) without using parameter labels during refinement. Models trained from randomly initialized CNNs using only noisy spectra and TorchSpin reconstruction loss achieved median similarities of at least 0.99. CNNs trained on TorchSpin-generated libraries also transferred without adaptation to independently generated EasySpin spectra with performance comparable to EasySpin-trained controls. Once trained, the CNN produced initial parameter estimates in approximately 1 ms per spectrum while a batch of 512 was processed in approximately 1.3 ms with GPU acceleration. TorchSpin therefore provides both a tested Python implementation of established EPR calculations and a differentiable physical layer for rapid learned inference, spectral refinement, and parameter-label-free training.

Transcript

Introduction to the show: ident: AI Radio. Generated commentary on the latest Artificial Intelligence papers.

Tom: Today's paper: "TorchSpin: Differentiable Electron Paramagnetic Resonance Simulation in PyTorch".

Jane: The gist: TorchSpin presents an open-source PyTorch framework that ports EasySpin's organization into a differentiable tensor-based environment, enabling rapid learned inference and parameter-label-free training for electron paramagnetic resonance simulations.

Tom: First, who's behind it and why it matters.

Paper summary: Tom: So, we’ve covered the basic idea that TorchSpin ports EasySpin into PyTorch and makes it differentiable. The thesis is that you can connect forward calculations directly to learned parameter inference through automatic differentiation >

Jane: It seems like the core problem they are solving is that traditional simulation methods don't easily let you feed them back into a learning system where the relationship between parameters and the output signal isn't directly available through automatic differentiation >

Lu: Exactly. The distinction matters because learned spectra can’t easily be tied to physical parameters when you just have separate programs for forward simulation and fitting >

Meng: So, if you use this framework, you get a second form of training where parameters predicted from a spectrum can be returned to the physical model and disagreement between the reconstructed and measured spectra can propagate through the simulation to update either the predicted parameters or the network itself >

Lalam: This allows for spectral feedback even when you don't know what exactly your generating Hamiltonian is >

Tom: And they’ve shown this works across many different EPR regimes, including continuous-wave EPR, ENDOR, pulse EPR, spin dynamics, trajectory simulation and magnetometry >

Jane: It sounds like a comprehensive tool for working with these complex systems because it covers so much ground from different types of experiments >

Lu: They compared their calculations against independently generated EasySpin outputs using matched spin-system experimental and numerical parameters where each comparison used identical field, frequency, time or temperature axes without interpolation >

Meng: That’s a rigorous way to compare them. It means they aren't just comparing apples to oranges; they are testing the same underlying physics with different computational tools >

Lalam: For example, in the fast-motion continuous wave cw EPR spectrum calculated with garlic, it was reproduced to numerical precision with a normalized root mean square error below ten-fifteen > <ref:2610.18924#pg3,was reproduced to numerical precision with a normalized root mean square error>

Tom: That’s a concrete number. So they showed high fidelity across the board for those specific calculations >

Jane: It shows that TorchSpin isn't just a theoretical idea; they’ve actually validated it against established software and experimental setups >

Conclusion: Tom: To wrap up, "TorchSpin: Differentiable Electron Paramagnetic Resonance Simulation in PyTorch" brings representative EPR simulation methods into a differentiable PyTorch framework while keeping the organization and nomenclature familiar to EasySpin users >

Jane: The most consequential part, I think, is that supported forward calculations can participate directly in automatic differentiation >

Lu: This lets spectral disagreement refine a supervised inverse model and to train models from random initialization without parameter labels or clean spectral targets >

Meng: It’s about using the physical model as a constraint or a decoder for parameter-label-free learning, which is useful when you don't have clean training data available >

Lalam: The accompanying code, validation data, benchmarks and notebooks provide a reproducible foundation for extending this approach to additional EPR methods and importantly, for testing it against experimental spectra >

Tom: The practical value is that the forward calculation can serve as a differentiable physical constraint or a decoder for parameter-label-free learning or a generator of synthetic libraries for reusable inverse models >

Jane: It’s about bringing established simulation methods into the PyTorch environment where you can use the same physical model to generate training data evaluate predicted parameters and propagate spectral disagreement through an optimization or learning system >

More episodes

← Home