Bayesian Optimisation for Automated Nuclear Magnetic Resonance Shimming

Jashvir Rathore, Han Hao, Mikkel Jordahn, John Willes, Gary Tom, Jasper Snoek, Varinia Bernales, James Harrison, Alan Aspuru-GuzikAI4Mat @ NeurIPS 2026

TL;DR

SHIMBO automates "shimming"—the finicky process of tuning magnetic fields in Nuclear Magnetic Resonance (NMR) spectrometers—using Bayesian Optimisation with Variational Bayesian Last Layer (VBLL) neural networks. Tested live on a 60-MHz bench-top NMR machine, it matches human experts on static samples in under an hour and, crucially, adapts on the fly to drifting lab conditions and changing samples in continuous-flow experiments.

What Problem Does This Paper Address?

NMR spectroscopy is one of chemistry's most powerful tools for figuring out molecular structures and monitoring reactions. But there is a catch: to get a clean, readable spectrum, the magnetic field hitting the sample must be extraordinarily uniform. Achieving this requires shimming—iteratively adjusting dozens of small corrective magnetic coils to cancel out field inhomogeneities.

In modern self-driving laboratories (SDLs), compact bench-top NMRs are popular because they are cheap and small. However, their permanent magnets are far more sensitive to temperature swings and vibrations than superconducting high-field magnets. Worse, their 64 shim coils are physically crammed together, meaning their effects are correlated and cannot be tuned one by one.

In flow NMR, where a reacting mixture continuously moves through the spectrometer, the sample's magnetic susceptibility and the lab environment are both constantly shifting. Static shimming presets quickly go stale, creating a major bottleneck for fully autonomous chemical discovery.

Methods

The authors frame shimming as a black-box optimisation problem over a 64-dimensional discrete space ([-2^15, 2^15 - 1]^64) and introduce SHIMBO:

  • VBLL Surrogates: Instead of standard Gaussian Processes (GPs), SHIMBO uses Variational Bayesian Last Layer (VBLL) neural networks with Multi-Layer Perceptron (MLP) backbones. These naturally learn the physical correlations between the 64 shim coils.
  • Batched Exploration & Trust Regions: To search the 64D space efficiently, SHIMBO uses batched qLogEI acquisition (via BoTorch) alongside multiple trust regions to encourage diverse sampling.
  • Hardware Constraints: Not every 64-coil setting can be physically supplied by the spectrometer's digital-to-analogue converter. Because this validity region has no closed-form equation, SHIMBO uses an offline-trained binary classifier p(c|x) to steer the acquisition function away from infeasible settings.
  • Continual Flow Adaptation: For flow NMR, SHIMBO uses a sliding data window (500 minutes) to phase out stale observations as the sample or environment drifts.
  • Spectral Objectives: Depending on the sample, SHIMBO maximises either inverse full-width half-max (1/FWHM) or negative spectral entropy.

Datasets

No simulated or pre-existing benchmark datasets were used—every experiment was run live on a single 60-MHz bench-top NMR spectrometer:

  • Static samples: Pure water (H2O), a DMSO/H2O mixture, and aqueous caffeine.
  • Flow NMR: A 40-hour run on fully dissolved caffeine (with deliberate perturbations to test recovery) and a 65-hour run with active caffeine dissolution (using tBuOH as an internal standard).

Key Insights and Ideas

  • You have to tune all 64 coils together: Ablations on water show that optimising any subset of the 64 shims consistently underperforms joint optimisation.
  • Batching and multiple trust regions are essential: Unbatched (q = 1) optimisation and single trust regions perform significantly worse than batched (q = 8, 16, 32) and multi-region (m = 4, 8, 16) setups.
  • VBLLs beat GPs on CPU: While ensemble surrogates perform best overall, they require GPUs. Among CPU-practical models, a single VBLL consistently outperforms a GP in both sample and time efficiency.
  • Forgetting is a feature in flow NMR: Keeping the full observation history slows recovery after perturbations. A 500-minute sliding window lets SHIMBO adapt quickly to non-stationary samples.

Key Results

  • Static Shimming: Within a practical 1-hour wall-clock budget, SHIMBO sharpens every peak from a stale initial shim—matching an experienced experimentalist on water and successfully shimming multi-peak DMSO/H2O and caffeine spectra.
Figure 1: NMR spectra before and after SHIMBO optimisation. Each panel overlays the spectrum obtained under the stale, previously optimal configuration (initial shim) against the best spectrum found by SHIMBO , for (a) water, (b) a DMSO/water mixture, and (c) aqueous caffeine. Peak assignments are shown with the unlabeled peak in (b) and (c) from water. Despite the increasing number of peaks from (a) to (c), SHIMBO sharpens every peak relative to the stale initial shim.
  • Surrogate Comparison: Across water, DMSO/H2O, and caffeine, VBLL outperforms GP, while the VBLL ensemble achieves the highest overall objective values.
Figure 2: Surrogate model comparison for static-sample shimming. (a–c) Best objective value found so far as a function of wall-clock time, for GP, VBLL, VBLL ensemble and MLP ensemble surrogates on (a) water (1/FWHM), (b) DMSO/water (1/FWHM of the water peak) and (c) aqueous caffeine (negative spectral entropy); shaded regions show 95% CI across seeds. (d–f) Final spectrum obtained by the median-seed run of each surrogate for the corresponding sample in (a–c).
  • Flow NMR: In the 65-hour active dissolution run, sliding-window SHIMBO accurately tracks the per-proton integral ratio of two closely spaced caffeine peaks (3.208 and 3.376 ppm) relative to tBuOH. In contrast, a fixed initial shim underestimates the dissolution rate throughout the entire experiment.

Limitations and Future Work

  • Compute vs. Performance Trade-off: Ensemble surrogates (VBLL ensemble and MLP ensemble) deliver the strongest performance, but they are impractical to run without GPU resources, leaving the single VBLL as the best CPU-only option.
  • Hardware Scope: All experimental validation was performed on a single 60-MHz bench-top NMR spectrometer; broader testing across other spectrometer architectures is not discussed in the paper.

Summary updated

BibTeX
@inproceedings{rathore2026bayesian,
  author = {Jashvir Rathore and Han Hao and Mikkel Jordahn and John Willes and Gary Tom and Jasper Snoek and Varinia Bernales and James Harrison and Alan Aspuru-Guzik},
  title = {{Bayesian Optimisation for Automated Nuclear Magnetic Resonance Shimming}},
  booktitle = {AI4Mat @ NeurIPS},
  year = {2026},
  url = {https://openreview.net/forum?id=SmjcDNoISg},
}

Loading related content...

Figure