#### 2.1. The Effect of Controlled Imperfection

Let us consider the periodic repetition of a basic pulse unit with a time duration

T and containing a number

N of

$\pi $ pulses (see

Figure 1a). In the case of ideal pulse sequences, each

$\pi $ pulse is instantaneous and rotates the qubit by an angle

$\pi $ along an axis in the

$x-y$ plane. In realistic situations, however, the control Hamiltonian for the

$\pi $ pulses in the rotating frame lreads

where

${\widehat{\sigma}}_{\alpha}$ (

$\alpha =x,y,z$) is a Pauli matrix,

$\Omega $ is the Rabi frequency and

$\varphi $ is the pulse phase of the control. Between the

$\pi $ pulses the control field is switched off with

$\Omega =0$. Here the frequency detuning

$\Delta $ introduces a rotational axis and rotation-angle errors. In addition, amplitude fluctuations on the control field change the value of the Rabi frequency

$\Omega $, thereby further altering the rotation angle of the

$\pi $ pulse. The ideal value of the Rabi frequency is

${\Omega}_{\mathrm{ideal}}=\pi /{t}_{p}$ for a

$\pi $ pulse duration

${t}_{p}$, which we assume to be the same for all the

$\pi $ pulses. We will consider the strengths of frequency detuning and amplitude fluctuation errors in terms of

${\Omega}_{\mathrm{ideal}}$.

For the sake of simplicity in the presentation, we do not consider the environment (e.g., a nuclear spin bath) of the qubit, and directly show the effect of pulse errors. However, the presence of nuclear spins will be taken into account in our numerical simulations of quantum sensing. Using Equation (

1), the evolution matrix of a single

$\pi $ pulse reads

${\widehat{U}}_{\pi}\left(\varphi \right)=exp(-i{\widehat{H}}_{c}{t}_{p})$. It is tedious to write down the expression of

${\widehat{U}}_{\pi}\left(\varphi \right)$ in terms of the amplitude error

$\Omega -{\Omega}_{0}$ and detuning error

$\Delta $. However,

${\widehat{U}}_{\pi}\left(\varphi \right)$ has the general form [

30,

35]

where the real numbers

$\alpha $,

$\beta $ and

$\u03f5$ depend on the explicit realization of the

$\pi $ pulse but are independent of the pulse phase

$\varphi $. Because static fluctuations in the detuning and Rabi frequency are the dominant sources of pulse errors [

36], we follow the standard procedure of robust sequence design [

30,

37] by assuming that each pulse has the same static errors; that is,

$\alpha $,

$\beta $ and

$\u03f5$ are the same for all the

$\pi $ pulses. When

$\u03f5=0$, the pulse corresponds to a perfect

$\pi $ pulse up to a drift

$\beta $ (which can be caused by the detuning error

$\Delta $) on the pulse phase. The pulse phase

$\varphi $ is fully tunable by changing the phase of the applied control field, and we assume that the phases of the pulses are applied in order with the values

${\varphi}_{1}$,

${\varphi}_{2}$, …,

${\varphi}_{N}$.

We consider the widely-used basic DD

$\pi $ pulse units to lead to the identity operation on the qubit after their application. Typical examples of these basic DD

$\pi $ pulse units are the

$\pi $ pulse arrangements belonging to the XY family [

28], the YY8 sequence [

34] and the Carr–Purcell sequence [

38], which contain an even number of

$\pi $ pulses. To the first order of

$\u03f5$, the evolution matrix of a DD pulse unit reads [

30,

35]

where

C is a complex number that depends on the structure of the employed DD pulse unit. One example of a DD pulse unit (i.e., the widely used XY8 sequence) can be found in the lower panel of

Figure 1a. In addition, we note that if one introduces a global phase shift

$\Phi $ to the phases of all pulses, the constant

C changes as

$C\to C{e}^{-i\Phi}$.

#### 2.1.1. Standard Protocol

In the standard protocol where the basic pulse unit is repeated

M times as

$\widehat{U}={\left({\widehat{U}}_{\mathrm{unit}}\right)}^{M}$, the control errors accumulate coherently. Using Equation (

3), we obtain the evolution matrix of the whole sequence, i.e., of

$\widehat{U}$:

In this equation (Equation (

4)) one can observe that the error

$MC\u03f5$ scales linearly with

M. This is illustrated in

Figure 1b.

#### 2.1.2. Randomisation Protocol

In the randomization protocol [

35], a random global phase

${\Phi}_{r,m}$ is imposed to all

$\pi $ pulses of each

mth basic DD pulse unit. Now, by using Equation (

3), the evolution matrix of the whole sequence reads [

35]

where

${Z}_{r,M}=\frac{1}{M}{\sum}_{m=1}^{M}exp(-i{\Phi}_{r,m})$, with

$\left\{{\Phi}_{r,m}\right\}$ being a set of phases. Due to the random value that each phase

${\Phi}_{r,m}$ takes, the quantity

${Z}_{r,M}$ becomes a (normalized) 2D random walk with

$\langle |{Z}_{r,M}{|}^{2}\rangle =1/M\le 1$ [

35]. This suppresses the effect of control errors (see

Figure 1c).

#### 2.1.3. Correlated Randomization Protocol

