Optimal control for quantum detectors

Quantum systems are promising candidates for sensing of weak signals as they can provide unrivaled performance when estimating parameters of external fields. However, when trying to detect weak signals that are hidden by background noise, the signal-to-noise-ratio is a more relevant metric than raw sensitivity. We identify, under modest assumptions about the statistical properties of the signal and noise, the optimal quantum control to detect an external signal in the presence of background noise using a quantum sensor. Interestingly, for white background noise, the optimal solution is the simple and well-known spin-locking control scheme. We further generalize, using numerical techniques, these results to the background noise being a correlated Lorentzian spectrum. We show that for increasing correlation time, pulse based sequences such as CPMG are also close to the optimal control for detecting the signal, with the crossover dependent on the signal frequency. These results show that an optimal detection scheme can be easily implemented in near-term quantum sensors without the need for complicated pulse shaping.

Introduction.-Quantum systems are extremely sensitive to the environment which makes them an ideal candidate as a sensor of weak external fields. Many promising candidates have been put forward as quantum sensors such as defect centers in diamond or Silicon Carbide, SQUID based sensors, atomic sensors, along with many others (see e.g. [1]). A variety of sensing techniques have been developed which can be used to detect either the magnitude or the phase of the signal. In Ramsey interferometry [2], a qubit is prepared in the equal superposition state and its oscillation frequency is sensitive to the splitting of the qubit, which depends on the external field to be sensed. This allows for estimation of the magnetic field amplitude with sensitivity limited by the freeevolution dephasing time of the qubit, which can be enhanced through optimal control methods [3]. Similarly, detecting AC signals is possible with Ramsey and echo sequences such as Carr-Purcell (CP) [4] and Dynamical Decoupling (DD) [5,6] sequences. These sequences can also be used for estimating frequencies of the signal [7,8]. For amplitude sensing, the typical figure of merit one considers when measuring the performance of a quantum sensor is the sensitivity, which characterizes the smallest external field that can be measured in a given amount of time [1]. This can be formulated in terms of the quantum Cramér-Rao bound and has associated applications and limiting cases [9][10][11][12][13].
While sensitivity is important for parameter estimation, it is less relevant for signal detection. In this manuscript, we reformulate the quantum sensing problem in a manner consistent with the following decision theoretic question: How does one optimally detect the presence of a stochastic signal with a known spectrum in the presence of background noise? The detection of signals in the presence of noise has been extensively studied in the field of classical decision theory [14]. A highly relevant applied formulation determined how to optimally choose whether a time-varying signal was signal plus noise or noise only, which has broad applicability FIG. 1. Schematic description of the single-qubit experiment for detection of a signal. The qubit is initialized in an eigenstate of σx, |ψin = 1 √ 2 (|0 + |1 ) and evolves in the presence of a signal, background noise and control. The measurement is done in the σz basis after a Hadamard rotation. The average probability of the occupation of state |0 (denoted by P |0 ) decays as a function of time, with the decay rate dependent on the presence/absence of a signal. The detection is optimally performed at topt when the difference between the two decay rates is the largest.
for detection systems such as radar receivers [15,16]. This field of study was extended to the quantum domain by Helstrom [17,18] who considered how to optimally choose between one of two density operators as the correct description of a receiver and Holevo [19] who considered the question of the optimal measurement to distinguish between one of two quantum states. Results following these works have placed bounds on the limits of quantum state [20,21] and channel discrimination [22][23][24][25][26].
We build upon this early work but incorporate the filter function formalism originating from quantum control theory [27][28][29][30] to answer this question of how to optimally detect sig-nals with a controllable quantum sensor. Unlike earlier works on state and channel discrimination that aim to identify the optimal measurements to distinguish two states/channels, our work is focused on identifying the control scheme that optimally separates the two cases.
Our model, as shown schematically in Fig. 1, considers a single qubit (or an ensemble of non-interacting qubits) with external fields coupled through an energy splitting term and single-axis control on the transverse axis. We seek control protocols that maximize the relative dephasing of the qubit under the two different scenarios of signal plus noise or noise only. We examine arbitrary single-axis time-dependent controls for this discrimination problem and show that under certain assumptions on the background noise, the optimal control protocol is remarkably just a constant control with Rabi frequency corresponding to the maximum of the signal spectrum. This corresponds to what is traditionally known as spinlocking in the nuclear magnetic resonance literature [31]. The spin-locking technique, along with its pulsed analogue, has been widely used in quantum sensing and noise spectroscopy applications [8,[32][33][34][35][36].
Model.-Let us consider a single qubit as a quantum sensor, in the presence of a dephasing signal and noise. Assuming uniaxial control (along σ x ), and under the rotating wave approximation, the qubit Hamiltonian is given by, where Ω(t) is the Rabi frequency of an arbitrary timedependent control, the signal s(t) and background noise η(t) are both considered to be classical wide sense stationary Gaussian stochastic processes and α denotes the ratio of the signalto-noise power (SNR) and J 2 is the total noise power. These stochastic processes have mean zero, s(t) = η(t) = 0 and two-point time correlations given by η(t)η(t ) = g η (t − t ), s(t)s(t ) = g s (t − t ) and η(t)s(t ) = 0 with the normalization g η (0) = g s (0) = 1 and (· · · ) denoting averaging over noise realizations. Alternatively, the noise correlations may also be represented in the frequency domain, using the power spectrum, S η (ω) = ∞ −∞ dτ g η (τ )e −iωτ , with the normalization ∞ −∞ dωS η (ω) = 2π, and similarly for S s (ω). In this manuscript, we consider two distinct types of noise for the background. In the simple case of white-noise, we can obtain analytical results for the optimal control. In addition, we also consider the background noise spectrum to be a Lorentzian, corresponding to g η (t) = e −|t|/σt , where σ t denotes the correlation time-scale. This noise spectrum is quite relevant to quantum sensing platforms such as Nitrogen-vacancy centers in diamond [37,38]. We examine the Lorentzian case numerically.
For the numerical simulations, the dynamics of the qubit sensor are modeled by an exact noisy quantum simulation and control library -'Mezze' [39], which uses a stochastic Liouville equation formalism with a Trotter decomposition. We fix the noise power J 2 = 30/π ≈ 9.549 and rescale all frequencies and time-scales in units of J. We also keep fixed the SNR α = 0.05 and Trotter time-step ∆t = 10 −3 . The signal power-spectrum S s (ω) is chosen to be white-cutoff, centered around a frequency Ω 0 and width 2∆Ω; see e.g., 2(a) (in orange). Note that the parameters considered in this manuscript are chosen to be in the regime of low SNR (α 1) and weak noise relative to the control (J/max{Ω(t)} 1). The weak noise limit allows us to utilize the cumulant expansion to study the dynamics of the qubit.
Detection Protocol.-The aim of this protocol is to optimally detect the presence of a stochastic signal with a known spectrum in the presence of background noise. This is in contrast to the goal of estimating an AC or DC signal as traditionally considered in quantum sensing [1]. The detection protocol can be described in four steps. (i) Initialize the qubit in the state |+ = 1 Here, t opt is chosen depending on the signal, noise, and control by maximizing the infidelity between the signal present and signal absent cases. This maximizes the likelihood-ratio that allows one to optimally discriminate between the signal absent versus the signal present hypotheses by the Neyman-Pearson Lemma [40]. (iii) Rotate the qubit using a Hadamard gate (denoted as H). (iv) Measure in theσ z basis. Record outcome as '0' or '1'. Repeat these steps N shots times. This procedure is schematically described in Fig. 1.
In this paper, we make no assumptions on the shape of the control function Ω(t) in order to obtain the optimal detection protocol. The numerically optimized detection scheme, Ω(t) = Ω opt (t) is compared with the performance of some well-known protocols used in sensing (i) Spin-locking: Ω(t) = constant; (ii) Carr, Purcell, Meiboom, Gill (CPMG) pulse sequence: Ω(t) is given by a series of equidistant πpulses separated by free evolution periods of duration τ CPMG ; and (iii) Ramsey interferometry: Ω(t) = 0. Examining the dephasing dynamics in the presence of control, the probability to observe the qubit in state |0 is P |0 (t) = 1 2 (1 + e −χ(t) ). Clearly, the dephasing exponent depends on the presence or absence of a signal and is denoted as χ η+s and χ η respectively. The corresponding outcome probabilities are labeled as P η+s and P η respectively. In the following, we compute these two exponents in the regime of weak noise and signal as well as low SNR, and identify the control protocol that at a particular optimal time (t opt ) of measurement gives the maximum separation between the two decaying average probabilities, ∆P |0 = P η − P η+s .
Dephasing in Second Cumulant Approximation (SCA).-Let us consider the dephasing of a qubit just in the presence of noise, setting s(t) = 0. The dynamics of the qubit in a weak noisy environment, is well understood using the cumulant expansion [30,41]. The dephasing exponent, χ η , can be obtained from the dynamics of σ x (t) = Tr [σ x ρ(t)] ≈ e −χ(t) σ x 0 ; σ x 0 denoting the initial state. In the interaction frame of the control U I (t) = e −i 1 2σ x Λt , where Λ t = t 0 dtΩ(t), the dynamics is straightforwardly rewritten in terms of the cumulant expansion, σ x (t) = Tr exp ∞ n=1 [41,42]. In the regime that the noise is weak, it is sufficient to terminate the series at the second cumulant (odd cumulants vanish trivially) to obtain the following expression for the decay [42], where, χ η (t) is always real.
In the frequency domain, Eq. (2) can be recast into an overlap between the noise spectrum and the Filter Function (FF), χ η (t) = The FF is now given by the following expression, where we use the symmetry of the noise spectrum, S η (ω) = S η (−ω). Note that the FFs have a normalization, As an example, consider the limiting case when the background noise is white. In this case, which is the Dirac δ-function. To be consistent with our normalization [g(0) = 1], we define g(t − t ) = lim →0 e −|t|/ . However, to have a non-zero decay rate, we must rescale the noise power J 2 such that , 2J 2 = γ is a constant. Now, χ η is obtained straightforwardly from Eq. (2), χ η (t) = 1 2 γt. Interestingly, this dephasing rate under white noise is constant regardless of the control, Ω(t) applied. This gives the standard T 2 time for the qubit with T 2 = 2/γ.
In order to compare with numerics, it is convenient to switch to the discrete time picture, with time-steps ∆t = t/N , where N is the total number of steps, in addition to a piecewise constant control Ω = (Ω 0 , · · · , Ω N ). Here, Eq. (2) becomes a Riemann sum and χ η is a matrix expectation value. To this end, let us introduce (i) an N −dimensional vector for the control, Using these definitions, the expression for χ can now be written in a compact form, The white-noise limit is recovered by setting G η to be a diagonal matrix,G η [i, i] = 1, and J 2 ∆t = γ. We also note that in this discrete time notation, the FF [See Eq. (3)] is the Fourier series of Θ. Optimization for Detection.-Let us now describe the procedure for optimizing the control for detecting the signal. Both the signal and the noise cause the qubit to dephase, and the dephasing exponent is straightforwardly obtained in the SCA using Eq. (4). Since the signal and noise are uncorrelated, the decay in the presence of a signal is a sum, χ η+s = χ η + χ s , where χ s and χ η are the decay exponents obtained from having just the signal or the noise present, respectively. Thus, the qubit decays at a faster rate in the presence of both signal and noise compared to just the background noise. In order to optimize for detection, we maximize over the difference between the two outcome probabilities, ∆P |0 . We now have an effective heuristic for designing optimal detection controls that becomes optimal when the SCA applies. We define the following objective function, We carry out the optimization as a two-step procedure: Recall that the detection time sets the dimension of the control vector, dim [Ω] = t/∆t. In the limit of white background noise, we will obtain analytically the optimal control that maximizes O. More generally, for arbitrary noise spectrum, the optimization is implemented using stochastic gradient descent (SGD) algorithms. We do this using the Adam optimization algorithm implemented in TensorFlow library [43,44] taking advantage of graphical processing units to accelerate the optimization procedure. Note that it is also straightforward to add additional constraints on the variables that could be motivated by experimental requirements; e.g. maximum available power [42].
(ii) Optimize over the time of detection, t opt to obtain the optimal detection protocol. The optimal time is obtained using a grid search over different detection times t. Therefore, we obtain the optimal detector in the SCA, which we denote as 'SCA-optimal', with O opt = O(t opt , Ω opt ) White Background Noise-Let us start by discussing the SCA-optimal protocol when the background noise is close to white, σ t 1/Ω 0 , 1/∆Ω. Here, we assume that the signal spectrum S s (ω) is characterized by a peak at ω = Ω 0 and width ≈ 2∆Ω. This case allows us to compute the optimal control analytically. Dephasing in the absence of any signal, χ η , is independent of the applied control, which simplifies the optimization objective, O [See Eq. (5)]. Therefore, O can be maximized by maximizing χ s given by a formula analogous to Eqs. (2) and (4). Examining the expression of χ s in terms of FFs, the following bound is obtained, where, we use the normalization, In the following, we show that this upper bound on χ s (t) can be achieved in the limit of long times (t 1/∆Ω), using a control that is constant in time, Ω(t) = argmax ω [S(ω)] = Ω 0 . This control scheme is commonly referred to as 'spinlocking'.
A spin-locked (SL) control scheme, Ω(t) = Ω 0 has the FF, F t (ω) = te i(Ω−ω)t/2 sinc (Ω 0 − ω) t 2 and decay exponent, where, in the second step, we approximate the sinc( x) as a rectangular function. Therefore, we see that the bound for χ s (t)[see Eq. (6)] can be saturated using this simple control protocol. While we have shown this result for a spectrum that has a maxima at Ω 0 , it is straightforward to generalize it to a white-cutoff signal spectrum [see Fig. 2(a)], in which case the optimal spin-locking frequency is at the middle of the band. We emphasize the following subtlety in the derivation of Eq. (8): The optimal time for measurement (t opt ) is large compared to the inverse width of the signal spectrum, t opt 1/∆Ω. The SCA-optimal detection protocol at any particular time of measurement t, with white background noise, can also be calculated numerically without using time-consuming SGD based optimizers. Since this control maximizes χ s , it can be obtained from the eigenstructure of the correlation matrix G s [see Eq. (4)]. In fact, it is straightforward to show that χ opt s (t) ≤ 1 2 J 2 αt∆tg max , where g max (Φ max t ) denotes the largest eigenvalue (eigenvector) of the correlation matrix of the signal spectrum G s . However, the eigenvector of the correlation matrix is not necessarily an allowed control protocol. Therefore, the SCA-optimal control protocol is obtained from identifying a control vector Θ opt t = 1 √ N e −iΛ0 , · · · , e −iΛt with the largest overlap with Φ max t . Noting, that the eigenspectrum of G s is doubly degenerate (denote them by i = ±), we can construct two possible SCA-optimal control vectors elementwise as, where, the two possible optimal controls correspond to driving around ±Ω 0 . Having constructed the SCA-optimal control for arbitrary time t, the optimal time of measurement, t opt is obtained by maximizing O from Eq. (5). Now, we have the SCA-optimal control for detection, Θ opt topt an example of which is shown in Fig. 2(c).
We numerically simulate the performance of the sensing protocol for white background noise; the results are shown in Fig. 2. A nearly-white background noise spectrum is obtained by choosing the correlation time to be small, Jσ t = 0.01 30/π J/∆Ω. Fig. 2(b) shows the observed outcome probability of state |0 , P |0 as a function of time. Both with and without the signal, P |0 (shown in orange and blue) decays exponentially, with very good agreement between the exact dynamics (points) and SCA (solid line). We calculate the optimal time for detection t opt by maximizing the difference, O, see Eq. (5). In Fig. 2(c) and (d), we examine the optimality of spin-locking. Fig. 2(c) compares spin-locking to the numerically obtained SCA-optimal protocol, Θ opt topt [see Eq. (9)], up to their respective optimal times of measurement. Comparing the two control schemes, it is clear that spin-locking is close to optimal. In fact, for long times of measurement, t → ∞, Θ opt t→∞ converges to spin-locking. However, at finite measurement times, t = t opt , Θ opt topt remains distinct from spin-locking, with oscillations around the spin-lock frequency. Fig. 2 (d) compares the performance of spin-locking as a function of the Rabi frequency of the applied control Ω to the SCA-optimal detector. Comparing the performance of spin-locking as obtained from exact numerics (blue dots) with that obtained for the SCA-optimal control (red dashed line), it is clear that spin-locking may perform marginally better in practice, which we attribute to corrections to the dynamics beyond the SCA.
Lorentzian Background Noise.-We now compare the performance of spin-locking as a function of correlation time of the background noise. Specifically, we compare it to CPMG with τ CPMG = π/Ω 0 and Ramsey interferometry, Ω(t) = 0. We also numerically obtain the SCA-optimal control protocol using SGD based optimizers and compare its shape with One of the important takeaways from the numerical optimization of the objective function, O, is that the SCA-optimal protocol depends on the correlation time, σ t . The control obtained from the SGD, is close to spin-locking for short correlation times; however, for correlation times longer than a crossover scale, CPMG performs better [See Fig. 3(b)]. In Fig. 3(a), we show the different controls for a particular correlation time, Jσ t = 1.17. Clearly, the SCA-optimal control has close resemblance to CPMG. Interestingly, for larger correlation times, the SGD based optimizer finds novel control schemes that are neither CPMG or spin-locking [42].
The crossover correlation-timescale for CPMG to perform better than spin-locking depends approximately as a power law to the signal frequency, σ cross The better performance of CPMG compared to spin-locking for longer correlation times can be understood qualitatively from the shape of their corresponding FFs. While the FF for spinlocking has all of its weight close to Ω 0 , CPMG has some weight also at the odd harmonics of Ω 0 [42,45,46]. In addition, the amplitude of the FF for CPMG at frequencies, ω < Ω 0 , is lower compared to spin-locking [42]. Since the background spectrum is Lorentzian and S η (ω) decays at higher frequencies, this leads to χ CPMG η < χ SL η ; unlike when the background is white where the χ η is independent of the control. The optimization objective depends on χ s/η in a non-  Fig. 1). For a given number of shots, the threshold for the detector is chosen to minimize the total probability of FP and FN outcomes.
linear fashion (see Eq. (5)) which increases with either decreasing χ η or increasing χ s . Even though for the signal spectrum, χ CPMG s < χ SL s , the smaller value of χ CPMG η leads to a larger O. It is interesting to note that, in the presence of experimentally motivated constraints, such as maximum available power, the optimal protocol interpolates between CPMG (instantaneous π-pulses) and spin-locking [42].
Let us now discuss the performance of the different control schemes as obtained from exact numerical simulation, see Fig. 4. We compare the performance of spin-locking, CPMG and Ramsey schemes at their respective optimal detection times; the controls are shown in Fig. 4 (a). In order to quantify the performance of each control scheme, we calculate the rate of error for detecting the signal in the presence of background noise; see Fig. 4 (b). The error rate is defined as follows. Given N shots measurement shots and a chosen threshold for detection (fixed number of |0 as measurement outcomes), the error rate of the detector corresponds to the average probability of False-Positive (FP) and False-Negative (FN) classifications. Choosing the threshold such that the average of probability of FP (type I error) and FN (type II error) is minimum, we plot the Error Rate as a function of the number of measurements in Fig. 4(b); a better detector is characterized by lower error rates. Rather surprisingly, even when the correlation time is large Jσ t = 1.17, the performance of CPMG and spin-locking remains fairly close to each other, with spinlocking still performing marginally better. This is likely due to the fact that the SGD based optimization is done under the assumption that the SCA holds. However, non-negligible contributions from higher cumulants to the dephasing rate leads to deviations from SCA, which may lead to better performance of spin-locking. This also reveals some general robustness in the optimality of spin-locking as a detection protocol for the signal.
Discussion.-In this work we discuss the performance of different control schemes for detecting a known signal in the presence of certain background noise environments and show that a spin-lock drive is close to optimal in all cases we considered. This work opens up a potentially exciting use case for currently available quantum sensor hardware. These detectors can be used to identify signals in electromagnetic fields where the detection bandwidth is only limited by the frequency range of the control drive. This work opens up several directions for future work. We only considered the dynamics in the second cumulant approximation where we are able to show the near-optimality of spinlocking. We did not take into account the role of the higher cumulants as they do not play a significant role at optimal detection time. However for qubits with higher T 2 times and larger signal power, it will be essential to consider its role for determining optimal controls for detection. Another possibility is to consider the performance of detection protocols when the signal or noise is non-gaussian and/or non-stationary. Furthermore, we have considered the control drive to be on resonance. Any detuning will result in a two-dimensional control in the rotating frame, with controls along both σ x and σ y . The optimal detection protocol in the presence of detuning will be a topic of future work, and will point to more robust protocols for detection. Finally, we have considered only a single qubit or a non-interacting ensemble of qubits as the sensor and do not consider the role of entanglement, which may provide an enhancement in sensing beyond that available classically.
The authors would like to thank Mohammad Hafezi, Jeff Barnes, Colin Trout and Timothy Sweeney for useful discussions. PT, KMS, GDQ and BC also acknowledge funding from the Internal Research and Development program of the Applied Physics Laboratory. AS gratefully acknowledges support from ARO-MURI and Physics Frontier Center by National Science Foundation at the JQI.  Fig. 4(a).
The integrand can be simplified using, Averaging over noise realizations, and noting that η(t 1 )η(t 2 ) = f η (t 1 − t 2 ), with f (t) being an even function. Therefore, the term ∝ σ x in C (2) (t) vanish. Simplifying the expression for the second cumulant, Defining the decay exponent, χ(t) as σ x (t) = e −χ(t) σ x 0 , we have an expression for the decay from in the second cumulant expansion, , which means that if S(ω) = S(−ω), the expression for χ can be further simplified by introducing F t (ω) introduced in Eq. (2). This completes the derivation for expressions of χ(t) and F (ω) as defined in Eq. (2) in the main text. As an example, we plot the filter functions to the controls considered in Fig. 4 (a).

