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

A. Bloch equations
The Bloch equations describe the time evolution of magnetization observed in an NMR system. The relevant variables are:

                                                               ⃗.
   • Mx , My , Mz , the components of the magnetization vector M

                                                                  ⃗
   • Bx , By , Bz , the components of the external magnetic field B.

   • γ, the nuclear spin’s gyromagnetic ratio.

   • T1 , the longitudinal (spin-lattice) relaxation time.

   • T2 , the transverse (spin-spin) relaxation time.

   • M0 , the equilibrium magnetization.

The corresponding system of coupled differential equations is:

                                             dMx                       Mx
                                                 = γ(My Bz − Mz By ) −    ,                                                   (4)
                                              dt                       T2
                                             dMy                       My
                                                 = γ(Mz Bx − Mx Bz ) −    ,                                                   (5)
                                              dt                       T2
                                          dMz                       Mz − M0
                                              = γ(Mx By − My Bx ) −         .                                                 (6)
                                           dt                          T1

B. Policy architecture and supporting information
Here, we outline the structuring of the Markov Decision Process (MDP) and the architecture of the Proximal Policy
Optimization (PPO) agent as implemented in Stable-Baselines3 (Raffin et al., 2021). The parameters of the policy network
and the training pipeline are contained in Algorithms 1 and 2.
In this work, we structured our problem statement to employ a Markov Decision Process (MDP), a standard formalism for
decisionmaking under uncertainty which is frequently applied in the context of reinforcement learning. An MDP is defined
by the tuple (S, A, Πsa , r, Γ), with:

   • S: the set of possible states the system can occupy.
   • A: the set of possible actions the agent can take. The system (S, A) is termed the environment, and it evolves with
     transition probabilities P(s|s′ , a), which define the probability of that the environment evolves to state s after action
     a is taken in state s′ . In this paper, the transition probabilities effectively reduce to delta functions when we disable
     Johnson-Nyquist noise, because the Bloch equations are deterministic.
   • Πsa : the policy which determines the agent’s behavior to manipulate its environment. While deterministic policies are
     possible, in our case the policy is randomly distributed and modeled with parameters θ as Πsa = P(a|s) ∼ πθ (a|s). 4
   • r(s, a): the reward function which maps each state-action pair to a scalar signal indicating the desirability of the state
     with respect to a specified metric. The agent’s policy is trained to maximize this reward. Note that the reward functions
     used in this work implicitly depend on a but are specified only as functions of the state, r(s).
   • Γ ∈ [0, 1): the discount factor which is responsible for balancing immediate rewards against future rewards. It
     multiplies contributions to the cumulative reward in each timestep, controlling the divergence of cumulative rewards
     over time and enabling the agent to drive the environment toward optimal outcomes on a long time horizon.

In many real-world settings the agent may not observe the full environment, but instead a state st which is a subset of all
available observables. This was the case for our setup, and we explain which values are masked in the details to follow.
   4
     We avoided the more standard notation Πsa = π in the main body of the paper so as to avoid confusion with the angular shifts
induced by 1D NMR pulses, e.g. “pulsing with π” versus “pulsing by π.”

                                                               12
