Continuous quantum error correction requires a controller to infer errors from noisy measurements and act on that inference. Using the three qubit bit flip code, we implement this process in Wolfram Language and evolve the physical state alongside the controller’s estimate. The calculations examine the effects of uncertainty about the initial state, incorrectly assumed detector efficiency, and residual logical errors. We then compare two feedback schemes as detector efficiency varies.
In this computational essay, we encode one qubit of quantum information, called a logical qubit, in three physical qubits. We represent logical zero by
|
0
L
〉=|000〉
and logical one by
|
1
L
〉=|111〉
. These two states span the two dimensional code subspace. Let
X
i
and
Z
i
denote the Pauli
X
and
Z
operators acting on physical qubit
i
. Our aim is to preserve an initial logical state while bit flip errors
X
i
, with
i=1,2,3
, act on the qubits. We continuously measure two stabilizers,
S
1
=
Z
1
Z
2
and
S
2
=
Z
2
Z
3
, each testing whether neighboring qubits agree or differ in the computational basis. The four possible pairs of stabilizer outcomes, called syndromes, label the code subspace and three error subspaces. The measurements produce two noisy records from which a classical controller estimates syndrome probabilities and determines corrective drives.
To implement this controller, we first ask what information must be retained to update the syndrome probabilities as new measurements arrive. With feedback off, the four probabilities can be updated using only their current values and the new measurement record increments. With the feedback Hamiltonian used here, their evolution also depends on coherences between the syndrome subspaces. Our implementation therefore updates a density matrix estimate and extracts the syndrome probabilities from it.
We then assess how well the feedback preserves the initial logical state by calculating the physical state’s fidelity with that state. Logical zero and logical one have the same syndrome, so syndrome probabilities alone cannot establish successful preservation. We examine how uncertainty in the controller’s initial estimate and incorrectly assumed detector efficiency affect fidelity, then examine the remaining fidelity loss. Finally, we compare feedback based on the syndrome estimate with a Markovian feedback scheme that monitors the bit flip error channels and applies feedback directly from their records, without maintaining a state estimate. For this comparison, we vary detector efficiency and calculate the probability of the code syndrome.
We set
ℏ=1
throughout.

The Stochastic Master Equation

Let
ρ
c
(t)
denote the density matrix of the physical qubits conditioned on the measurement record up to time
t
. Each qubit undergoes independent bit flip errors
X
i
at rate
γ
. We continuously measure
S
1
and
S
2
, each with measurement strength
κ
and detector efficiency
η∈
. The feedback Hamiltonian
H
fb
combines single qubit
X
i
drives; setting
H
fb
=0
turns feedback off. The conditional state obeys the stochastic master equation:
d
ρ
c
=γ
3
∑
i=1
𝒟[
X
i
]
ρ
c
dt+κ
∑
k
𝒟[
S
k
]
ρ
c
dt+
ηκ
∑
k
ℋ[
S
k
]
ρ
c
d
W
k
-i[
H
fb
,
ρ
c
]dt,
For an operator
c
, the dissipator and measurement superoperator are
𝒟[c]ρ=cρ
†
c
-
1
2
{
†
c
c,ρ},    ℋ[c]ρ=cρ+ρ
†
c
-Tr[(c+
†
c
)ρ]ρ,
where
{A,B}=AB+BA
.
The two detectors supply measurement record increments
d
Q
k
=2
ηκ
〈
S
k
〉
c
dt+d
W
k
,    k=1,2,
where
〈
S
k
〉
c
=Tr[
S
k
ρ
c
]
. The independent Wiener increments
d
W
k
have zero mean and variance
dt
. Each detector increment therefore combines a signal determined by the conditional state with noise.
The error terms change the syndrome probabilities. The deterministic measurement terms suppress coherences between syndrome subspaces without changing those probabilities, while the stochastic measurement terms update the conditional state using the measurement records. The commutator describes the unitary evolution generated by the feedback Hamiltonian.
We use this equation to study syndrome estimation with
H
fb
=0
and correction with
H
fb
determined by the controller’s estimate. The Markovian feedback scheme introduced later monitors the bit flip error channels and requires a separate master equation, which we give there. We begin by defining the Wolfram Language functions for deterministic evolution and conditional state updates.

Numerical Methods