Now, we impose a constraint on the random phases

${\Phi}_{r,m}$, such that

${Z}_{r,M}=\frac{1}{M}{\sum}_{m=1}^{M}exp(-i{\Phi}_{r,m})=0$. In this manner, the effect of control errors will be suppressed more efficiently as compared to a fully random scheme, and irrespective of the value of

M. Note that, in the randomization protocol in [

35], a larger

M provides a better improvement, as is demonstrated in the previous section with the expression

$\langle |{Z}_{r,M}{|}^{2}\rangle =1/M\le 1$. In this correlated randomization protocol,

$\langle |{Z}_{r,M}{|}^{2}\rangle =0$, which means that the leading-order static error in the perturbative parameter

$\u03f5$ is fully eliminated. To cancel the effect of slowly fluctuating errors more efficiently, we choose a smaller number

$1<G\le M$ of subsequent random phases such that

${z}_{r,G}={\sum}_{j=1}^{G}exp(-i{\Phi}_{r,k+j})=0$ for some integer

k. Our method also improves the performance of the method over static errors since, by developing

${\widehat{U}}_{M}$ in the perturbative parameter

$\u03f5$, one can see that: Sequences with a low number

G cancel high-order-error terms better in

$\u03f5$.

An example of a possible target sequence is in

Figure 1d. Here we impose a constraint for every three subsequent random phases (i.e.,

$G=3$) such that the sum of their phase factors vanishes. Note that it is not necessary to choose the same value of

G for all the subsequent random phases in a single DD sequence. But for simplicity, we will use one fixed

G for each DD sequence in our simulations and call the value of

G as the

elimination size.

#### 2.2. Comparison of Different Protocol Performances

The sequence performance can be studied by the survival probability of the quantum sensor in the initial state (note this is initialised in an eigenstate of

${\widehat{\sigma}}_{x}$) after the application of the whole sequence. This survival probability is the directly measured value in experiments. Explicitly, we use

$|\psi \rangle =\frac{1}{\sqrt{2}}\left(\right|0\rangle +|1\rangle )$, an eigenstate of

${\widehat{\sigma}}_{x}$, as the initial state. After the sequence evolution

$\widehat{U}$, the state evolves to

$\widehat{U}|\psi \rangle $, where

$\widehat{U}$ is the qubit evolution operator. A measurement with respect to the eigenstates of

${\widehat{\sigma}}_{x}$ gives the measured survival probability

In

Figure 2, we compare the robustness of different protocols against control imperfections by numerically simulating the sequence fidelity. In particular, the fidelity is defined as the survival probability

${P}_{\psi}$ because, in the absence of external signals to detect, the quantum state of the sensor should remain unaffected after the application of the protocol and

${P}_{\psi}=1$. In addition, we clarify that white regions in these figures have lower fidelities (out of the range of each plot) such that their values are not shown for clarity.

An inspection of the panels in

Figure 2 shows that: even with a small number of repetitions

$M=6$ for the DD sequences, our method using correlated random phases presents an improved fidelity over the standard protocol and the randomization protocol in [

35]. For larger

M the fidelities of the randomization protocol and our correlated random phases protocol are expected to be similar. However, for

$M=24$ our protocol is still better than the randomization protocol (see

Figure 3). We have also observed that our protocol using correlated random phases performs slightly better when one uses a small elimination size

G, which is consistent with our theory (compare the results of

$G=2$ and 3 in

Figure 2 and

Figure 3). While the smallest

$G=2$ would be the optimal number with respect to the robustness enhancement, a slightly larger

G (e.g.,

$G=3$) also performs well. This implies that the correlated randomization protocol with different values of small

G for the subsequent random phases in a single DD sequence would also enhance sequence robustness.

In

Figure 4, we simulate the results of quantum sensing with XY8 sequences. In these simulations, we considered an NV quantum sensor in diamond. In the rotating frame of NV electron spin, the electron spin and its nearby nuclear spins have the Hamiltonian

where

${A}_{\perp}^{\left(n\right)}$ and

${A}_{\Vert}^{\left(n\right)}$ are components of the hyperfine field at the location of the

nth nucleus;

${I}_{x}^{\left(n\right)}$ and

${I}_{z}^{\left(n\right)}$ are nuclear spin operators;

${\gamma}_{n}$ the gyromagnetic ratio;

${B}_{z}$ is the maganetic field applied along the symmetry axis of the NV center. See [

29,

35] for more information on the model. The target is to sense a proton (

${}^{1}\mathrm{H}$) spin outside of the diamond sample. Due to limited control power, the Rabi frequency

$\Omega $ of control pulses has a finite value, and consequently, the

$\pi $ pulses are not instantaneous and have a non-zero time duration. In addition, in our numerical simulations we also consider static errors on the control (see caption). The non-zero pulse duration can leads to spurious resonances [

31] of sensing signal at the presence of other nuclear spins (e.g., a

${}^{13}\mathrm{C}$ spin in our simulation) (see

Figure 4a for a simulation). This signal error can be suppressed by the use of randomization protocol (

Figure 4b). As shown in

Figure 4c,d, the enhancement of the control robustness by using the correlated randomization protocol can significantly further improve the signal fidelity in quantum sensing.