    Counting atoms faster: policy-based nuclear magnetic resonance pulse sequencing for atomic abundance measurement

time to relax to its initial state. This is a problem if the          environment. During this phase, the agent learns to replicate
experiment is to be repeated many times in order to suppress          the time-dependent behavior of the standard pulse sequence.
measurement noise, suggesting the need for a second policy
                                                                      Once pre-training is complete, the neural network weights
which can accelerate the sample’s return to equilibrium. We
                                                                      are transferred to the underlying network of the PPO agent.
address this concern in Experiment 3.2.
                                                                      The agent is then trained for 5M timesteps in the environ-
                                                                      ment, following the same procedure used in the baseline
3.1.1. T RAINING WITH INCREASING NOISE
                                                                      experiment detailed in Section 3.1. This approach allows
To understand the impact of increased noise on model ef-              the agent to refine the standard 1D NMR pulse using our
ficacy, we modify the training procedure by progressively             reinforcement learning framework. Interestingly, the policy
increasing the instrument noise profile applied to the ob-            converged rapidly, within the first 300K timesteps, which
served magnetizations. The training begins with an insub-             suggests that the 1D NMR pulse may be a local minimum
stantial noise profile, allowing the model to initially focus         for the loss function.
on learning how its actions affect the spins without being
                                                                      This model proved to be the most effective among our three
hindered by noise. Every 500k timesteps, the noise level is
                                                                      chirping models. As shown in Figure 1, it achieves a sub-
multiplied by a factor of 10. This gradual increase in noise
                                                                      stantial increase in achieved magnetization, particularly in
continues until the final 500k timesteps, at which point the
                                                                      higher concentration samples. This suggests that leveraging
noise profile is identical to that under which the model in
                                                                      the structured prior of the 1D NMR pulse sequence provides
the baseline Experiment 3.1 is trained. This staged approach
                                                                      a strong initialization, allowing the model to refine its policy
introduces the agent to increasingly challenging conditions
                                                                      more efficiently and exploit domain-specific patterns that
over time, while also preventing it from being overwhelmed
                                                                      improve performance.
by noise in the early stages. We find that this increased
noise did not meaningfully change the capabilities of the
                                                                      3.2. Model 2: Accelerated Spoiling
learned policy at achieving a high magnetization, compared
to the standard procedure used in Experiment 3.1. This                The standard 1D NMR pulse sequence alternates between
indicates that the model is either inherently robust to noise         applying a sinusoidal pulse and allowing the system to re-
variations or that the later stages of training, where noise          set (i.e. not pulsing at all) during a fixed period. This
levels match those in Experiment 3.1, dominate the learned            ensures that the system resets to the equilibrium state, so
policy. Consequently, our findings suggest that while pro-            that repeated pulses (or scans) can generate statistically-
gressive noise increases may prevent early instability, it does       independent samples of the same signal. The effect of
not meaningfully improve final performance.                           repeated measurement is to suppress noise at a rate pro-
                                                                      portional to √1n , where n is the number of scans. While this
3.1.2. D IRECT OPTIMIZATION OF STANDARD 1D NMR                        conservative approach ensures accuracy, it is time-intensive.
       PULSE SEQUENCE                                                 An approach known as spoiling can be employed to more
In this experiment, we initialize the agent with a pre-trained        quickly nullify residual transverse magnetization (Jehenson
policy derived from from the standard 1D NMR pulse se-                & Bloch, 1991).
quence. This approach leverages the structure and known               In this experiment, we learn an accelerated spoiling policy.
efficacy of the standard pulse sequence as a prior, rather than       The MDP is the same as in Experiment 3.1, but the reward
starting from scratch. By doing so, we seek to understand             at any timestep t is modified to
whether features of existing approaches can be exploited to
                                                                               2      2                  2      2
design effective pulse sequences by reinforcement. The pro-            rt = −(Mx,t + My,t ) − 1[t = T ](Mx,T + My,T ). (2)
cess we apply here is analogous to the design of so-called
“soft” NMR pulses, which are slight deformations of the               This reward penalizes the model for the current transverse
standard or “hard” pulses (Brüschweiler et al., 1988).               magnetization at any step t, as well as the final transverse
                                                                      magnetization at the end of the episode.
To pre-train the model, we employ behavior cloning using
the imitation learning framework from the Stable-Baselines3           We find that the learned spoiling policy is highly effective
library (Raffin et al., 2021). Observation-action sequences           at rapidly reducing transverse magnetization by actively dis-
are generated by choosing the actions determined by apply-            persing the spins from the transverse plane, which is how
ing the 1D NMR pulse sequence to the NMR environment,                 the agent receives the system state after the chirp. Com-
where the observations are determined by the state of the             pared to the standard method of simply applying no pulse,
system, and the actions are the pulse values dictated by              our approach achieves an up to 28% reduction in average
the standard pulse sequence. The model is trained for 50K             magnetization over the evaluation period. This effect can be
epochs, with each epoch consisting of 2,048 timesteps in the          visualized in Figure 2, where the policy outperforms passive
                                                                      relaxation in driving the system to lower magnetization.

                                                                  5