S.II. DETAILS FOR NUMERICAL OPTIMIZATION
We use a two-step numerical optimization to find the Ω opt that maximizes ∆P |0 = e −χη (1 − e −χs ). Specifically, we do a grid search over different durations of the protocol, and for each t, we find the control schedule that optimizes the objective function. Since the cost function is differentiable, we use the Adam [S3] optimizer with default parameters in TensorFlow to optimize the object function. Moreover, we constrain [Ω] i to be positive for all values of i. We either run the optimization for 10000 iterations, or stop if the magnitude of the difference of the objective function values separated by 1000 iterations is smaller than 10 −6 . In all the optimizations performed in this work, we discretize the control to ∆t = 0.01J −1 . We repeat this procedure for different control lengths t from 300∆t to 1300∆t in increments of 10∆t. We then choose a t that has the optimal objective value. , and the right panel shows the associated filter functions |Ft(ω)|. Note that for small values of Jσt, noise spectrum is nearly white and the optimal control coincides with spin-lock protocol. As Jσt increases the optimal control gets closer to CMPG protocol, and later assumes novel solutions that differ from both spin-lock and CPMG protocols.
After finishing this two-step optimization, we evaluate ∆P |0 at the optimal time with the optimal control by interpolating the results to a finer discretization of ∆t = 0.001J −1 and compare it to the value of ∆P |0 with CPMG and spin-lock control schemes. We obtain the best time for CPMG and spin-lock control schemes by numerically evaluating the ∆P |0 using discretized control with ∆t = 0.001J −1 and varying the duration of the protocol for t from 3000∆t to 13000∆t in increments of 100∆t. The optimal protocol compared with Spin-lock and CPMG for different values of σ t , together with their corresponding filter functions, are shown in Fig. S2.
To take experimental limitations into account, we also consider a scenario where the maximum power is limited. This is manifested in a constraint on the maximum value of Ω at any time. We can implement this constraint by either adding an L2 regularization term to the objective function, that is O L2 = β||Ω|| 2 2 , where β is a hyper parameter that controls the magnitude, or imposing a hard cutoff Ω c on the value of the optimization variable. We observe that in a regime where the optimizer finds a CPMG-like control scheme to be optimal, adding these constraint transforms instantaneous pulses to finite-width version of the pulse that ultimately reaches the spin-lock solution, see Fig. S3.