These are the catalog's functions, reproduced so the notebook is self-contained, with one added guard in
measurementStep
that checks there is one efficiency per watched operator. If you have run the catalog you can evaluate this section without reading it and return only when you want the implementation. The Pauli matrices and the two-by-two identity first:
In[]:=
{id2,X,Y,Z}=Table[PauliMatrix[j],{j,0,3}];
The density matrix of a pure state:
In[]:=
densityMatrix[v_]:=KroneckerProduct[v,Conjugate[v]];
The unitary commutator, the coherent part of the motion:
In[]:=
commutatorTerm[H_,rho_]:=-I(H.rho-rho.H);
The dissipator, the incoherent part each leak channel contributes:
In[]:=
dissipator[c_,rho_]:=c.rho.ConjugateTranspose[c]-​​(ConjugateTranspose[c].c.rho+rho.ConjugateTranspose[c].c)/2;
The Lindbladian that sums the coherent term and every dissipator:
In[]:=
lindbladian[H_,leaks_List,rho_]:=commutatorTerm[H,rho]+Total[dissipator[#,rho]&/@leaks];
The master equation solved two independent ways, once by exponentiating the Liouvillian (the matrix that enacts
ℒ
on the vectorized state) and once by an ODE solver, so any result can be cross-checked:
In[]:=
liouvillian[H_,leaks_List,d_]:=With[{id=IdentityMatrix[d]},​​-I(KroneckerProduct[H,id]-KroneckerProduct[id,Transpose[H]])+​​Total[Function[c,KroneckerProduct[c,Conjugate[c]]-​​(KroneckerProduct[ConjugateTranspose[c].c,id]+​​KroneckerProduct[id,Transpose[ConjugateTranspose[c].c]])/2]/@leaks]];
In[]:=
evolve[H_,leaks_List,rho0_,t_]:=With[{d=Length[rho0]},​​ArrayReshape[MatrixExp[liouvillian[H,leaks,d]t].Flatten[rho0],{d,d}]];
In[]:=
evolveODE[H_,leaks_List,rho0_,t1_]:=​​NDSolveValue[{s'[t]==lindbladian[H,leaks,s[t]],s[0]==N@rho0},s,{t,0,t1}];
The positivity-preserving measurement step of Rouchon and Ralph (2015), which conditions the state on a record increment without ever leaving the set of valid states, given the watched operators, their detector efficiencies, the unwatched leaks, and the time step:
In[]:=
measurementStep[H_,watched_,effs_,unwatched_,dt_]:=Enclose[​​Module[{d=Length[H],id=IdentityMatrix[Length[H]],channels=Join[watched,unwatched],drift,corr},​​ConfirmAssert[VectorQ[effs,0<=#<=1&],"efficiencies must lie in [0,1]"];​​ConfirmAssert[TrueQ[dt>0],"time step must be positive"];​​ConfirmAssert[Length[effs]==Length[watched],"one efficiency per watched operator"];​​drift=IH+Fold[Plus,0H,ConjugateTranspose[#].#&/@channels]/2;​​corr=Fold[Plus,0H,MapThread[#1(#2.#2)&,{effs,watched}]]/2;​​Function[{rho,dJ},Module[{sig,M,top,nrm},​​sig=Fold[Plus,0H,MapThread[Sqrt[#2]#1#3&,{dJ,effs,watched}]];​​M=id-driftdt+sig+sig.sig/2-corrdt;​​top=M.rho.ConjugateTranspose[M]+​​dtFold[Plus,0H,#.rho.ConjugateTranspose[#]&/@unwatched]+​​dtFold[Plus,0H,MapThread[(1-#2)#1.rho.ConjugateTranspose[#1]&,{watched,effs}]];​​nrm=Re@Tr[top];​​If[TrueQ[nrm>0],top/nrm,​​Failure["NonPositiveNormalization",<|"Normalization"->nrm|>]]]]]];
Generate the measurement record increment at one time step, consisting of a signal term and a Gaussian noise increment:
In[]:=
measurementRecord[rho_,watched_List,effs_List,dt_,kick_List]:=​​MapThread[Sqrt[#3]Re@Tr[(#1+ConjugateTranspose[#1]).rho]dt+#2&,​​{watched,kick,effs}];
Generate one trajectory by drawing Wiener increments, constructing the measurement record increments, and updating the conditional state at each time step:
In[]:=
trajectory[rho0_,H_,watched_List,effs_List,unwatched_List,dt_,tf_,seed_]:=​​BlockRandom[SeedRandom[seed];​​Module[{n=Round[tf/dt],step,kicks,states,record},​​step=measurementStep[H,watched,effs,unwatched,dt];​​kicks=RandomVariate[NormalDistribution[0,Sqrt[dt]],{n,Length[watched]}];​​states=FoldList[​​Function[{r,dw},step[r,measurementRecord[r,watched,effs,dt,dw]]],rho0,kicks];​​record=MapThread[measurementRecord[#1,watched,effs,dt,#2]&,{Most[states],kicks}];​​<|"times"->dtRange[0,n],"states"->states,"record"->record|>]];
With the toolkit in hand, we build the code.

The Three Qubit Bit Flip Code and Its Syndromes

The three-qubit bit-flip code stores one logical qubit in three physical qubits, with logical basis states
|
0
L
〉=|000〉
and
|
1
L
〉=|111〉
. They span the two-dimensional code subspace within the eight-dimensional space of three qubits. An arbitrary encoded state is
α|
0
L
〉+β|
1
L
〉
. A single-qubit bit flip moves this state into an orthogonal error subspace, allowing us to detect the error without learning
α
or
β
.
We need single-qubit operators acting on one of the three qubits. Define an operator that places
o
on qubit
i
and the identity on the other two, as a Kronecker product:
In[]:=
op3[o_,i_]:=KroneckerProduct@@ReplacePart[{id2,id2,id2},i->o];
The Wolfram Quantum Framework provides an elegant way to work with composite quantum systems. In this notebook, we build the needed structures ourselves using only built-in Wolfram Language functions.
Next, define the three-qubit computational basis kets, indexed by their bit strings:
In[]:=
ket[bits_List]:=Normal@SparseArray[FromDigits[bits,2]+1->1,8];
To detect single qubit bit flips, we monitor two operators called stabilizers:
S
1
=
Z
1
Z
2
and
S
2
=
Z
2
Z
3
. Each acts on two neighboring qubits, giving outcome
+1
for
|00〉
and
|11〉
, and
-1
for
|01〉
and
|10〉
. The measurement distinguishes these two groups without distinguishing the states within either group.
Build
S
1
=
Z
1
Z
2
:
In[]:=
S1=op3[Z,1].op3[Z,2];
Build
S
2
=
Z
2
Z
3
:
In[]:=
S2=op3[Z,2].op3[Z,3];
First, find the eigenvalues of each stabilizer and count how many times each occurs:
In[]:=
Counts@*Eigenvalues/@{S1,S2}
Out[]=
{-14,14,-14,14}
The pair of stabilizer outcomes is called the syndrome. We will verify below that its four possible values
(±1,±1)
label four two dimensional subspaces.
Confirm that
|000〉
and
|111〉
are
+1
eigenstates of both stabilizers:
In[]:=
{S1.ket[{0,0,0}]==ket[{0,0,0}],S2.ket[{0,0,0}]==ket[{0,0,0}],​​S1.ket[{1,1,1}]==ket[{1,1,1}],S2.ket[{1,1,1}]==ket[{1,1,1}]}
Out[]=
{True,True,True,True}
Both logical basis states give the same stabilizer outcomes, so the stabilizer measurements modeled here preserve any superposition of them.
By linearity,
S
1
and
S
2
leave every encoded state
α|
0
L
〉+β|
1
L
〉
unchanged. Verify this directly with symbolic
α
and
β
:
In[]:=
With[{ψL=αket[{0,0,0}]+βket[{1,1,1}]},​​{S1.ψL==ψL,S2.ψL==ψL}]
Out[]=
{True,True}
These operators are called stabilizers because they act as the identity on the code subspace.
Logical operations act on the encoded qubit while preserving the code subspace. The logical bit flip
X
L
=
X
1
X
2
X
3
exchanges
|
0
L
〉
and
|
1
L
〉
. The logical phase flip
Z
L
=
Z
1
leaves
|
0
L
〉
unchanged and multiplies
|
1
L
〉
by
-1
.
Build
X
L
=
X
1
X
2
X
3
:
In[]:=
XL=op3[X,1].op3[X,2].op3[X,3];
Build
Z
L
=
Z
1
:
In[]:=
ZL=op3[Z,1];
Confirm both commute with the two stabilizers:
In[]:=
{XL.S1==S1.XL,XL.S2==S2.XL,ZL.S1==S1.ZL,ZL.S2==S2.ZL}
Out[]=
{True,True,True,True}
These commutation relations ensure that
X
L
and
Z
L
preserve the code subspace and leave the syndrome unchanged.
Those eight pairs are not all different. Group the states by the pair of signs they return:
Build the eight-dimensional identity matrix:
Then the four sector projectors, collected into an Association keyed by the sign pair:
Verify completeness: the four projectors must sum to the identity, ensuring that the four syndrome probabilities sum to one for any normalized state:
A projector's rank gives the dimension of its syndrome subspace. Compute the four ranks:
Show it as a matrix:

Syndrome Estimation Without Feedback

Continuous measurement of the two stabilizers provides two noisy records from which we can infer the syndrome. Correcting a bit flip requires an additional physical operation that reverses its effect on the encoded state. These are two distinct tasks:
1
.
Diagnosis: use the noisy measurement record to estimate the syndrome.
2
.
Correction: apply a control operation to restore the original encoded state.
Feedback stays off throughout this section. We build a filter that uses the measurement record to track the changing syndrome as bit flips occur.

Continuous Stabilizer Measurement

The Syndrome Probability Equations

Bit flips transfer population between sectors. The deterministic measurement term suppresses coherence between sectors without changing their populations, while the stochastic term updates the probabilities from the measurement record. Simplifying these contributions gives a system of coupled stochastic differential equations for the four syndrome probabilities:
Here:

Implementing the Syndrome Filter

We implement the filter with two operations per time step: predict the syndrome probabilities under the bit flip dynamics, then update them using the new pair of measurement record increments.

Tracking Bit Flip Errors

Initialize the filter with certainty that the state is in the code sector:
Feed the measurement record to the filter, starting from the same syndrome distribution as the conditional state:
Compare the filter's probabilities with those extracted from the conditional states. Both use the same initial syndrome distribution, measurement record, rates, and detector efficiency. Compute the largest absolute difference across all sectors and times:
The two methods use different numerical updates for the same continuous population equation, so a finite time step can produce a discrepancy.
Plot the filter's four probabilities as the run unfolds:
The filter starts certain of the code sector and uses successive measurement record increments to track the changing syndrome. The plotted curves are inferred probabilities; the simulation does not separately sample exact bit flip times. No corrective operation responds to these estimates, so learning the syndrome does not repair the encoded state. The next section uses the syndrome estimate to drive a feedback Hamiltonian.

Continuous Correction from the State Estimate

From the Estimate to the Feedback Hamiltonian

From its updated estimate, the controller computes the three error sector probabilities,
and sets the Hamiltonian for the next interval to
Compare the information flow with and without feedback. First, define a helper that draws labeled boxes and arrows showing the dependencies:
With feedback off, the Hamiltonian is fixed independently of the measurement record. The diagram shows how the current conditional state and the new pair of measurement record increments enter the next update, together with the Hamiltonian and bit flip dynamics:

Implementing the Feedback Rule

Fidelity With and Without Feedback

Form the watched operators at the new strength:
Average the states across the forty trajectories at each integration time:
Evaluate the uncorrected baseline at the same times, using the master equation with errors on and feedback off:
Compare the mean fidelity with and without feedback. For this initial state and error model, averaging the conditional state over the stabilizer measurement records with feedback off gives the same evolution as bit flip errors alone, so the master equation supplies the baseline.
Feedback improves the mean fidelity for these parameters. Resolving the noisy syndrome and applying a correction both take time, while bit flip errors continue to act. The remaining loss of fidelity can reflect population outside the code subspace or a change of logical state within it. We will distinguish these contributions in “Residual Fidelity Loss.”
The plot estimates the mean fidelity for one randomly chosen logical input using forty trajectories. Reevaluating the cell chooses another input while retaining the same noise seeds. These examples do not establish equal performance for all logical states.

The Physical State and the Controller’s Estimate

The diagram shows one update of the physical conditional state in the upper row and the controller’s estimate in the lower row, using the same measurement record and feedback Hamiltonian:

Incorrectly Assumed Detector Efficiency

Plot the physical state’s fidelity with logical zero and the estimate’s overlap with that same state, each averaged over forty realizations. The bands show the standard error of each mean:
The physical state and the estimate use the same measurement record in each realization. To compare them directly, subtract the estimate’s overlap with logical zero from the physical state’s fidelity with logical zero at each time within each realization. Plot the mean of these differences across the forty realizations, with a band showing its standard error:
A positive mean gap indicates that the controller underestimates the physical state’s fidelity with logical zero on average; a negative gap indicates overestimation. This comparison measures the discrepancy between estimated and physical fidelity. Whether assuming the wrong detector efficiency also reduces protection requires a separate comparison.
Plot the mean fidelity difference across the forty paired realizations, with a band showing the standard error of that mean:
A positive mean difference indicates higher physical fidelity with logical zero when the controller uses the actual detector efficiency. Both simulations have the same actual detector efficiencies, so this comparison isolates how the controller’s assumed efficiency affects protection for the chosen initial state and parameters.

Residual Fidelity Loss

And read its population off the averaged run:
Plot the population in the code subspace together with the population in logical one:

Detector Efficiency: Why the Feedback Rule Matters

Less Information for the Syndrome Estimate

Markovian Feedback

Comparing Population in the Code Subspace

Conclusions

Continuous stabilizer measurement provides information for estimating the syndrome, while corrective drives act on the physical qubits. For the logical zero example and parameters studied here, feedback improves mean fidelity but leaves residual loss. Some of that loss appears as population in logical one, which has the same stabilizer values as logical zero. Retaining population in the code subspace therefore does not, by itself, establish preservation of the initial logical state.
The physical state and the controller’s estimate also have distinct roles. The qubits can retain high mean fidelity with logical zero even when the estimate begins with equal weight in logical zero and logical one. An incorrectly assumed detector efficiency can instead change how the controller interprets the records and sets the corrective drives. Our comparisons distinguish a discrepancy in estimated fidelity from a change in the protection of the physical qubits.
At unit detector efficiency, the chosen Markovian scheme preserves every encoded state exactly within the idealized model. This stronger protection relies on direct monitoring of the bit flip error channels and feedback operators built from the code projector. Below unit efficiency, an additional dissipative term removes that exact protection. The comparison shows why detector efficiency must be considered together with the particular measurements and controls used for correction.

References

1
.
C. Ahn, A. C. Doherty, and A. J. Landahl, "Continuous quantum error correction via quantum feedback control," Phys. Rev. A 65, 042301 (2002), arXiv:quant-ph/0110111.
2
.
C. Ahn, H. M. Wiseman, and G. J. Milburn, "Quantum error correction for continuously detected errors," Phys. Rev. A 67, 052310 (2003), arXiv:quant-ph/0302006.
3
.
H. M. Wiseman, S. Mancini, and J. Wang, "Bayesian feedback versus Markovian feedback in a two-level atom," Phys. Rev. A 66, 013807 (2002), arXiv:quant-ph/0201145.
4
.
M. Sarovar, C. Ahn, K. Jacobs, and G. J. Milburn, "A practical scheme for error control using feedback," Phys. Rev. A 69, 052324 (2004), arXiv:quant-ph/0402017.
5
.
R. van Handel and H. Mabuchi, "Optimal error tracking via quantum coding and continuous syndrome measurement," arXiv:quant-ph/0511221 (2005).
6
.
R. Mohseninia, J. Yang, I. Siddiqi, A. N. Jordan, and J. Dressel, Quantum 4, 358 (2020), arXiv:1907.08882.
7
.
W. P. Livingston, M. S. Blok, E. Flurin, J. Dressel, A. N. Jordan, and I. Siddiqi, "Experimental demonstration of continuous quantum error correction," Nat. Commun. 13, 2307 (2022), arXiv:2107.11398.
8
.
P. Rouchon and J. F. Ralph, "Efficient quantum filtering for quantum feedback control," Phys. Rev. A 91, 012118 (2015), arXiv:1410.5345.
9
.
H. M. Wiseman and G. J. Milburn, "Quantum theory of optical feedback via homodyne detection," Phys. Rev. Lett. 70, 548 (1993).
10
.
W. M. Wonham, "Some applications of stochastic differential equations to optimal nonlinear filtering," J. SIAM Control 2, 347 (1965).