Achieving the Heisenberg limit in quantum metrology using quantum error correction

Quantum metrology has many important applications in science and technology, ranging from frequency spectroscopy to gravitational wave detection. Quantum mechanics imposes a fundamental limit on measurement precision, called the Heisenberg limit, which can be achieved for noiseless quantum systems, but is not achievable in general for systems subject to noise. Here we study how measurement precision can be enhanced through quantum error correction, a general method for protecting a quantum system from the damaging effects of noise. We find a necessary and sufficient condition for achieving the Heisenberg limit using quantum probes subject to Markovian noise, assuming that noiseless ancilla systems are available, and that fast, accurate quantum processing can be performed. When the sufficient condition is satisfied, a quantum error-correcting code can be constructed that suppresses the noise without obscuring the signal; the optimal code, achieving the best possible precision, can be found by solving a semidefinite program.

Q uantum metrology concerns the task of estimating a parameter, or several parameters, characterizing the Hamiltonian of a quantum system. This task is performed by preparing a suitable initial state of the system, allowing it to evolve for a specified time, performing a suitable measurement, and inferring the value of the parameter(s) from the measurement outcome. Quantum metrology is of great importance in science and technology, with wide applications including frequency spectroscopy, magnetometry, accelerometry, gravimetry, gravitational wave detection, and other high-precision measurements [1][2][3][4][5][6][7][8][9] .
Quantum mechanics places a fundamental limit on measurement precision, called the Heisenberg limit (HL), which constrains how the precision of parameter estimation improves as the total probing time t increases. According to HL, the scaling of precision with t can be no better than 1/t; equivalently, precision scales no better than 1/N with the total number of probes N used in an experiment. For a noiseless system, HL scaling is attainable in principle by, for example, preparing an entangled "cat" state of N probes [10][11][12] . In practice, though, in most cases environmental decoherence imposes a more severe limitation on precision; instead of HL, precision scales like 1= ffiffiffiffi N p , called the standard quantum limit (SQL), which can be achieved by using N independent probes [13][14][15][16][17][18] . The quest for measurement schemes surpassing the SQL has inspired a variety of clever strategies, such as squeezing the vacuum 1 , optimizing the probing time 19 , monitoring the environment 20,21 , and exploiting non-Markovian effects [22][23][24] .
Quantum error correction (QEC) is a particularly powerful tool for enhancing the precision of quantum metrology [25][26][27][28][29][30] . Quantum error correction is a method for reducing noise in quantum channels and quantum processors [31][32][33] . In principle, it enables a noisy quantum computer to simulate faithfully an ideal quantum computer, with reasonable overhead cost, if the noise is not too strong or too strongly correlated. But the potential value of QEC in quantum metrology has not yet been fully fleshed out, even as a matter of principle. A serious obstacle for applications of QEC to sensing is that it may in some cases be exceedingly hard to distinguish the signal arising from the Hamiltonian evolution of the probe system from the effects of the noise acting on the probe. Nevertheless, it has been shown that QEC can be invoked to achieve HL scaling under suitable conditions [25][26][27][28] , and experiments demonstrating the efficacy of QEC in a room-temperature hybrid spin register have recently been conducted 34 .
As is the case for quantum computing, we should expect positive (or negative) statements about improving metrology via QEC to be premised on suitable assumptions about the properties of the noise and the capabilities of our quantum hardware. But what assumptions are appropriate, and what can be inferred from these assumptions? In this paper, we assume that the probes used for parameter estimation are subject to noise described by a Markovian master equation 35,36 , where the strength and structure of this noise is beyond the experimentalist's control. However, aside from the probe system, the experimentalist also has noiseless ancilla qubits at her disposal, and the ability to apply noiseless quantum gates that act jointly on the ancilla and probe; she can also perform perfect ancilla measurements, and reset the ancillas after measurement. Furthermore, we assume that a quantum gate or measurement can be executed in an arbitrarily short time (though the Markovian description of the probe's noise is assumed to be applicable no matter how fast the processing).
Previous studies have shown that whether HL scaling can be achieved by using QEC to protect a noisy probe depends on the algebraic structure of the noise. For example, if the probe is a qubit (two-dimensional quantum system), then HL scaling is possible when detecting a σ z signal in the presence of bit-flip (σ x ) errors [25][26][27][28] , but not for dephasing (σ z ) noise acting on the probe, even if arbitrary quantum controls and feedback are allowed 16 . (Here σ x,y,z denote the Pauli matrices.) For this example, we say that σ x noise is "perpendicular" to the σ z signal, while σ z noise is "parallel" to the signal. In some previous work on improving metrology using QEC, perpendicular noise has been assumed 25,26 , but this assumption is not necessary-for a qubit probe, HL scaling is achievable for any noise channel with just one Hermitian jump operator L, except in the case where the signal Hamiltonian H commutes with L 37 .
In this paper, we extend these results to any finite-dimensional probe, finding the necessary and sufficient condition on the noise for achievability of HL scaling. This condition is formulated as an algebraic relation between the signal Hamiltonian whose coefficient is to be estimated and the Lindblad operators {L k } that appear in the master equation describing the evolution of the probe. We prove that (1) if the signal Hamiltonian can be expressed as a linear combination of the identity operator I, the Lindblad operators L k , their Hermitian conjugates L y k and the products L y k L j for all k, j, then SQL scaling cannot be surpassed. (2) Otherwise HL scaling is achievable by using a QEC code such that the effective "logical" evolution of the probe is noiseless and unitary. Notably, under the assumptions considered here, either SQL scaling cannot be surpassed or HL scaling is achievable via quantum coding; in contrast, intermediate scaling is possible in some other metrology scenarios 19 . For the case where our sufficient condition is satisfied, we explicitly construct a QEC code that achieves HL scaling. Furthermore, we show that searching for the QEC code that achieves optimal precision can be formulated as a semidefinite program (SDP) that can be efficiently solved numerically, and can be solved analytically in some special cases. Our sufficient condition cannot be satisfied if the noise channel is full rank, and is therefore not applicable for generic noise. However, for noise which is ϵ-close to meeting our criterion, using the QEC code ensures that HL scaling can be maintained approximately for a time Oð1=ϵÞ, before crossing over to asymptotic SQL scaling.

Results
Sequential scheme for quantum metrology. We assume that the probes used for parameter estimation are subject to noise described by a Markovian master equation. In addition to the probe system, the experimentalist also has noiseless ancilla qubits at her disposal. She can apply fast, noiseless quantum gates that act jointly on the ancilla and probe; she can also perform perfect ancilla measurements, and reset the ancillas after measurement.
We endow the experimentalist with these powerful tools because we wish to address, as a matter of principle, how effectively QEC can overcome the deficiencies of the noisy probe system. Our scenario may be of practical interest as well, in hybrid quantum systems where ancillas are available, which have a much longer coherence time than the probe. For example, sensing of a magnetic field with a probe electron spin can be enhanced by using a quantum code, which takes advantage of the long coherence time of a nearby (ancilla) nuclear spin in diamond 34 . In cases where noise acting on the ancilla is weak but not completely negligible, we may be able to use QEC to enhance the coherence time of the ancilla, thus providing better justification for our idealized setting in which the ancilla is effectively noiseless. Our assumption that quantum processing is much faster than characteristic decoherence rates is necessary for QEC to succeed in quantum computing as well as in quantum metrology, and recent experimental progress indicates that this assumption is applicable in at least some realistic settings. For example, in superconducting devices, QEC has reached the break-even point where the lifetime of an encoded qubit exceeds the natural lifetime of the constituents of the system; 38 one-and two-qubit logical operations have also been demonstrated 39,40 . Moreover, if sensing could be performed using a probe encoded within a noiseless subspace or subsystem 41 , then active error correction would not be needed to protect the probe, making the QEC scheme more feasible using near-term technology.
In accord with our assumptions, we adopt the sequential scheme for quantum metrology 37,42,43 (Fig. 1a). In this scheme, a single noisy probe senses the unknown parameter for many rounds, where each round lasts for a short time interval dt, and the total number of rounds is t/dt, where t is the total sensing time. In between rounds, an arbitrary (noiseless) quantum operation can be applied instantaneously, which acts jointly on the probe and the noiseless ancillas. The rapid operations between rounds empower us to perform QEC, suppressing the damaging effects of the noise on the probe. Note that this sequential scheme can simulate a parallel scheme (Fig. 1b), in which N probes simultaneously sense the parameter for time t/N 37,42 .
Necessary and sufficient condition for HL. We denote the ddimensional Hilbert space of our probe by H P , and we assume the state ρ p of the probe evolves according to a time-homogeneous Lindblad master equation of the form (with ħ = 1) 31,35,36 , where H is the probe's Hamiltonian, {L k } are the Lindblad jump operators, and r is the "rank" of the noise channel acting on the probe (the smallest number of Lindblad operators needed to describe the channel). The Hamiltonian H depends on a parameter ω, and our goal is to estimate ω. For simplicity, we will assume that H = ωG is a linear function of ω, but our arguments actually apply more generally. If H(ω) is not a linear function of ω, the coding scheme we describe below can be repeated many times if necessary, using our latest estimate of ω after each round to adjust the scheme used in the next round. By including in the protocol an inverse Hamiltonian evolution step exp iHω ð Þdt ð Þ applied to the probe, whereω is the estimated value of ω, we can justify the linear approximation whenω is sufficiently accurate. The asymptotic scaling of precision with the total probing time is not affected by the preliminary adaptive rounds 44 .
We denote by H A the d-dimensional Hilbert space of a noiseless ancilla system, whose evolution is determined solely by our fast and accurate quantum controls. Over the small time interval dt, during which no controls are applied, the ancilla evolves trivially, and the joint state ρ of probe and ancilla evolves according to the quantum channel: where G, L k are shorthand for G I, L k I, respectively. We assume that this time interval dt is sufficiently small that corrections higher order in dt can be neglected. In between rounds of sensing, each lasting for time dt, control operations acting on ρ are applied instantaneously. Our conclusions about HL and SQL scaling of parameter estimation make use of an algebraic condition on the master equation that we will refer to often, and it will therefore be convenient to have a name for this condition. We will call it the Hamiltonian-not-in-Lindblad span (HNLS) condition, or simply HNLS, an acronym for "Hamiltonian-not-in-Lindblad span." We denote by S the linear span of the operators I, L k , L y k , L y k L j (for all k and j ranging from 1 to r), and say that the Hamiltonian Fig. 1 Metrology schemes and qubit probe. a The sequential scheme. One probe sequentially senses the parameter for time t, with quantum controls applied every dt. b The parallel scheme. N probes sense the parameter for time t/N in parallel. The parallel scheme can be simulated by the sequential scheme. c The relation between the signal Hamiltonian, the noise, and the QEC code on the Bloch sphere for a qubit probe state our main conclusion about parameter estimation using fast and accurate quantum controls as Theorem 1. Theorem 1 applies if the ancilla is noiseless, and also for an ancilla subject to Markovian noise obeying suitable conditions, as we discuss in the Methods.
Qubit probe. To illustrate how Theorem 1 works, let's look at the case where the probe is a qubit, which has been discussed in detail in ref. 37 . Suppose one of the Lindblad operators is L 1 ∝ n · σ, where n = n r + in i is a normalized complex 3-vector and n r , n i are its real and imaginary parts, so that If n r and n i are not parallel vectors, then n r , n i , and n i × n r are linearly independent, which means that I, L 1 , L y 1 , and L y 1 L 1 span the four-dimensional space of linear operators acting on the qubit. Hence HNLS cannot be satisfied by any qubit Hamiltonian, and therefore parameter estimation with HL scaling is not possible according to Theorem 1. We conclude that for HL scaling to be achievable, n r and n i must be parallel, which means that (after multiplying L 1 by a phase factor if necessary) we can choose L 1 to be Hermitian 37 . Moreover, if L 1 and L 2 are two linearly independent Hermitian traceless Lindblad operators, then {I, L 1 , L 2 , L 1 L 2 } span the space of qubit linear operators and HL scaling cannot be achieved. In fact, for a qubit probe, HNLS can be satisfied only if there is a single Hermitian (not necessarily traceless) Lindblad operator L, and the Hamiltonian does not commute with L.
We will describe below how to achieve HL scaling for any master equation that satisfies HNLS, by constructing a twodimensional QEC code that protects the probe from the Markovian noise. To see how the code works for a qubit probe, suppose G ¼ 1 2 m Á σ and L ∝ n · σ, where m and n are unit vectors in R 3 (Fig. 1c). Then the basis vectors for the QEC code may be chosen to be: here 0 j i A , 1 j i A are basis states for the ancilla qubit, and m ? ; ± j i P are the eigenstates with eigenvalues ±1 of m ⊥ · σ where m ⊥ is the (normalized) component of m perpendicular to n. In particular, if m ⊥ n (perpendicular noise), then C 0 the coding scheme previously discussed in refs. [25][26][27][28] .
In the case of perpendicular noise, we estimate ω by tracking the evolution in the code space of a state initially prepared as (in a streamlined notation) ψ 0 If a jump then occurs at time t, the state is transformed to Jumps are detected by performing a two-outcome measurement that projects onto either the span of {|+, 0〉, |−, 1〉} (the code space) or the span of {|−, 0〉, |+, 1〉} (orthogonal to the code space), and when detected they are immediately corrected by flipping the probe. Because errors are immediately corrected, the errorcorrected evolution matches perfectly the ideal evolution (without noise), for which HL scaling is possible.
When the noise is not perpendicular to the signal, then not just the jumps but also the Hamiltonian evolution can rotate the joint state of probe and ancilla away from the code space. However, after evolution for the short time interval dt, the overlap with the code space remains large, so that the projection onto the code space succeeds with probability 1 − O(dt 2 ). Neglecting O(dt 2 ) corrections, then, the joint probe-ancilla state rotates noiselessly in the code space, at a rate determined by the component of the Hamiltonian evolution along the code space. As long as this component is nonzero, HL scaling can be achieved.
We will see that this reasoning can be extended to any finitedimensional probe satisfying HNLS, including quantum manybody systems and (appropriately truncated) bosonic channels.
Here we briefly mention a few other cases where HNLS applies, and therefore HL scaling is achievable. (1) For a many-qubit system, suppose that each Lindblad jump operator L k is supported on no more than t qubits (hence each L y k L j is supported on no more than 2t qubits), and the Hamiltonian contains at least one term acting on at least 2t + 1 qubits. Then HNLS holds. (2) Consider a d-dimensional system (a qudit), and define generalized Pauli operators (where addition is modulo d). Suppose that the Hamiltonian H (Z) is a non-constant function of Z and that there is a single Lindblad jump operator L(X) which is a function of X. Then HNLS holds. HNLS may also apply for a multi-qubit sensor with qubits at distinct spatial positions, where the signal and noise are parallel for each individual qubit, but the signal and noise depend on position in different ways 45 . We must explain how, when HNLS holds, a quantum code can be constructed that achieves HL scaling. But first we will discuss why HL is impossible when HNLS fails.
Non-achievability of HL when HNLS fails. The necessary condition for HL scaling can be derived from the quantum Cramér-Rao bound [46][47][48] hereω denotes any unbiased estimator for the parameter ω, and δω is that estimator's standard deviation. F ρ ω ðtÞ ð Þ is the quantum Fisher information (QFI) of the state ρ ω (t); this state is obtained by preparing an initial state ρ in of the probe, and then evolving this state for total time t, where the evolution is governed by the ω-dependent probe Hamiltonian H(ω), the Markovian noise acting on the probe, and our fast quantum controls. For a scheme in which the measurement protocol is repeated many times in succession, R denotes the number of such repetitions. Here we show that F ρ ω ðtÞ ð Þis at most asymptotically linear in t when the Hamiltonian H(ω) is contained in the linear span (denoted S) of I, L k , L y k , and L y k L j , which means that SQL scaling cannot be surpassed in this case.
Though it is challenging to compute the maximum attainable QFI for arbitrary quantum channels, useful upper bounds on QFI can be derived, which provide lower bounds on the precision of quantum metrology [15][16][17][18]37,42,49 . The quantum channel describing the joint evolution of probe and ancilla has a Kraus operator representation and in terms of these Kraus operators we define where we express the Kraus operators in vector notation K :¼ K 0 ; K 1 ; ð Þ T , and the over-dot means the derivative with respect to ω. If ρ in is the initial joint state of probe and ancilla at time 0, and ρ(t) is the corresponding state at time t, then the upper bound on the QFI ( Á k k denotes the operator norm) derived by the "channel extension method" holds for any choice of ρ in even when fast and accurate quantum controls are applied during the evolution 37 . This upper bound on the QFI provides a lower bound on the precision δω via Eq. (7). Kraus representations are not unique-for any matrix u satisfying u † u = I, K′ = uK represents the same channel as K. Hence, we can tighten the upper bound on the QFI by minimizing the RHS of Eq. (11) over all such valid Kraus representations. We see that where h ¼ iu y _ u. Therefore, to find α dt and β dt providing the tightest upper bound on the QFI, it suffices to replace _ K by _ K À ihK and to optimize over the Hermitian matrix h.
To evaluate the bound for asymptotically large t, we expand α dt , β dt , h in powers of ffiffiffiffi ffi dt p : We show in the Methods that the first two terms in α dt and the first four terms in β dt can all be set to 0 by choosing a suitable h, assuming that HNLS is violated. We therefore have α dt = O(dt) and β dt = O(dt 2 ), so that the second term in the RHS of Eq. (11) vanishes as dt → 0: proving that SQL scaling cannot be surpassed when HNLS is violated (the necessary condition in Theorem 1). We require the probe to be finite dimensional in the statement of Theorem 1 because otherwise the norm of α dt or β dt could be infinite. The theorem can be applied to the case of a probe with an infinitedimensional Hilbert space if the state of the probe is confined to a finite-dimensional subspace even for asymptotically large t.
QEC code for HL scaling when HNLS holds. To prove the sufficient condition for HL scaling, we show that a QEC code achieving HL scaling can be explicitly constructed if H(ω) is not in the linear span S. Our discussion of the qubit probe indicates how a QEC code can be used to achieve HL scaling for estimating the parameter ω. The code allows us to correct quantum jumps whenever they occur, and in addition the noiseless errorcorrected evolution in the code space depends nontrivially on ω. Similar considerations apply to higher-dimensional probes. Let Π C denote the projection onto the code space. Jumps are correctable if the code satisfies the error correction conditions 31-33 , namely: for some complex numbers λ k and μ kj . The error-corrected joint state of probe and ancilla evolves according to the unitary channel (asymptotically) where H eff = Π C HΠ C = ωG eff . There is a code state for which the evolution depends nontrivially on ω provided that For this noiseless evolution with effective Hamiltonian ωG eff , the QFI of the encoded state at time t is where ρ in is the initial state at time t = 0. The QFI is maximized by choosing the initial pure state where λ min j i, λ max j i are the eigenstates of G eff with the minimal and maximal eigenvalues; with this choice the QFI is By measuring in the appropriate basis at time t, we can estimate ω with a precision that saturates the Cramér-Rao bound in the asymptotic limit of a large number of measurements, hence realizing HL scaling.
To prove the sufficient condition in Theorem 1, we will now show that a code with properties (1)-(3) can be constructed whenever HNLS is satisfied. (For further justification of these conditions see the Methods.) In this code construction we make use of a noiseless ancilla system, but as we discuss in the Methods, the construction can be extended to the case where the ancilla system is subject to Markovian noise obeying suitable conditions.
To see how the code is constructed, note that the ddimensional Hermitian matrices form a real Hilbert space where the inner product of two matrices A and B is defined to be tr(AB). Let S denote the subspace of Hermitian matrices spanned by I, L k þ L y k , i L k À L y k , L y k L j þ L y j L k , and i L y k L j À L y j L k for all k, j. Then G has a unique decomposition into G ¼ G k þ G ? , where G k 2 S and G ? ?S.
If HNLS holds, then G ? is nonzero. It must also be traceless, in order to be orthogonal to I, which is contained in S. Therefore, using the spectral decomposition, we can write G ? ¼ 1 2 tr G ? j j ð Þðρ 0 À ρ 1 Þ, where ρ 0 and ρ 1 are trace-one positive matrices with orthogonal support and G ? j j :¼ ffiffiffiffiffiffi ffi G 2 ? p . Our QEC code is chosen to be the two-dimensional subspace of H P H A spanned by |C 0 〉 and |C 1 〉, which are normalized purifications of ρ 0 and ρ 1 respectively, with orthogonal support in H A . (If the probe is d-dimensional, a d-dimensional ancilla can purify its state.) Because the code basis states have orthogonal support on H A , it follows that, for any O acting on H P , and furthermore In particular, for any O in the span S we have tr G ? O ð Þ¼0, and therefore Code properties (1)-(3) now follow from Eqs. (24) and (26). For this two-dimensional code, the projector onto the code space is and therefore for O 2 S, which implies properties (1) and (2) because L k and L y k L j are in S. Property (3) is also satisfied by the code, because À Á =tr G ? j j>0, which means that the diagonal elements of Π C GΠ C are not equal when projected onto the code space. Thus, we have demonstrated the existence of a code with properties (1) and (3).
Code optimization. When HNLS is satisfied, we can use our QEC code, along with fast and accurate quantum control, to achieve noiseless evolution of the error-corrected probe, governed by the effective Hamiltonian H eff = Π C HΠ C = ωG eff where Π C is the orthogonal projection onto the code space. Because the optimal initial state Eq. (22) is a superposition of just two eigenstates of G eff , a two-dimensional QEC code suffices for achieving the best possible precision. For a code with basis states {|C 0 〉, |C 1 〉}, the effective Hamiltonian is here we have ignored the contribution due to G k , which is an irrelevant additive constant if the code satisfies condition (2). We have seen how to construct a code for which It is possible, though, that a larger value of this difference of eigenvalues could be achieved using a different code, improving the precision by a constant factor (independent of the time t).
To search for a better code, with basis states {|C 0 〉, |C 1 〉}, definẽ and considerG ¼ρ 0 Àρ 1 : Conditions (1)-(2) on the code imply and we want to maximize over matricesG of the form Eq. (32) subject to Eq. (33). Note that G is the difference of two normalized density operators, and therefore satisfies trG 2. In fact, though, ifG obeys the constraint Eq. (33), then the constraint is still satisfied if we rescaleG by a real constant greater than one, which increases tr G ?G À Á ; hence the maximum of tr G ?G À Á is achieved for trG ¼ 2, which means thatρ 0 andρ 1 have orthogonal support. Now recall that G ? ¼ 1 2 tr G ? j j ð Þ ρ 0 À ρ 1 ð Þ is also (up to normalization) a difference of density operators with orthogonal support, and obeys the constraint Eq. (33). The quantity to be maximized is proportional to If ρ 0 and ρ 1 are both rank 1, then the maximum is achieved by choosingρ 0 ¼ ρ 0 andρ 1 ¼ ρ 1 . Conditions (1)-(2) are satisfied by choosing |C 0 〉 and |C 1 〉 to be purifications of ρ 0 and ρ 1 with orthogonal support on H A . Thus, we have recovered the code we constructed previously. If ρ 0 or ρ 1 is higher rank, though, then a different code achieves a higher maximum, and hence better precision for parameter estimation. Fig. 2 Schematic illustration of HNLS and code optimization. a G ? is the projection of G onto S in the Hilbert space of Hermitian matrices equipped with the Hilbert-Schmidt norm ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi trðO Á OÞ p . G ? ≠0 if and only if G= 2S, which is the HNLS condition. bG } is the projection of G onto S in the linear space of Hermitian matrices equipped with the operator norm O k k ¼ max ψ j i ψ h jO ψ j i. In general, the optimal QEC code can be contructed fromG } andG } is not necessarily equal to G ? Geometrical picture. There is an alternative description of the code optimization, with a pleasing geometrical interpretation. As discussed in the Methods, the optimization can be formulated as a SDP with a feasible dual program. By solving the dual program we find that, for the optimal QEC code, the QFI is where Á k k denotes the operator norm. In this sense, the QFI is determined by the minimal distance between G ? and S (Fig. 2b).
We can recover the solution to the primal problem from the solution to the dual problem. We denote byG } k the choice of G k 2 S that minimizes Eq. (36), and we definẽ ThenG Ã that maximizes Eq. (34) has the form whereρ } 0 is a density operator supported on the eigenspace ofG } with the maximal eigenvalue, andρ } 1 is a density operator supported on the eigenspace ofG } with the minimal eigenvalue. The minimization in Eq. (36) ensures thatG Ã of this form can be chosen to obey the constraint Eq. (33).
In the noiseless case S ¼ spanfIg ð Þ , the minimum in Eq. (36) occurs when the maximum and minimum eigenvalues G ? ÀG k have the same absolute value, and then the operator norm is half the difference of the maximum and minimum eigenvalues of G ? . Hence, we recover the result Eq. (23). When noise is introduced, S swells and the minimal distance shrinks, lowering the QFI and reducing the precision of parameter estimation. If HNLS fails, then the minimum distance is zero, and no QEC code can achieve HL scaling, in accord with Theorem 1.
Kerr effect with photon loss. To illustrate how the optimization procedure works, consider a bosonic mode with the nonlinear (Kerr effect 50 ) Hamiltonian where our objective is to estimate ω. In this case, the probe is infinite dimensional, but suppose we assume that the occupation number n = a † a is bounded: n n, where n is even. The noise source is photon loss, with Lindblad jump operator L / a. Can we find a QEC code that protects the probe against loss and achieves HL scaling for estimation of ω?
To solve the dual program, we find real parameters α, β, γ, δ, which minimize the operator norm of where n n. Since a and a † are off-diagonal in the occupation number basis, we should set β and γ to zero for the purpose of minimizing the difference between the largest and smallest eigenvalue ofñ 2 . After choosing α such thatñ 2 is minimized at n ¼ n=2, and choosing δ so that the maximum and minimum eigenvalues ofñ 2 are equal in absolute value and opposite in sign, we haveñ 2 À Á } ¼ n À 1 2 which has operator normñ 2 ð Þ } ¼ n 2 =8; hence the optimal QFI after evolution time t is F ρðtÞ ð Þ ¼ t 2 n 4 =16, according to Eq. (36). For comparison, the minimal operator norm is n 2 =2 for a noiseless bosonic mode with n n. We see that loss reduces the precision of our estimate of ω, but only by a factor of 4 if we use the optimal QEC code. HL scaling can still be maintained. The scaling δω $ 1=n 2 of the optimal precision arises from the nonlinear boson-boson interactions in the Hamiltonian Eq. (39) 51 .
To find the code states, we note that the eigenstate ofñ 2 ð Þ } with the lowest eigenvalue Àn 2 =8 is n ¼ n=2 j i , while the largest eigenvalue þn 2 =8 has the two degenerate eigenstates |n = 0〉 and n ¼ n j i. The code condition (2) requires that both code vectors have the same expectation value of L † L ∝ n, and we therefore may choose as the code achieving optimal precision. For n ! 4, the ancilla may be discarded, and we can use the simpler code which is easier to realize experimentally. Eqs. (17) and (18) are still satisfied without the ancilla, because the states C 0 j i; C 1 j i; a C 0 j i; a C 1 j i f gare all mutually orthogonal. This encoding Eq. (43) belongs to the family of "binomial quantum codes" which, as discussed in ref. 52 , can protect against loss of bosonic excitations.
An experimental realization of this coding scheme can be achieved using tools from circuit quantum electrodynamics, by coupling a single transmon qubit to two microwave waveguide resonators. For example, when n is a multiple of 4, C 0 j i and C 1 j i both have even photon parity while a C 0 j i and a C 1 j i both have odd parity. Then QEC can be carried out by the following procedure: (1) a quantum non-demolition parity measurement is performed to check whether photon loss has occurred 38,53 . (2) If photon loss is detected, the initial logical encoding is restored using optimal control pulses 38,39 . (3) If there is no photon loss, the quantum state is projected onto the code space span C 0 j i; C 1 j i f g 54 . The probability of an uncorrectable logical error becomes arbitrarily small if the QEC procedure is sufficiently fast compared to the photon loss rate. Meanwhile, the Kerr signal accumulates coherently in the relative phase of | C 0 〉 and |C 1 〉, so that HL scaling can be attained for arbitrarily fast quantum control. For integer values of n that are not a multiple of 4, coding schemes can still be constructed that protect against photon loss, as described in ref. 52 .
Approximate error correction. Generic Markovian noise is full rank, which means that the span S is the full Hilbert space H P of the probe; hence the HNLS criterion of Theorem 1 is violated for any probe Hamiltonian H(ω), and asymptotic SQL scaling cannot be surpassed. Therefore, for any Markovian noise model that meets the HNLS criterion, the HL scaling achieved by our QEC code is not robust against generic small perturbations of the noise model.
We should therefore emphasize that a substantial improvement in precision can be achieved using a QEC code even in cases where HNLS is violated. Consider in particular a Markovian master equation with Lindblad operators divided into two sets {L k } (L-type noise) and {J m } (J-type noise), where the J-type noise is parametrically weak, with noise strength ( Á k k denotes the operator norm). If we use the optimal code that protects against L-type noise, then the joint logical state of (See the Methods for further discussion.) This means that the state of the error-corrected probe deviates by a distance O ϵt ð Þ (in the L 1 norm) from the (effectively noiseless) evolution in the absence of J-type noise. Therefore, using this code, the QFI of the error-corrected probe increases quadratically in time (and the precision δω scales like 1/t) up until an evolution time t / 1=ϵ, before crossing over to asymptotic SQL scaling.

Discussion
Noise limits the precision of quantum sensing. Quantum error correction can suppress the damaging effects of noise, thereby improving the fidelity of quantum information processing and quantum communication, but whether QEC improves the efficacy of quantum sensing depends on the structure of the noise and the signal Hamiltonian. Unless suitable conditions are met, the QEC code that tames the noise might obscure the signal as well, nullifying the advantages of QEC.
Our study of quantum sensing using a noisy probe has focused on whether the precision δ of parameter estimation scales asymptotically with the total sensing time t as δ / 1/t (HL) or δ / 1= ffiffi t p (SQL). We have investigated this question in an idealized setting, where the experimentalist has access to noiseless (or correctable) ancillas and can apply quantum controls that are arbitrarily fast and accurate, and we have also assumed that the noise acting on the probe is Markovian. Under these assumptions, we have found the general criterion for HL scaling to be achievable, the HNLS criterion. If HNLS is satisfied, a QEC code can be constructed that achieves HL scaling, and if HNLS is violated, then SQL scaling cannot be surpassed.
In the case where HNLS is satisfied, we have seen that the QEC code achieving the optimal precision can be chosen to be twodimensional, and we have described an algorithm for constructing this optimal code. The precision attained by this code has a geometrical interpretation in terms of the minimal distance (in the operator norm) of the signal Hamiltonian from the "Lindblad span" S, the subspace spanned by I, L k , L y k , and L y k L j , where {L k } is the set of Lindblad jump operators appearing in the probe's Markovian master equation.
Many questions merit further investigation. We have focused on the dichotomy of HL vs. SQL scaling, but it is also worthwhile to characterize constant factor improvements in precision that can be achieved using QEC in cases where HNLS is violated 55 . We should clarify the applications of QEC to sensing when quantum controls have realistic accuracy and speed. Finally, it is interesting to consider probes subject to non-Markovian noise. In that case, tools such as dynamical decoupling [56][57][58][59] can mitigate noise, but just as for QEC, we need to balance desirable suppression of the noise against undesirable suppression of the signal in order to formulate the most effective sensing strategy.
Note added: During the preparation of this manuscript, we became aware of related work by Demkowicz-Dobrzański et al. 60 , which provided a similar proof of the necessary condition in Theorem 1 and an equivalent description of the QEC conditions Eqs. (17), (18), and (20). We and the authors of ref. 60 obtained this result independently. Both our paper and ref. 60 generalize results obtained earlier in ref. 37 .

Methods
Linear scaling of the QFI. Here we prove that the QFI scales linearly with the evolution time t in the case where the HNLS condition is violated. We follow the proof in ref. 37 , which applies when the probe is a qubit, and generalize their proof to the case where the probe is d-dimensional.
We approximate the quantum channel by the following one:Ẽ where K 0 ¼ I þ ÀiωG À 1 2 P r k¼1 L y k L k dt and K k ¼ L k ffiffiffiffi ffi dt p for k ≥ 1. The approximation is valid because the distance between E dt andẼ dt is O(dt 2 ) and the sensing time is divided into t dt segments, meaning the error O t dt Á dt 2 À Á ¼ OðtdtÞ introduced by this approximation in calculating the QFI vanishes as dt→0. Next, we calculate the operators the channelẼ dt ðρÞ, and expand these operators as a power series in ffiffiffiffi ffi dt p : We will now search for a Hermitian matrix h that sets low-order terms in each power series to 0. Expanding , and using the notation Therefore h (0) K (0) = 0 and α (1) = β (0) = 0 are automatically satisfied. Then, β ð1Þ ¼ ÀK ð0Þy h ð1Þ K ð0Þ ¼ Àh which can be set to 0 if and only if G is a linear combination of I; L k ; L y k and L y k L j (0 ≤ k, j ≤ r).
In addition, can be satisfied by setting the above parameters (which do not appear in the expressions for α (0,1) and β (0,1,2) ) all to 0 (other terms in β (3) are 0 because of the constraints on h (0) and h (1) in Eqs. (50) and (51)). Therefore, when G is a linear combination of I; L k ; L y k and L y k L j , there exists an h such that α dt = O(dt) and β dt = O (dt 2 ) for the quantum channelẼ dt ; therefore the QFI obeys in which α ð2Þ ¼ h ð1Þ K ð0Þ þ h ð0Þ K ð1Þ À Á y h ð1Þ K ð0Þ þ h ð0Þ K ð1Þ À Á under the constraint β (2) = 0.
The QEC condition. Here we consider the quantum channel Eq. (2), which describes the joint evolution of a noisy quantum probe and noiseless ancilla over time interval dt. Suppose that a QEC code obeys the conditions (1) and (2) in Eqs. (17) and (18), where Π C is the orthogonal projector onto the code space. We will construct a recovery operator such that the error-corrected time evolution is unitary to linear order in dt, governed by the effective Hamiltonian H eff = ωΠ C GΠ C .
For a density operator ρ = Π C ρΠ C in the code space, conditions (1) and (2) imply where Π E = I − Π C . When acting on a state in the code space, Π E E d tðÁÞΠ E is an operation with Kraus operators which obey the normalization condition where we have used conditions (1) and (2). Therefore, if ρ is in the code space, then a recovery channel R E ðÁÞ such that can be constructed, provided that the operators L k À λ k f g r k¼1 satisfy the standard QEC conditions [31][32][33] . Indeed, these conditions are satisfied because completely reverses the effects of the noise. The channel describing time evolution for time dt followed by an instantaneous recovery step is a noiseless unitary channel with effective Hamiltonian ωΠ C GΠ C if O(dt 2 ) corrections are neglected. The dependence of the Hamiltonian on ω can be detected, for a suitable initial code state ρ in , if and only if Π C GΠ C has at least two distinct eigenvalues. Thus, for nontrivial error-corrected sensing we require condition (3): Error-correctable noisy ancillas. In the main text, we assumed that a noiseless ancilla system is available for the purpose of constructing the QEC code. Here, we relax that assumption. We suppose instead that the ancilla is subject to Markovian noise, which is uncorrelated with noise acting on the probe. Hence, the joint evolution of probe and ancilla during the infinitesimal time interval dt is described by the quantum channel where {L k } are Lindblad jump operators acting on the probe, and L′ k f g are Lindblad jump operators acting on the ancilla.
In this case, we may be able to protect the probe using a code C scheme with two layers-an "inner code" C′ and an "outer code" C. Assuming as before that arbitrarily fast and accurate quantum processing can be performed, and that the Markovian noise acting on the ancilla obeys a suitable condition, an effectively noiseless encoded ancilla can be constructed using the inner code. Then, the QEC scheme that achieves HL scaling can be constructed using the same method as in the main text, but with the encoded ancilla now playing the role of the noiseless ancilla used in our previous construction.
Errors on the ancilla can be corrected if the projector Π C′ onto the inner code C′ satisfies the conditions.
Eqs. (63) and (64) resemble Eqs. (17) and (18), except that the inner code C′ is supported only on the ancilla system H A , while the code C in Eqs. (17) and (18) is supported on the joint system H P H A of probe and ancilla. To search for a suitable inner code C′, we may use standard QEC methods; namely we seek an encoding of the logical ancilla with sufficient redundancy for Eqs. (63) and (64) to be satisfied. Given a code C that satisfies Eqs. (17), (18), and (20) for the case of a noiseless ancilla, and a code C′ supported on a noisy ancilla that satisfies Eqs. (63) and (64), we construct the code C that achieves HL scaling for a noisy ancilla system by "concatenating" the inner code C′ and the outer code C. That is, if the basis states for the code C are {|C 0 〉, |C 1 〉}, where then the corresponding basis states for the code C are C 0 ; C 1 , where and C′ k j i denotes the basis state of C′ which encodes |k〉. Using our fast quantum controls, the code C′ protects the ancilla against the Markovian noise, and the code C then protects the probe, so that HL scaling is achievable.
In fact, the code that achieves HL scaling need not have this concatenated structure; any code that corrects both the noise acting on the probe and the noise acting on the ancilla will do. For Markovian noise acting independently on probe and ancilla as in Eq. (62), the conditions Eqs. (17) and (18) on the QEC code should be generalized to here S ¼ span I; L k ; L y k ; L y j L k ; 8k; j n o , S′ ¼ span I; L′ k ; L′ y k ; L′ y j L′ k ; 8k; j n o , and Π C is the projector onto the code C supported on H P H A . The condition Eq. (20) remains the same as before, but now applied to the code C: Π C ðG IÞΠ C ≠constant Π C . When these conditions are satisfied, the noise acting on probe and ancilla is correctable; rapidly applying QEC makes the evolution of the probe effectively unitary (and nontrivial), to linear order in dt.
Robustness of the QEC scheme. We consider the following quantum channel, where the "J-type noise," with Lindblad operators fJ m g r2 m¼1 , is regarded as a small perturbation: We assume that the "L-type noise," with Lindblad operators L k f g r1 k¼1 , obeys the QEC conditions (1) and (2), and that R is the recovery operation that corrects this noise. By applying this recovery step after the action of E dt on a state ρ in the code space, we obtain a modified channel with residual J-type noise.
Suppose that R has the Kraus operator decomposition R σ ð Þ ¼ P s j¼1 R j σR y j , where P s j¼1 R y j R j ¼ I. We also assume that R j = Π C R j , because the recovery procedure has been constructed such that the state after recovery is always in the code space. Then to first order in dt, where Á k k denotes the operator norm. If the noise strength Code optimization as a semidefinite program. Optimization of the QEC code can be formulated as the following optimization problem: maximize trGG ? À Á subject to trG À Á 2 and trG À Á This optimization problem is convex (because tr|·| is convex) and satisfies the Slater's condition, so it can be solved by solving its Lagrange dual problem 61 . The Lagrangian LG; λ; ν À Á is defined for λ ≥ 0 and ν k 2 R: LG; λ; ν À Á ¼ trGG ?
where {E k } is any basis of S. The optimal value is obtained by taking the minimum of the dual g λ; ν ð Þ ¼maxG LG; λ; ν À Á over λ and {ν k }, where Á k k ¼ max ψ j i ψ h j Á ψ j i j jis the operator norm. Hence the optimal value of the primal problem is The optimization problem Eq. (75) is equivalent to the following SDP: 61 minimize s subject to for variables ν k 2 R and s # 0. Here "δ0" denotes positive semidefinite matrices. SDPs can be solved using the Matlab-based package CVX 62 .
Once we have the solution to the dual problem, we can use it to find the solution to the primal problem. We denote by λ } and ν } the values of λ and ν where g(λ,ν) attains its minimum, and definẽ The minimum g λ } ; ν } À Á matches the value of the Lagrangian LG; λ } ; ν } À Á whenG ¼G Ã is the value ofG that maximizes trGG ? À Á subject to the constraints. This means that Since we require trG Ã À Á ¼ 0 and trG Ã ¼ 2, and because minimizing g(λ,ν) enforces that the maximum and minimal eigenvalues ofG } have the same absolute value and opposite sign, we conclude that whereρ } 0 is a density operator supported on the eigenspace ofG } with the maximal eigenvalue, andρ } 1 is a density operator supported on the eigenspace of G } with the minimal eigenvalue. AG Ã of this form which satisfies the constraints of the primal problem is guaranteed to exist.
Data availability. Data sharing not applicable to this article as no data sets were generated or analyzed during the current study.