# Deep Reinforcement Learning for Online Control of Stochastic Partial
Differential Equations

Erfan Pirmorad1, Faraz Khoshbakhtian1, Farnam Mansouri2,3, Amir-massoud
Farahmand3, 2, 1
1Department of Mechanical & Industrial Engineering, University of Toronto
2Department of Computer Science, University of Toronto
3Vector Institute
{erfan.pirmorad, faraz.khoshbakhtian<EMAIL_ADDRESS>
<EMAIL_ADDRESS>First three authors have equal contribution

###### Abstract

In many areas, such as the physical sciences, life sciences, and finance,
control approaches are used to achieve a desired goal in complex dynamical
systems governed by differential equations. In this work we formulate the
problem of controlling stochastic partial differential equations (SPDE) as a
reinforcement learning problem. We present a learning-based, distributed
control approach for online control of a system of SPDEs with high dimensional
state-action space using deep deterministic policy gradient method. We tested
the performance of our method on the problem of controlling the stochastic
Burgers’ equation, describing a turbulent fluid flow in an infinitely large
domain.

##  1 Introduction

Partial differential equations (PDE) are commonly used to explain complex
dynamical systems such as fluid dynamics, electromagnetism, etc. While PDEs
successfully describe a wide range of dynamical systems, random perturbations
require further modelling in the governing equations of some dynamical
systems, e.g., turbulent flows. Stochastic partial differential equations
(SPDEs) are used to model the inherent stochasticities in dynamical systems
(Walsh (1986)). Drawing by recent advances in design and control of the
dynamical systems in engineering applications, PDE control has attracted a lot
of attention (Krstić (2008); Ahuja et al. (2011); Brunton and Noack (2015);
Burns and Hu (2013)); whereas control of SPDEs remains scarce. PDE control
methods are incorporated successfully in many engineering applications;
however, the majority of them require far too much knowledge of the system,
including a complete model of the PDE and the design of a customized
controller, both of which are computationally expensive and not robust to
environmental changes.

Reinforcement learning (RL) was recently used for PDE control with the
application of heating, ventilating, air conditioning (HVAC) control design in
a room as an example(Farahmand et al. (2016, 2017); Pan et al. (2018)). In
these works, the heat transfer equation with a pre-determined flow field
velocity was formulated as an MDP, and RL algorithms used to control the state
of the ventilator. Unlike PDE control, there have been few studies on
controlling SPDEs. Due to the nonlinearity and randomness of the system, such
a problem is extremely challenging for traditional control methods to address
(Rosseel and Wells (2012); Øksendal (2005)). In this work, we present an RL
framework for online control of stochastic dynamical systems. Inspired by the
promising performance of recent RL algorithms in PDE control, we formulate the
problem of controlling a SPDE as an MDP with an infinite dimensional state-
action space, and use Deep Deterministic Policy Gradient (DDPG) (Lillicrap et
al. (2016)) to train our agent. We evaluate our framework to control the
stochastic Burgers’ equation, by damping the shock wave induced by inherent
perturbations.

##  2 Methodology

We consider a (controlled) stochastic dynamical system governed by

$\frac{\partial\mathbf{u}(\mathbf{x},t)}{\partial
t}=\mathcal{F}\left(\mathbf{x},\mathbf{u},\frac{\partial\mathbf{u}}{\partial\mathbf{x}},\left(\frac{\partial^{2}\mathbf{u}}{\partial
x_{i}\partial
x_{j}}\right)_{i,j=1:n},\dotsi;\mathbf{p}\right)+\xi\left(\mathbf{x},t\right)+\mathbf{f}\left(\mathbf{x},t\right),$
(1)

where $\mathbf{u}\left(\mathbf{x},t\right)$ denotes the state variable of the
dynamical system which depends on spatial free variables
$\mathbf{x}=(x_{1},\dotsi,x_{n})$, within an $n$-dimensional domain $\Omega$,
$x_{1:n}\in\Omega\subset\mathcal{R}^{n}$, and time $t\in\mathcal{R}^{+}$, and
its derivatives with respect to the free variables. $\mathcal{F(.)}$ is a
nonlinear general function of the derivatives parameterized by $\mathbf{p}$.
In the above equation $\xi\left(\mathbf{x},t\right)$ is a multidimensional
noise that is white in time and correlated in space, and
$\mathbf{f}(\mathbf{x},t)$ is a control input forcing function, which will be
further discussed later.

The above SPDE is solved, either numerically or analytically, on domain
$\Omega$ bounded to the boundary $\partial\Omega=\Gamma$, with boundary
condition $u_{\Gamma}$. An example of the control problem here can be defined
as setting the state variable to a desirable value
$\mathbf{u}=\mathbf{u}^{*}$, within an arbitrary controlled sub-domain of
$\Omega_{c}$ bounded to the boundary $\partial\Omega_{c}=\Gamma_{c}$, at all
time $t$. A realistic example of this sort of control problem is an HVAC unit
system where we attempt to set the temperature to a comfortable value, in a
specific part of a building, in the presence of an air flow. The desired
control problem can be formally defined as the following optimal control
problem:

$\displaystyle\inf_{\mathbf{f}}\;J(\mathbf{u},\mathbf{u}^{*})\overset{\Delta}{=}\frac{1}{2}\int\int_{\Omega_{c}}\left(\mathbf{u}(\mathbf{x},t)-\mathbf{u}^{*}(\mathbf{x},t)\right)^{2}\mathrm{d}\Omega\;\mathrm{d}t$
(2) $\displaystyle\text{ s.t.
}\;\frac{\partial\mathbf{u}(\mathbf{x},t)}{\partial
t}=\mathcal{F}\left(\mathbf{x},\mathbf{u},\frac{\partial\mathbf{u}}{\partial\mathbf{x}},\left(\frac{\partial^{2}\mathbf{u}}{\partial
x_{i}\partial
x_{j}}\right)_{i,j=1:n},\dotsi;\mathbf{p}\right)+\xi\left(\mathbf{x},t\right)+\mathbf{f}\left(\mathbf{x},t\right).$

To solve this (optimal) control problem, we propose using an RL approach. To
this end, the continuous space-time SPDE is discretized in both space and time
by a numerical solver, and the discretized SPDE is formulated as a discrete
space-time, continuous state-action space, discounted MDP
$(\mathcal{S},\mathcal{A},\mathcal{P},\mathcal{R},\gamma)$ (Sutton and Barto
(2018); Szepesvári (2010)), where state space $\mathcal{S}$ and action space
$\mathcal{A}$ are vector functions depending on the function space of SPDE
$\mathcal{F}(\mathcal{Z})$, defined over the domain $\mathcal{Z}$ of SPDE. The
current value of the target variable, within $\Omega_{c}$ at each discrete
time $t$, is the current state $s_{t}=\mathbf{u}(\mathbf{x},t)$. Assuming that
the system is equipped with a number of actuators, a localized control input
function is the continuous action $a_{t}=\mathbf{f}(\mathbf{x},t)$, within the
controlled domain $\Omega_{c}$. A scalar reward function is defined to
penalize the RL agent when the target variable deviates from the desired
value, given by:

$r_{t}=-\left[\frac{1}{2}\int_{\Omega_{c}}\left(\mathbf{u}(\mathbf{x},t)-\mathbf{u}^{*}(\mathbf{x},t)\right)^{2}\mathrm{d}\Omega+\frac{1}{2}\lambda\left\|\mathbf{f}(\mathbf{x},t)\right\|^{2}\right],$
(3)

which is negative of the cost function, regularized by the cost of choosing an
action (which is small or zero for cheap controls and large for expensive
controls). A new state given the chosen action and the previous state is
sampled as $s_{t+1}\sim\mathcal{P}(\cdot\mid s_{t},a_{t})$, where the
transition probability kernel $\mathcal{P}$ depends on the SPDE.

Figure 1: Schematic of the RL control agent interacting with an environment
that is a 2D domain $\Omega$ governed by an SPDE, and the control sub-domain
$\Omega_{c}$, where a desired condition is enforced.

##  3 Experiments

The potential benefits of SPDE control is known to be significant in
controlling turbulent flows that occur in various engineering applications
(Naseri and Malek (2014)). Attempts to control turbulent flows in engineering
applications have focused on the manipulation of coherent structures, such as
a shock wave. A shock wave is a region within the fluid flow where physical
conditions undergo an abrupt change because of high flow variable gradients,
and this damages structures as it propagates. 1D Stochastic Burgers’ equation
(SBE) is a simple model that best describes this phenomenon:

$\frac{\partial u}{\partial t}+\frac{\partial}{\partial
x}\frac{u^{2}}{2}=\nu\frac{\partial^{2}u}{\partial
x^{2}}+\epsilon\eta_{t}(x),\quad\eta_{t}=\frac{\partial\dot{W}}{\partial
x},\quad W\sim\mathcal{N}\left(0,\sigma^{2}\right),$ (4)

where $\eta_{t}(x)$ is a space-time white noise with the intensity of
$\epsilon$, and it is realized as the generalized derivative of the Brownian
sheet, i.e. ${\eta}_{t}(x)=\partial_{t}\partial_{x}{W}_{t}(x)$, where
$W_{t}(x)$ is a Gaussian process. Due to the presence of nonlinear convective
terms, solution of the 1D Burgers’ equation is prone to exhibit a chaotic
behaviour. Here, we test our proposed RL framework to control the fluid flow
governed by the SBE to damp the developed shock wave and stabilize the system
in an online manner, and compare it against previous non-RL approaches (Choi
et al. (1993); Munteanu (2019)). A distributed control method is used by
introducing an external forcing term, $f(x,t)$, as a control input of the
system. The control problem here is formalized to find the proper $f(x,t)$
applied to the fluid flow in the solution domain to squash the shock wave at
each time. Squashing in our terminology means
$\inf_{f}\mathbb{E}[\int_{\Omega_{c}}\left(u(x,t)-\bar{u}\right)^{2}\mathrm{d}x]$
in each time step, where
$\bar{u}=\mathbb{E}[\frac{1}{2\pi}\int_{\Omega_{c}}u(x,t)\mathrm{d}x]$. The
described control problem above can be expressed as the following inverse
problem:

$\displaystyle\inf_{f}\;J(u,f)\overset{\Delta}{=}\int\left[\frac{1}{2}\int_{\Omega_{c}}\left(u(x,t)-\bar{u}\right)^{2}\mathrm{d}x+\frac{1}{2}\lambda\left\|f\right\|^{2}\right]\;\mathrm{d}t\quad\text{
on }\Omega_{c}$ (5) $\displaystyle\text{ s.t. }\;\begin{cases}&\frac{\partial
u}{\partial t}+\frac{\partial}{\partial
x}\frac{u^{2}}{2}=\nu\frac{\partial^{2}u}{\partial
x^{2}}+\epsilon\eta_{t}(x)+f(x,t),\quad 0<x<2\pi\\\ &u(x,t=0)=u_{0}(x)\\\
&u(x=0,t)=u(x=2\pi,t),\quad\text{Periodic Boundary condition}\end{cases}$

###  3.1 Training Procedure

#### SPDE solver:

A uniform computational grid of $n_{x}=151$ points is used for spatial
discretization. A Crank-Nicolson method (Crank et al. (1947)) in time and
second-order centred differences in space are used to discretize the equation,
an explicit iterative method is used to solve the discretized nonlinear
equation. Instantaneous velocity field for evolution of a shock wave is shown
in Figure 2. It is observed that the shock wave energy dissipates over time by
the structural diffusivity of system.

Figure 2: Instantaneous velocity field for evolution of a shock wave in space
and time in four different times.

#### RL:

Given the continuous state-action nature of the SPDE, we use a deep
deterministic policy gradient (DDPG) approach to train the RL agent. We
implemented an actor/critic DDPG framework according to Lillicrap et al.
(2016). The DDPG states and actions are $u(.;t)$ and $f(.;t)$, respectively.
To facilitate this algorithm implementation in the real world, the action
space is limited to a set of 4-interval piecewise constant functions. Similar
fully connected 2-layer networks are used as the actor and critic networks
architecture, that consist of hidden layers of ReLU units, and a linear output
layer. Network parameters are initialized using Xavier initialization (Glorot
and Bengio (2010)), and Adam optimizer(Kingma and Ba (2015)) is used for
optimization. An experience replay with the buffer size of $1000000$ is used.
Details on the hyperparameters used for training is provided in Appendix A.

###  3.2 Results

Here we show some preliminary results on controlling the SBE, and compare them
against benchmarks. Figure 3(a) and Figure 3(b) show the free evolution of the
shock wave (black line), evolution under online control of the RL agent (red
dotted-line), and the input control function at $t=0.8$ and averaged over
$N=20$ runs with $90\%$ confidence interval, respectively. It can be seen that
the control input function damps the shock wave and reduces the gradients
throughout the domain. We compare the average return for $N_{eps}=100$
episodes obtained by the RL against uncontrolled system, and the suboptimal
control approach used by Choi et al. (1993), given the same form of piecewise
constant functions as the action space in Figure 3(c). Finally, the average
return for three gradually more expressive action functions are compared in
Figure 3(d).

Figure 3: (a) Velocity fields $u(.;t=0.8)$ (state) for uncontrolled (black)
and controlled (red) evolution of the shock wave described by the SBE. (b)
Calculated control input $f(.;t=0.8)$. Average return for (c) the RL agent
(blue), the controller of Choi et al. (1993) (red), and the uncontrolled
environment (black); and (d) different form of action functions with 4, 7, and
10 dimensional actions space.

##  4 Conclusion

In this work, we presented a learning-based approach, based on reinforcement
learning, to control behaviour of a SPDE that describes a noisy dynamical
system. Preliminary results for online control of the 1D SBE showed promising
results in damping the shock wave and reducing sharp gradients. Although
boundary control approaches are more practical in fluid mechanics, we adopted
a distributed control approach for the case of 1D SBE because it is defined in
an infinitely large domain, represented by periodic boundary conditions on a
$2\pi$ length cell. Our proposed RL control approach is easily extendable to a
boundary control strategy to control bounded systems. We will extend this work
to more realistic higher dimensional SPDEs in our future work.

##  5 Acknowledgment

AMF acknowledges the funding from the Canada CIFAR AI Chairs program.

## References

  * Ahuja et al. [2011] S. Ahuja, A. Surana, and E. Cliff.  Reduced-order models for control of stratified flows in buildings.  _Proceedings of the 2011 American Control Conference_ , pages 2083–2088, 2011.
  * Brunton and Noack [2015] S. Brunton and B. R. Noack.  Closed-loop turbulence control: Progress and challenges.  _Applied Mechanics Reviews_ , 67:050801, 2015.
  * Burns and Hu [2013] J. Burns and Weiwei Hu.  Approximation methods for boundary control of the boussinesq equations.  _52nd IEEE Conference on Decision and Control_ , pages 454–459, 2013\.
  * Choi et al. [1993] H. Choi, R. Temam, P. Moin, and John Kim.  Feedback control for unsteady flow and its application to the stochastic Burgers equation.  _Journal of Fluid Mechanics_ , 253:509–543, 1993.
  * Crank et al. [1947] J. Crank, P. Nicolson, and D. Hartree.  A practical method for numerical evaluation of solutions of partial differential equations of the heat-conduction type.  1947\.
  * Farahmand et al. [2016] A. Farahmand, S. Nabi, P. Grover, and D. Nikovski.  Learning to control partial differential equations: Regularized fitted q-iteration approach.  _2016 IEEE 55th Conference on Decision and Control (CDC)_ , pages 4578–4585, 2016.
  * Farahmand et al. [2017] A. Farahmand, S. Nabi, and D. Nikovski.  Deep reinforcement learning for partial differential equation control.  _2017 American Control Conference (ACC)_ , pages 3120–3127, 2017\.
  * Glorot and Bengio [2010] X. Glorot and Y. Bengio.  Understanding the difficulty of training deep feedforward neural networks.  In _AISTATS_ , 2010.
  * Kingma and Ba [2015] D. P. Kingma and J. Ba.  Adam: A method for stochastic optimization.  In _3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings_ , 2015.
  * Krstić [2008] M. Krstić.  Boundary control of PDEs: A course on backstepping designs.  2008\.
  * Lillicrap et al. [2016] T. Lillicrap, Jonathan J. Hunt, A. Pritzel, N. Heess, T. Erez, Yuval Tassa, D. Silver, and Daan Wierstra.  Continuous control with deep reinforcement learning.  In _ICLR_ , 2016.
  * Munteanu [2019] Ionuţ Munteanu.  Exponential stabilization of the stochastic Burgers equation by boundary proportional feedback.  _Discrete & Continuous Dynamical Systems_, 39(4):2173–2185, 2019.
  * Naseri and Malek [2014] R. Naseri and A. Malek.  Numerical optimal control for problems with random forced SPDE constraints.  _ISRN Applied Mathematics_ , 2014:974305, Feb 2014.
  * Øksendal [2005] B. Øksendal.  Optimal control of stochastic partial differential equations.  _Stochastic Analysis and Applications_ , 23:165 – 179, 2005\.
  * Pan et al. [2018] Y. Pan, A. Farahmand, M. White, S. Nabi, P. Grover, and D. Nikovski.  Reinforcement learning with function-valued action spaces for partial differential equation control.  In _ICML_ , 2018.
  * Rosseel and Wells [2012] E. Rosseel and G. N. Wells.  Optimal control with stochastic PDE constraints and uncertain controls.  _Computer Methods in Applied Mechanics and Engineering_ , 213-216:152–167, 2012.  ISSN 0045-7825.
  * Sutton and Barto [2018] R. S. Sutton and A. G. Barto.  _Reinforcement Learning: An Introduction_.  A Bradford Book, Cambridge, MA, USA, 2018.  ISBN 0262039249.
  * Szepesvári [2010] C. Szepesvári.  _Algorithms for Reinforcement Learning_.  Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan & Claypool Publishers, 2010.
  * Walsh [1986] J. B. Walsh.  An introduction to stochastic partial differential equations.  In P. L. Hennequin, editor, _École d’Été de Probabilités de Saint Flour XIV - 1984_ , pages 265–439, Berlin, Heidelberg, 1986. Springer Berlin Heidelberg.  ISBN 978-3-540-39781-6.

##  Appendix A Hyperparameters

Table 1: Parameter values for 1D SBE equation training Parameter | Value | Description
---|---|---
$t_{start}$ | 0 | Initial time
$t_{end}$ | 2 | Finishing time
$\delta_{t}$ | 2 | Episode length
$n_{x}$ | 151 | Number of spatial grids
$x$ | [0, $2\pi$] | Lower and upper bounds of $x$
$u$ | [-8, 8] | Lower and upper bounds of $u$
$f$ | [-10,10] | Lower and upper bounds of $f$
$\nu$ | 0.01, 1, 10 | Diffusion coefficient
$\epsilon$ | 0.01 | Magnitude of the Gaussian noise
$\lambda$ | 0.2 | Regularizer weight
$\alpha$ | 2.5e-5 | Actor network learning rate
$\beta$ | 2.5e-4 | Critic network learning rate
$layer1-size$ | 400 | First layer dimension for both Actor/Critic
$layer2-size$ | 300 | Second layer dimension for both Actor/Critic
$\tau$ | 0.1 | Target network update parameter


# Spin-augmented observables for efficient photonic quantum error correction

Elena Callus<EMAIL_ADDRESS>Pieter Kok<EMAIL_ADDRESS>Department of Physics and Astronomy, The University of Sheffield, Sheffield,
S3 7RH, UK

###### Abstract

We demonstrate that the spin state of solid-state emitters inside micropillar
cavities can serve as measure qubits in syndrome measurements. The photons,
acting as data qubits, interact with the spin state in the microcavity and the
total state of the system evolves conditionally due to the resulting circular
birefringence. By performing a quantum non-demolition measurement on the spin
state, the syndrome of the optical state can be obtained. Furthermore, due to
the symmetry of the interaction, we can alternatively choose to employ the
optical states as measure qubits. This protocol can be adapted to various
resource requirements, including spectral discrepancies between the data
qubits and codes with modified connectivities, by considering entangled
measure qubits. Finally, we show that spin-systems with dissimilar
characteristic energies can still be entangled with high levels of fidelity
and tolerance to cavity losses in the strong coupling regime.

Linear optical quantum computing with single photons becomes resource-
inefficient and requires a high overhead due to weak photon–photon
interactions, making multi-qubit gates difficult to implement Kok  _et al._
(2007). However, this drawback can be overcome at the measurement stage if one
can resolve amongst a broader class of observables, e.g., performing
measurements of two-photon qubits such as Bell states Knill  _et al._ (2001).
This would thereby allow for the execution of non-linear gates more
efficiently. Although quantum dot (QD) spin systems tend to be too short-lived
for useable long-term memories, they interact efficiently with light. The
spin–photon interaction augments photonic quantum information processing, with
important applications in photonic state measurements. This complements linear
optical quantum computing and can dramatically increase its efficiency. Here
we propose an application of this interaction to the measurement of a larger
class of qubit observables.

Figure 1: Schematic of the stabilizer measurement setup, with (a) a single QD
and (b) multiple entangled QDs. The optical states, $\ket{\psi}$, interact
with the spin state(s) either (a) successively or (b) in parallel. A spin
measurement, M, in the $\hat{X}$ basis is performed as a final step. Hadamard
gates, HX, pre- and post-interaction are applied only in the case of a star
measurement, $\mathsf{X}_{s}$. Figure 2: A schematic of the two-dimensional
array of data (open circles) and measure (black circles) qubits of a surface
code. The plaquette, $\mathsf{Z}_{p}$, and star, $\mathsf{X}_{s}$, measurement
operators are shown in green (dotted outline) and pink (solid outline),
respectively.

The spin–photon interface is a promising candidate for applications in quantum
information technologies and quantum communication Kimble (2008); Atatüre  _et
al._ (2018). The low decoherence rate of the photon renders it suitable as a
flying qubit, transporting information over large distances and interacting
readily with the solid-state spin, which acts as a stationary qubit. Over the
last few years, various systems belonging to this family have been extensively
studied with the aim of applications in various quantum technologies, yielding
the development of, e.g., photonic quantum gates Hacker  _et al._ (2016); Duan
and Kimble (2004) and optical non-linearities Javadi  _et al._ (2018, 2015),
as well as entanglement of remote spin states Delteil  _et al._ (2015); Young
_et al._ (2013); Cirac  _et al._ (1997), photon polarisation Hu  _et al._
(2008a) and spin–photon states Economou and Dev (2016). The circular
birefringence arising from the optical selection rules for a spin state
confined in a cavity Young  _et al._ (2011) has been used to develop schemes
for, e.g., quantum teleportation Hu and Rarity (2011), quantum non-demolition
measurements Hu  _et al._ (2009a) and entanglement beam splitters Hu  _et al._
(2009b). Furthermore, this system also has applications in the design of
complete and deterministic Bell-state analyzers Bonato  _et al._ (2010); Hu
and Rarity (2011), a marked improvement over what is possible using just
linear optics Calsamiglia and Lütkenhaus (2001). Here, the spin–photon system
measures the qubit parity whilst information about the symmetry is obtained
using linear optics.

In this work, we will discuss the application of spin–photon interfaces to
carry out efficient photonic stabilizer measurements in the surface code. A
key objective in quantum physics is the physical realisation of fault-tolerant
quantum computers, necessitating the development of quantum error detection
and correction Shor (1995). Surface codes are a well-studied set of stabilizer
codes designed for the implementation of error-corrected quantum computing
Roffe (2019). The first proposal was presented by Kitaev in the form of the
toric code Kitaev (2003, 1997), assuming periodic boundary conditions that
allow it to be mapped onto a torus. This was later generalised to planar
versions with different variations in the boundary conditions Bravyi and
Kitaev (1998); Freedman and Meyer (1998); Fowler  _et al._ (2012). The surface
code considers a 2D square lattice arrangement of data and measure qubits,
with the latter being used to detect errors and perform stabilizer
measurements of the encoded data qubits.

Stabilizer measurement is one type of error detection technique, indicating
the presence of possible noisy errors in the physical data qubits Nielsen and
Chuang (2012); Gottesman (1997). It consists of a series of projective
measurements performed on specific sets of qubits, with the measurement
outcomes, or syndromes, indicating the location and type of error. Given that
a direct measurement of the physical data qubits interferes with the coherence
of the state and destroys the encoded information, the measurements are
performed on entangled measure qubits. There exist several approaches when it
comes to the physical implementation of quantum error correction, with
platforms including photonic architectures Bell  _et al._ (2014); Yao  _et
al._ (2012); Aoki  _et al._ (2009), superconducting circuits Andersen  _et
al._ (2020); Ristè  _et al._ (2015); Kelly  _et al._ (2015), trapped atomic
ions Linke  _et al._ (2017); Lanyon  _et al._ (2013) and nitrogen-vacancy
centres Cramer  _et al._ (2016) having been experimentally explored.

Using solid-state QDs trapped inside micropillar cavities and scattering
interactions at the single-photon level, the total state of the optical and
spin sub-systems evolves conditionally, with entanglement occuring in the
presence of coherent errors. This allows us to perform a quantum non-
demolition measurement of one of the two subsystems, effectively retrieving
information about the state of the other. Letting the optical and spin states
serve as data and measure qubits, we show this interaction and measurement
process can be used to extract the syndrome, as shown schematically in Fig. 1.
The scheme also has the advantage that the assignment of the data and measure
qubits can be swapped around. Moreover, we will discuss the use of multiple
entangled measure qubits as a means of reducing resource requirements,
accommodating for possible spectral variations between the data qubits and
codes that consider various connectivities between the qubits.

The detection of errors in the data qubits is performed by means of syndrome
measurements. The measurement operators, or stabilizers, for a surface code
are comprised of star, $\mathsf{X}_{s}=\prod_{j\in\text{star}(s)}\hat{X}_{j}$,
and plaquette operators,
$\mathsf{Z}_{p}=\prod_{j\in\text{plaq}(p)}\hat{Z}_{j}$, where $\hat{X}$ and
$\hat{Z}$ are the Pauli-X and Pauli-Z operators. The operators act on either
the four data qubits that are adjacent to a vertex, said to belong to a star
$s$, or adjacent to a face, said to belong to a plaquette $p$, as shown in
Fig. 2. Furthermore, the operators all commute, with
$[\mathsf{X}_{s},\mathsf{X}_{s^{\prime}}]=[\mathsf{Z}_{p},\mathsf{Z}_{p^{\prime}}]=[\mathsf{X}_{s},\mathsf{Z}_{p}]=0$.
The eigenstates of $\hat{Z}$ are $\ket{0}$ and $\ket{1}$, and those of
$\hat{X}$ are $\ket{\pm}\propto\left(\ket{0}\pm\ket{1}\right)$. The graph of
the surface code is stabilized by $\mathsf{X}_{s}$ and $\mathsf{Z}_{p}$. The
eigenvalues obtained from the measurement of these operators indicates the
possible presence of errors, and depends on the parity of the state, with an
eigenvalue of $+1$ ($-1$) corresponding to a state with even (odd) parity. The
state of the data qubits may be initialised such that they are simultaneous
eigenstates of all the stabilizer operators with eigenvalues of $\pm 1$,
referred to as the quiescent state. The standard method of extracting the
qubit syndrome involves the implementation of a CNOT gate on each of the data
qubits belonging to a star or plaquette, with the measure qubit serving as the
control.

Figure 3: (a) A micropillar cavity, with resonance frequency $\omega_{c}$,
coupled to a QD with strength $g$. The field in the cavity couples to the
output mode and lossy modes with rates $\kappa$ and $\kappa_{s}$,
respectively. (b) The polarisation- and spin-dependent coupling rules for the
QD with central frequency $\omega_{X^{-}}$ and decay rate $\gamma$.

The physical spin setup, demonstrated in Fig. 3, consists of a single-sided
micropillar with two distributed Bragg reflectors on both ends, where only one
side is fully reflective and the other end is partially transmissive. The
cavity mode couples to an electron spin in the form of a charged QD contained
within the micropillar cavity. Given the optical selection rules, the
interaction of a photon within the cavity becomes polarisation and spin
dependent Warburton (2013). In the case of a negatively charged QD, the
$\ket{\uparrow}$ ($\ket{\downarrow}$) spin state can be optically excited to
the negative trion, $X^{-}$, state $\ket{\uparrow\downarrow,\Uparrow}$
($\ket{\uparrow\downarrow,\Downarrow}$) by absorption of a left-handed (right-
handed) circularly polarised photon, $\ket{L}$ ($\ket{R}$). Cross-transitions
between the lower and higher energy states are not allowed by the conservation
of angular momentum.

The post-interaction reflection coefficient for a single-sided cavity coupled
to a QD is given by Hu  _et al._ (2008b)

$r_{h}(\omega)=\frac{\left[\mathrm{i}\mkern
1.0mu\left(\omega_{X^{-}}-\omega\right)+\frac{\gamma}{2}\right]\left[\mathrm{i}\mkern
1.0mu\left(\omega_{c}-\omega\right)+\frac{\kappa_{s}}{2}-\frac{\kappa}{2}\right]+g^{2}}{\left[\mathrm{i}\mkern
1.0mu\left(\omega_{X^{-}}-\omega\right)+\frac{\gamma}{2}\right]\left[\mathrm{i}\mkern
1.0mu\left(\omega_{c}-\omega\right)+\frac{\kappa_{s}}{2}+\frac{\kappa}{2}\right]+g^{2}},$
(1)

where $\omega$, $\omega_{c}$ and $\omega_{X^{-}}$ represent the frequencies of
the photon, the cavity mode and the trion transition, respectively; $\gamma$
represents the decay rate of the $X^{-}$ dipole, $\kappa$ and $\kappa_{s}$ are
the cavity decay rates into the output and the lossy side modes, respectively,
and $g$ is the coupling strength between the QD and the cavity field. When the
photon does not couple to the QD due to the selection rules, the only
contribution to the reflection coefficient is from the (empty) cavity
interaction. Setting $g=0$, we can characterise the cold cavity interaction by

$r_{0}(\omega)=\frac{\mathrm{i}\mkern
1.0mu\left(\omega_{c}-\omega\right)+\frac{\kappa_{s}}{2}-\frac{\kappa}{2}}{\mathrm{i}\mkern
1.0mu\left(\omega_{c}-\omega\right)+\frac{\kappa_{s}}{2}+\frac{\kappa}{2}}.$
(2)

We will consider only the resonant interaction case in this work, where
$\omega_{c}=\omega_{X^{-}}$, and allow detuning of the photon frequency,
$\omega$, where $\delta=\omega_{c}-\omega=\omega_{X^{-}}-\omega$. For small
enough cavity losses $\kappa_{s}$, one sees that $|r_{0}(\omega)|\simeq 1$ for
all frequency detuning, whilst $|r_{h}(\omega)|\simeq 1$ except in the region
of $\delta=\pm g$, when in the strong-coupling regime with
$g>\left(\kappa+\kappa_{s}\right)/4$. We apply a frequency detuning such that
the difference in phase shifts imparted during the coupled and the cold cavity
interactions is $\pm\pi/2$. This means that the $\delta$ is set such that
$\tilde{\phi}(\omega)\equiv\phi_{h}(\omega)-\phi_{0}(\omega)=\pm\pi/2$, where
$\phi_{i}(\omega)=\arg\left[r_{i}(\omega)\right]$ for $i=h,0$. We will drop
the notation for frequency dependence for ease of readability.

Fig. 1 shows a diagrammatic setup for the syndrome measurement, where we first
consider situation (a) with four photons interacting sequentially with a
single spin. The photons serve as data qubits with $\ket{L}$ and $\ket{R}$
encoding the logical $\ket{0}$ and logical $\ket{1}$ qubit states,
respectively, whilst the spin states act as the measure qubits. The Hadamard
gates are applied pre- and post-interaction only when performing a star
measurement, $\mathsf{X}_{s}$, such that the $\hat{X}$-basis eigenstates
transform as $\ket{+}\leftrightarrow\ket{g}$ and
$\ket{-}\leftrightarrow\ket{e}$. The electron spin state is initialised to
$\ket{+_{S}}=\left(\ket{\uparrow}+\ket{\downarrow}\right)/\sqrt{2}$, however
we note that the procedure also works for an initial spin state given by
$\ket{-_{S}}=\left(\ket{\uparrow}-\ket{\downarrow}\right)/\sqrt{2}$. Letting
the four photons belonging to a plaquette or star set interact with the spin
system sequentially in time, and assuming
$|r_{0}\left(\omega\right)|=|r_{h}\left(\omega\right)|=1$, a photonic
eigenstate and the electron spin state evolve together, up to a global phase,
as

$\begin{split}\bigotimes_{\begin{subarray}{c}j\in\text{star}(s)\\\ \text{or
}\text{plaq}(p)\end{subarray}}&\ket{i_{j}}\otimes\ket{+_{S}}\rightarrow\bigotimes_{\begin{subarray}{c}j\in\text{star}(s)\\\
\text{or }\text{plaq}(p)\end{subarray}}\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\delta_{i_{j}L}\right)\ket{i_{j}}\\\
&\otimes\left[\ket{\uparrow}+\prod_{\begin{subarray}{c}k\in\text{star}(s)\\\
\text{or }\text{plaq}(p)\end{subarray}}\exp\left[-\mathrm{i}\mkern
1.0mu\left(\phi_{k,\uparrow}-\phi_{k,\downarrow}\right)\right]\ket{\downarrow}\right]/\sqrt{2},\\\
\end{split}$ (3)

where $\ket{i_{j}}\in\\{\ket{L},\ket{R}\\}$, $j$ and $k$ index the same four
photonic qubits in a plaquette or star set, $\delta_{i_{j}L}$ is the Kronecker
delta, and $\phi_{j,\ast}$ is the phase shift resulting from the interaction
between the photonic state $\ket{i}_{j}$ and spin state
$\ket{\ast}\in\left\\{\ket{\uparrow},\ket{\downarrow}\right\\}$. The frequency
detuning, $\delta$, is set such that $\tilde{\phi}=\pm\pi/2$, resulting in
$\left(\phi_{k,\uparrow}-\phi_{k,\downarrow}\right)=\pm\pi/2$ ($\mp\pi/2$) for
a left-handed (right-handed) circularly polarised photon. The relative phase
shift between the two spin states accumulates with every spin–photon
interaction. The total phase shift imparted from two orthogonally polarised
photons is zero, whilst that resulting from pairs of identically polarised
photons is $\pm\pi$. Given the set of all eigenstates, the spin state evolves
to $\ket{+_{S}}$ ($\ket{-_{S}}$) for an even (odd) parity photonic state. By
measuring the spin in the $\hat{X}$-basis, we can therefore perform a quantum
non-demolition measurement that reveals the syndrome of the data qubits in a
complete and efficient manner. The phase shift acquired by the individual
photonic eigenstates post-measurement is shown in Eq. 3 and has two
contributions. The key contribution to the imparted phase shift is
$\exp\left(\mathrm{i}\mkern 1.0mu\tilde{\phi}\delta_{i_{j}L}\right)$, which
introduces unwanted phase flips to the encoded state. This is corrected by a
polarisation-dependent phase shift acting only on the right-circularly
polarised state such that $\ket{R}\rightarrow\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\right)\ket{R}$, possible to achieve in a passive manner
using linear optics. This rotation corrects the state, irrespective of the
physical state, preserving the original pre-measurement encoded state,
including any detected errors. The procedure is similar when we account for
the presence of various boundary conditions in the surface code (see SM).

Next, we consider the confidence in the spin read-out Kok and Braunstein
(2001) as an appropriate figure of merit for the measurement performance given
possible variations in the frequency detuning, $\delta$, from the optimal. The
ground state of the planar code is given by Nielsen and Chuang (2012)

$\ket{\psi_{0}}\propto\prod_{s}\left(\mathds{1}+\mathsf{X}_{s}\right)\ket{0}^{\otimes
n},$ (4)

where $n$ is the number of physical data qubits and the product is over the
whole set of stars $s$. The state is assumed to be prone to coherent errors
that can be modelled by applying a Pauli channel of the form

$\mathcal{E}\left(\rho\right)=(1-p)\rho+x\hat{X}\rho\hat{X}+y\hat{Y}\rho\hat{Y}+z\hat{Z}\rho\hat{Z}$
(5)

to each individual physical qubit, where $x,y,z$ are the probabilities of the
respective Pauli errors and $p=x+y+z$ is the physical qubit error rate. Since
plaquette (star) operators detect only $X$($Z$)-type errors, we may address
the performance of each measurement type individually. For our confidence
measure, we may simply assume that both star and plaquette measurements also
factor in any possible $Y$-type errors, since $\hat{Y}=\hat{Z}\hat{X}$. We can
then express the confidence in a spin read-out of $\ket{\pm}$ by

$\frac{\text{Tr}\left[\mathbb{P}_{\pm}\otimes\ket{\pm_{S}}\bra{\pm_{S}}\left\\{U\left(\mathcal{E}\left(\rho\right)\otimes\ket{+_{S}}\bra{+_{S}}\right)U^{\dagger}\right\\}\right]}{\text{Tr}\left[\mathds{1}\otimes\ket{\pm_{S}}\bra{\pm_{S}}\left\\{U\left(\mathcal{E}\left(\rho\right)\otimes\ket{+_{S}}\bra{+_{S}}\right)U^{\dagger}\right\\}\right]},$
(6)

where $U$ is the spin- and polarisation-dependent two-qubit gate describing
the interaction and $\mathbb{P}_{\pm}$ is the projection operator onto the
$\pm 1$ eigenstates.

We show in Fig. 4 the confidence in the two types of plaquette and star
measurement outcomes for different coupling strengths $g$ and for various
physical qubit error probabilities as a function of the frequency detuning
$\delta$. We consider here only the strong-coupling regime, as it is in this
case that we satisfy the requirement that $|r_{h}|\rightarrow 1$. Current
experimental values show coupling strengths with $g/\kappa$ reaching values of
up to around 2.4 Volz  _et al._ (2012); Reitzenstein  _et al._ (2007). We note
here that the distance of the code, i.e., the measure of the number of
physical qubits used to encode a logical qubit, does not have an effect on the
confidence value, and that the plaquette and star measurements show the same
type of behaviour due to their equivalence up to a Hadamard gate. We see that
the confidence in the $\ket{-}$ spin state measurement tends to be lower. This
is due to the way the coefficients accumulate in the presence of errors: the
accumulation in such cases builds up in an uneven way, resulting in a more
volatile behaviour as the $\delta$ is varied. Furthermore, we show that the
proposed scheme is robust and tolerant to deviations in the frequency detuning
from the optimal.

Figure 4: Confidence in the $\ket{+_{S}}$ (solid) and $\ket{-_{S}}$ (dashed)
spin read-outs as a function of the frequency detuning
$\delta=\omega_{c}-\omega=\omega_{X^{-}}-\omega$ for varying coupling
strengths, $g$, and physical qubit error probabilities of either $X$\- or
$Z$-type, $p^{*}$. The normalised linewidth, $\gamma/\kappa$, is set to 0.1.

Next, we consider a setup where the syndrome measurement is performed in
parallel on the incoming photons. This may be done in order to optimise for
the type of resources required as well as to accommodate for possible
differences in the spectral characteristic of the data qubits. Due to the
linear nature of our transformation, the total phase shift is equivalent to
the sum of the individual interactions and therefore the syndrome measurement
can be done using two or four measure qubits per stabilizer measurement. The
spins need to be entangled into a general GHZ-state up to any Pauli
operations. Each photon is then allowed to ineract with exactly one of the
spins (or, in the case of a two-qubit register, two photons interacting with
each spin), such that the interaction satisfies the conditions specified for
the single-qubit register. Finally, all the spins are measured in the
$\hat{X}$-basis, as was done in the single-qubit register, in order to extract
the syndrome.

A setup making use of two or four measure qubits would require fewer photon
switches and optical circulators, and would cater for a larger spectral
variation between the photons. On the other hand, this calls for entanglement
generation, which may require additional resources in terms of time and
physical components. One way of entangling the spin states of two QDs is to
allow a linearly polarised photon to interact with each state sequentially
Young  _et al._ (2013); Hu  _et al._ (2008b). This results in a so-called
optical Faraday rotation which rotates the polarisation and, given initial
spin states $\left(\ket{\uparrow}+\ket{\downarrow}\right)/\sqrt{2}$ and
$\tilde{\phi}=\pm\pi/2$, evolves the spin–photon state to $-\mathrm{i}\mkern
1.0mu\ket{V}\left(\ket{\uparrow\uparrow}-\ket{\downarrow\downarrow}\right)\pm\mathrm{i}\mkern
1.0mu\ket{H}\left(\ket{\uparrow\downarrow}+\ket{\downarrow\uparrow}\right)$,
up to normalisation. Therefore, by measuring the polarisation of the photon,
the spin state is projected onto a maximally entangled state. This protocol
can be extended to four spin states by entangling another pair and then
entangling together one spin state from each pair.

In the case of photonic data qubits with different frequencies, we would
require spectrally different QD-spin systems in order to satisfy the condition
of $\tilde{\phi}=\pm\pi/2$. In such cases, the entanglement procedure outlined
above may still be used to generate states with high fidelity, albeit the
heralded efficiency of the procedure is reduced. By setting the frequency of
the linearly polarised photon, say $\ket{H}$, such that
$\tilde{\phi_{1}}=-\tilde{\phi_{2}}$, where $\tilde{\phi_{i}}$ is the
difference in phase shifts for QD-spin system $i$, the state of the total
system post-interaction is

$\begin{split}\ket{H}&\left(\ket{\uparrow\uparrow}+\ket{\downarrow\downarrow}\right)+\left(e^{\mathrm{i}\mkern
1.0mu\tilde{\phi}}\ket{L}+e^{-\mathrm{i}\mkern
1.0mu\tilde{\phi}}\ket{R}\right)\ket{\uparrow\downarrow}\\\
&+\left(e^{-\mathrm{i}\mkern 1.0mu\tilde{\phi}}\ket{L}+e^{\mathrm{i}\mkern
1.0mu\tilde{\phi}}\ket{R}\right)\ket{\downarrow\uparrow},\end{split}$ (7)

up to some global phase and normalisation constant. Upon the detection of an
orthogonally polarised photon (in this case $\ket{V}$), the spin states would
be projected onto the maximally entangled state
$\left(\ket{\uparrow\downarrow}-\ket{\downarrow\uparrow}\right)/\sqrt{2}$.
Similarly, one can set the photonic frequency such that
$\tilde{\phi_{1}}=\tilde{\phi_{2}}$, probabilistically generating the
entangled state
$\left(\ket{\uparrow\uparrow}+\ket{\downarrow\downarrow}\right)/\sqrt{2}$. The
efficiency of the entanglement generation increases with the energy detuning
until it peaks at around $40-60\%$ of the maximum possible efficiency. This is
because a phase shift that maximises the probability of obtaining an
orthogonally polarised photon (i.e. $|\tilde{\phi}|\approx\pi/2$) while
satisfying the requirement set in Eq. 7 is easier to achieve in systems that
are sufficiently dissimilar.

One physical limitation that needs to be accounted for is the spin decoherence
time, $T_{2}$, whereby the coherence of the superposition of spin states
decays mostly due to interactions with nuclear spins, with experimental values
for $T_{2}$ in the range of several $\mathrm{ns}$ Androvitsaneas  _et al._
(2022); Tran  _et al._ (2022); Huang  _et al._ (2015). In the case of a single
QD, the fidelity of the spin state would reduce by a factor of
$\left(1+\exp\left[-t/T_{2}\right]\right)/2$, where $t$ is the total time
taken for all four photons to interact with the spin, with current lifetime
values of exciton photons in micropillars reaching a few hundred $\mathrm{ps}$
Ginés  _et al._ (2022, 2021); Huber  _et al._ (2020), depending on the
detuning between the emitter and the cavity. In the case of $n$ QDs, the
fidelity would decay by a factor of
$\left(1+\exp\left[-nt/T_{2}\right]\right)/2$. Since the interaction time $t$
is inversely proportional to the register size of the spins, the reduction in
fidelity due to spin decoherence when utilising multiple entangled spin states
remains the same. Moreover, although there is a reduction in the measurement
confidence and fidelity, the spin dephasing has no detrimental effect on the
quiescent state of the data qubits once the syndrome has been extracted.

In conclusion, we have shown how the spin–photon interface may be applied to
quantum error detection to perform syndrome measurements, specifically by
utilising solid-state emitters inside micropillar cavities and optical
circular birefringence. Working in the strong-coupling regime, we have also
shown that the scheme is robust over the frequency detuning $\delta$ for
coupling strengths $g$ routinely reached in experiment, making this proposed
scheme a viable practical candidate. Our analysis has centred around the use
of the spin state as the measure qubit, however due to the inherent symmetry
of the interaction, it is possible to swap around the assignment of the two
types of qubits and perform the syndrome measurement with the photonic state
instead. Moreover, it might prove to be useful to use entangled spin states in
some implementations as increasing the register of measure qubits in this way
also allows for flexibility in the connectivity of the code Chamberland  _et
al._ (2020a, b) and accommodates for spectral variations between the data
qubits. Such a setup may also prove to be a more resource efficient way of
physically realising surface codes tailored to biased noise, where Hadamard
transformations are applied to certain Pauli matrices of the star and
plaquette operators Tuckett  _et al._ (2018); Ataides  _et al._ (2021); Tiurev
_et al._ (2022). We therefore show that entanglement is still possible for QD-
systems with varying characteristic energies. This can be done with high
levels of fidelity, albeit with lower generation efficiencies, even in lossy
systems when working in the strong coupling regime.

Potential directions for future work include the extension of the proposed
scheme to other measurement families in quantum error correction. Examples of
these include the logical Pauli operators, acting on the whole column or row
of the qubit array Bravyi and Hastings (2014); lattice surgery, which results
in logical operations on the encoded qubits by means of splitting or merging
the qubit lattice Horsman  _et al._ (2012); and measurements in higher-
dimensional hypergraph product codes Zeng and Pryadko (2019). Other avenues to
explore would be the generalisation of a Bell-state analyser to a scheme that
would allow for the observation and discrimination between non-maximally
entangled states, as well as the measurement of photons for further
versatility. It is evident that the spin–photon interface has potential
applications in various aspects of optical quantum information processing,
proving it to be a versatile and integral component in the design of quantum
technology and vastly improving the performance of linear optical quantum
computing.

###### Acknowledgements.

EC is supported by an EPSRC studentship. PK is supported by the EPSRC Quantum
Communications Hub, Grant No. EP/M013472/1. The authors thank Armanda
Quintavalle, Joschka Roffe, Ruth Oulton and Andrew Young for valuable comments
and discussions.

## References

  * Kok  _et al._ (2007) P. Kok, W. J. Munro, K. Nemoto, T. C. Ralph, J. P. Dowling, and G. J. Milburn, Reviews of Modern Physics 79, 135 (2007).
  * Knill  _et al._ (2001) E. Knill, R. Laflamme, and G. J. Milburn, Nature 409, 46 (2001).
  * Kimble (2008) H. J. Kimble, Nature 453, 1023 (2008).
  * Atatüre  _et al._ (2018) M. Atatüre, D. Englund, N. Vamivakas, S.-Y. Lee, and J. Wrachtrup, Nature Reviews Materials 3, 38 (2018).
  * Hacker  _et al._ (2016) B. Hacker, S. Welte, G. Rempe, and S. Ritter, Nature 536, 193 (2016).
  * Duan and Kimble (2004) L.-M. Duan and H. J. Kimble, Physical Review Letters 92 (2004).
  * Javadi  _et al._ (2018) A. Javadi, D. Ding, M. H. Appel, S. Mahmoodian, M. C. Löbl, I. Söllner, R. Schott, C. Papon, T. Pregnolato, S. Stobbe, L. Midolo, T. Schröder, A. D. Wieck, A. Ludwig, R. J. Warburton, and P. Lodahl, Nature Nanotechnology 13, 398 (2018).
  * Javadi  _et al._ (2015) A. Javadi, I. Söllner, M. Arcari, S. L. Hansen, L. Midolo, S. Mahmoodian, G. Kiršanskė, T. Pregnolato, E. H. Lee, J. D. Song, S. Stobbe, and P. Lodahl, Nature Communications 6 (2015).
  * Delteil  _et al._ (2015) A. Delteil, Z. Sun, W. bo Gao, E. Togan, S. Faelt, and A. Imamoğlu, Nature Physics 12, 218 (2015).
  * Young  _et al._ (2013) A. B. Young, C. Y. Hu, and J. G. Rarity, Physical Review A 87 (2013).
  * Cirac  _et al._ (1997) J. I. Cirac, P. Zoller, H. J. Kimble, and H. Mabuchi, Physical Review Letters 78, 3221 (1997).
  * Hu  _et al._ (2008a) C. Y. Hu, W. J. Munro, and J. G. Rarity, Physical Review B 78 (2008a).
  * Economou and Dev (2016) S. E. Economou and P. Dev, Nanotechnology 27, 504001 (2016).
  * Young  _et al._ (2011) A. B. Young, R. Oulton, C. Y. Hu, A. C. T. Thijssen, C. Schneider, S. Reitzenstein, M. Kamp, S. Höfling, L. Worschech, A. Forchel, and J. G. Rarity, Physical Review A 84 (2011).
  * Hu and Rarity (2011) C. Y. Hu and J. G. Rarity, Physical Review B 83 (2011).
  * Hu  _et al._ (2009a) C. Y. Hu, W. J. Munro, J. L. O’Brien, and J. G. Rarity, (2009a), arXiv:0901.3964 [quant-ph] .
  * Hu  _et al._ (2009b) C. Y. Hu, W. J. Munro, J. L. O’Brien, and J. G. Rarity, Physical Review B 80 (2009b).
  * Bonato  _et al._ (2010) C. Bonato, F. Haupt, S. S. R. Oemrawsingh, J. Gudat, D. Ding, M. P. van Exter, and D. Bouwmeester, Physical Review Letters 104 (2010).
  * Calsamiglia and Lütkenhaus (2001) J. Calsamiglia and N. Lütkenhaus, Applied Physics B 72, 67 (2001).
  * Shor (1995) P. W. Shor, Physical Review A 52, R2493 (1995).
  * Roffe (2019) J. Roffe, Contemporary Physics 60, 226 (2019).
  * Kitaev (2003) A. Y. Kitaev, Ann. Phys. (N. Y.) 303, 2 (2003).
  * Kitaev (1997) A. Y. Kitaev, Russian Mathematical Surveys 52, 1191 (1997).
  * Bravyi and Kitaev (1998) S. B. Bravyi and A. Y. Kitaev, (1998), arXiv:quant-ph/9811052 [quant-ph] .
  * Freedman and Meyer (1998) M. H. Freedman and D. A. Meyer, (1998), arXiv:quant-ph/9810055 [quant-ph] .
  * Fowler  _et al._ (2012) A. G. Fowler, M. Mariantoni, J. M. Martinis, and A. N. Cleland, Physical Review A 86 (2012).
  * Nielsen and Chuang (2012) M. A. Nielsen and I. L. Chuang,  _Quantum Computation and Quantum Information_ (Cambridge University Press, 2012).
  * Gottesman (1997) D. Gottesman, “Stabilizer codes and quantum error correction,”  (1997).
  * Bell  _et al._ (2014) B. A. Bell, D. A. Herrera-Martí, M. S. Tame, D. Markham, W. J. Wadsworth, and J. G. Rarity, Nature Communications 5 (2014).
  * Yao  _et al._ (2012) X.-C. Yao, T.-X. Wang, H.-Z. Chen, W.-B. Gao, A. G. Fowler, R. Raussendorf, Z.-B. Chen, N.-L. Liu, C.-Y. Lu, Y.-J. Deng, Y.-A. Chen, and J.-W. Pan, Nature 482, 489 (2012).
  * Aoki  _et al._ (2009) T. Aoki, G. Takahashi, T. Kajiya, J. ichi Yoshikawa, S. L. Braunstein, P. van Loock, and A. Furusawa, Nature Physics 5, 541 (2009).
  * Andersen  _et al._ (2020) C. K. Andersen, A. Remm, S. Lazar, S. Krinner, N. Lacroix, G. J. Norris, M. Gabureac, C. Eichler, and A. Wallraff, Nature Physics 16, 875 (2020).
  * Ristè  _et al._ (2015) D. Ristè, S. Poletto, M.-Z. Huang, A. Bruno, V. Vesterinen, O.-P. Saira, and L. DiCarlo, Nature Communications 6 (2015).
  * Kelly  _et al._ (2015) J. Kelly, R. Barends, A. G. Fowler, A. Megrant, E. Jeffrey, T. C. White, D. Sank, J. Y. Mutus, B. Campbell, Y. Chen, Z. Chen, B. Chiaro, A. Dunsworth, I.-C. Hoi, C. Neill, P. J. J. O’Malley, C. Quintana, P. Roushan, A. Vainsencher, J. Wenner, A. N. Cleland, and J. M. Martinis, Nature 519, 66 (2015).
  * Linke  _et al._ (2017) N. M. Linke, M. Gutierrez, K. A. Landsman, C. Figgatt, S. Debnath, K. R. Brown, and C. Monroe, Science Advances 3 (2017).
  * Lanyon  _et al._ (2013) B. P. Lanyon, P. Jurcevic, M. Zwerger, C. Hempel, E. A. Martinez, W. Dür, H. J. Briegel, R. Blatt, and C. F. Roos, Physical Review Letters 111 (2013).
  * Cramer  _et al._ (2016) J. Cramer, N. Kalb, M. A. Rol, B. Hensen, M. S. Blok, M. Markham, D. J. Twitchen, R. Hanson, and T. H. Taminiau, Nature Communications 7 (2016).
  * Warburton (2013) R. J. Warburton, Nature Materials 12, 483 (2013).
  * Hu  _et al._ (2008b) C. Y. Hu, A. Young, J. L. O’Brien, W. J. Munro, and J. G. Rarity, Physical Review B 78 (2008b).
  * Kok and Braunstein (2001) P. Kok and S. L. Braunstein, Physical Review A 63 (2001).
  * Volz  _et al._ (2012) T. Volz, A. Reinhard, M. Winger, A. Badolato, K. J. Hennessy, E. L. Hu, and A. Imamoğlu, Nature Photonics 6, 605 (2012).
  * Reitzenstein  _et al._ (2007) S. Reitzenstein, C. Hofmann, A. Gorbunov, M. Strauß, S. H. Kwon, C. Schneider, A. Löffler, S. Höfling, M. Kamp, and A. Forchel, Applied Physics Letters 90, 251109 (2007).
  * Androvitsaneas  _et al._ (2022) P. Androvitsaneas, A. B. Young, T. Nutz, J. M. Lennon, S. Mister, C. Schneider, M. Kamp, S. Höfling, D. P. S. McCutcheon, E. Harbord, J. G. Rarity, and R. Oulton, (2022), arXiv:2207.05596 [quant-ph] .
  * Tran  _et al._ (2022) K. X. Tran, A. S. Bracker, M. K. Yakes, J. Q. Grim, and S. G. Carter, Physical Review Letters 129 (2022).
  * Huang  _et al._ (2015) Y. Q. Huang, Y. Puttisong, I. A. Buyanova, X. J. Yang, A. Subagyo, K. Sueoka, A. Murayama, and W. M. Chen, Applied Physics Letters 106, 093109 (2015).
  * Ginés  _et al._ (2022) L. Ginés, M. Moczała-Dusanowska, D. Dlaka, R. Hošák, J. R. Gonzales-Ureta, J. Lee, M. Ježek, E. Harbord, R. Oulton, S. Höfling, A. B. Young, C. Schneider, and A. Predojević, Physical Review Letters 129 (2022).
  * Ginés  _et al._ (2021) L. Ginés, M. Moczała-Dusanowska, R. Hošák, M. Ježek, S. Höfling, C. Schneider, and A. Predojevic, in  _Conference on Lasers and Electro-Optics_ (Optica Publishing Group, 2021).
  * Huber  _et al._ (2020) T. Huber, M. Davanco, M. Müller, Y. Shuai, O. Gazzano, and G. S. Solomon, Optica 7, 380 (2020).
  * Chamberland  _et al._ (2020a) C. Chamberland, G. Zhu, T. J. Yoder, J. B. Hertzberg, and A. W. Cross, Physical Review X 10 (2020a), 10.1103/physrevx.10.011022.
  * Chamberland  _et al._ (2020b) C. Chamberland, A. Kubica, T. J. Yoder, and G. Zhu, New Journal of Physics 22, 023019 (2020b).
  * Tuckett  _et al._ (2018) D. K. Tuckett, S. D. Bartlett, and S. T. Flammia, Physical Review Letters 120 (2018), 10.1103/physrevlett.120.050505.
  * Ataides  _et al._ (2021) J. P. B. Ataides, D. K. Tuckett, S. D. Bartlett, S. T. Flammia, and B. J. Brown, Nature Communications 12 (2021), 10.1038/s41467-021-22274-1.
  * Tiurev  _et al._ (2022) K. Tiurev, P.-J. H. S. Derks, J. Roffe, J. Eisert, and J.-M. Reiner, “Correcting non-independent and non-identically distributed errors with surface codes,”  (2022).
  * Bravyi and Hastings (2014) S. Bravyi and M. B. Hastings, in  _Proceedings of the Forty-Sixth Annual ACM Symposium on Theory of Computing_, STOC ’14 (Association for Computing Machinery, New York, NY, USA, 2014) p. 273–282.
  * Horsman  _et al._ (2012) C. Horsman, A. G. Fowler, S. Devitt, and R. V. Meter, New Journal of Physics 14, 123011 (2012).
  * Zeng and Pryadko (2019) W. Zeng and L. P. Pryadko, Physical Review Letters 122 (2019), 10.1103/physrevlett.122.230501.

Supplemental Material: Spin-augmented observables for efficient photonic
quantum error correction

## Star and plaqeutte measurements

We assume that the spin, serving as the measure qubit, is initialised in the
state $\ket{+_{S}}=\left(\ket{\uparrow}+\ket{\downarrow}\right)/\sqrt{2}$. The
star and plaquette operators, defined as

$\mathsf{X}_{s}=\prod_{j\in\text{star}(s)}\hat{X}_{j}\qquad\text{ and
}\qquad\mathsf{Z}_{p}=\prod_{j\in\text{plaq}(p)}\hat{Z}_{j},$ (S1)

respectively, where $\hat{X}$ and $\hat{Z}$ are the Pauli-X and Pauli-Z
operators, stabilize the surface code. The eigenbasis for these operators may
be expressed as

$\left\\{\bigotimes_{j\in\text{star}(s)}\ket{i}_{j}\text{s.t.}\ket{i}=\ket{0}\text{or}\ket{1}\right\\}\qquad\text{
and
}\qquad\left\\{\bigotimes_{j\in\text{plaq}(p)}\ket{i}_{j}\text{s.t.}\ket{i}=\ket{+}\text{or}\ket{-}\right\\},$
(S2)

respectively, where $\ket{\pm}=\left(\ket{0}\pm\ket{1}\right)/\sqrt{2}$.

We encode the logical $\ket{0}$ and logical $\ket{1}$ qubits into the left-,
$\ket{L}$ and right-handed polarisations, $\ket{R}$, and apply a Hadamard gate
before and after interaction in the case of a star measurement, such that
$\ket{0}\leftrightarrow\ket{+}$ and $\ket{1}\leftrightarrow\ket{-}$. Then the
evolution of a photonic eigenstate and the spin state can be expressed as

$\begin{split}\bigotimes_{\begin{subarray}{c}j\in\text{star}(s)\\\ \text{or
}\text{plaq}(p)\end{subarray}}\ket{i_{j}}\otimes\ket{+_{S}}\rightarrow&\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\phi_{j,\uparrow}\right)\ket{i_{j}}\otimes\ket{\uparrow}/\sqrt{2}+\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\phi_{j,\downarrow}\right)\ket{i_{j}}\otimes\ket{\downarrow}/\sqrt{2}\\\
&=\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\phi_{j,\uparrow}\right)\ket{i_{j}}\otimes\left[\ket{\uparrow}+\prod_{k}\exp\left[-\mathrm{i}\mkern
1.0mu\left(\phi_{k,\uparrow}-\phi_{k,\downarrow}\right)\right]\ket{\downarrow}\right]/\sqrt{2}\\\
&=e^{4\mathrm{i}\mkern 1.0mu\phi_{0}}\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\delta_{i_{j}L}\right)\ket{i_{j}}\otimes\left[\ket{\uparrow}+\prod_{k}\exp\left[-\mathrm{i}\mkern
1.0mu\left(\phi_{k,\uparrow}-\phi_{k,\downarrow}\right)\right]\ket{\downarrow}\right]/\sqrt{2},\end{split}$
(S3)

where $\ket{i_{j}}\in\\{\ket{L},\ket{R}\\}$, $j$ and $k$ index the same four
photonic qubits in a plaquette or star set, $\delta_{i_{j}L}$ is the Kronecker
delta, and $\phi_{j,\ast}$ is the phase shift resulting from the interaction
between the photonic state $\ket{i_{j}}$ and spin state
$\ket{\ast}\in\left\\{\ket{\uparrow},\ket{\downarrow}\right\\}$. This gives us
Eq. 3 up to a global phase $\exp\left[4\mathrm{i}\mkern 1.0mu\phi_{0}\right]$.
(One may also consider an initial spin state of
$\ket{-_{S}}=\left(\ket{\uparrow}-\ket{\downarrow}\right)/\sqrt{2}$, and
perform syndrome extraction in a similar manner.)

## Considering boundary conditions

So far, we have consider the toric code exhibiting only periodic boundary
conditions. Different surface codes may also be comprised of various types of
boundaries that result in modifications of the stabilizer operators applied on
the data qubits located along these boundaries. Consider boundaries in the
qubit array as shown in Fig. S1. The spin–photon interface can be used for
these syndrome measurements as well, without requiring a change in the
frequency detuning $\delta$, such that

$\bigotimes_{\begin{subarray}{c}j\in\text{star}(s)\\\ \text{or
}\text{plaq}(p)\end{subarray}}\ket{i_{j}}\otimes\ket{+_{S}}\rightarrow
e^{3\mathrm{i}\mkern 1.0mu\phi_{0}}\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\delta_{i_{j}L}\right)\ket{i_{j}}\otimes\left[\ket{\uparrow}+\prod_{k}\exp\left[-\mathrm{i}\mkern
1.0mu\left(\phi_{k,\uparrow}-\phi_{k,\downarrow}\right)\right]\ket{\downarrow}\right]/\sqrt{2}.\\\
$ (S4)

As the cumulation of the relative phase in the electron spin state is
dependent on the parity of the photonic state, where the $+1$ ($-1$)
eigenstates are of even (odd) parity, the state evolves to either
$\ket{L}_{S}=\left(\ket{\uparrow}+\mathrm{i}\mkern
1.0mu\ket{\downarrow}\right)/\sqrt{2}$
($\ket{R}_{S}=\left(\ket{\uparrow}-\mathrm{i}\mkern
1.0mu\ket{\downarrow}\right)/\sqrt{2}$). The syndrome can therefore be
obtained by measuring the spin in the $\hat{Y}$-basis. Any corrections to the
phase shift of the photonic state are addressed in the same manner as for
weight-four operators.

Figure S1: A representation of boundary conditions in the two-dimensional
surface code. The plaquette, $\mathsf{Z}_{p}$, and star, $\mathsf{X}_{s}$
measurement operators of weight three acting on the given boundaries are shown
in green (dotted outline) and pink (solid outline), respectively.

## Swapping the assignment of the data and measure qubits

The interaction between the photon and the spin is symmetric, meaning that the
assignment of the data and measure qubits may be swapped around. We show this
explicitly by starting off from, say, a horizontally polarised photon
$\ket{H}=\left(\ket{L}+\ket{R}\right)/\sqrt{2}$ that then interacts
consecutively with each spin state. The total state transforms to

$\bigotimes_{\begin{subarray}{c}j\in\text{star}(s)\\\ \text{or
}\text{plaq}(p)\end{subarray}}\ket{i_{j}}\otimes\ket{H}\rightarrow
e^{4\mathrm{i}\mkern 1.0mu\phi_{0}}\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\delta_{i_{j}\uparrow}\right)\ket{i}_{j}\otimes\left[\ket{\L}+\prod_{k}\exp\left[-\mathrm{i}\mkern
1.0mu\left(\phi_{k,L}-\phi_{k,R}\right)\right]\ket{R}\right]/\sqrt{2},$ (S5)

where now $\ket{i_{j}}\in\left\\{\ket{\uparrow},\ket{\downarrow}\right\\}$ and
$\phi_{j,\ast}$ is the phase shift resulting from the interaction between the
spin state $\ket{i_{j}}$ and spin state
$\ket{\ast}\in\left\\{\ket{L},\ket{R}\right\\}$. The detection of a
horizontally (vertically, $\ket{V}=-\mathrm{i}\mkern
1.0mu\left(\ket{L}-\ket{R}\right)/\sqrt{2}$) polarised photon would signal a
syndrome of $+1$ ($-1$). In the case of a syndrome measurement at the
boundaries, the photonic state evolves to $\ket{L}\pm\mathrm{i}\mkern
1.0mu\ket{R}$, which can be easily resolved into $\ket{H}$ and $\ket{V}$ by
adding a polarisation-dependent $\pi/2$ phase shift post-interaction and
before photon-detection.

In order to correct for possible changes in the relative phase shifts between
the eigenstates making up the quiescent state, it is sufficient to simply
allow a $\ket{R}$ photon to interact with each data qubit. Then

$\begin{split}e^{4\mathrm{i}\mkern
1.0mu\phi_{0}}\bigotimes_{j}\exp\left(\mathrm{i}\mkern
1.0mu\tilde{\phi}\delta_{i_{j}\uparrow}\right)\ket{i}_{j}\otimes\ket{R}\rightarrow&e^{4\mathrm{i}\mkern
1.0mu\phi_{0}}\bigotimes_{j}\exp\left[\mathrm{i}\mkern
1.0mu\left(\tilde{\phi}\delta_{i_{j}\uparrow}+\phi_{0}\delta_{i_{j}\uparrow}+\phi_{h}\delta_{i_{j}\downarrow}\right)\right]\ket{i}_{j}\otimes\ket{R}\\\
&=\exp\left[4\mathrm{i}\mkern
1.0mu\left(\phi_{0}+\phi_{h}\right)\right]\bigotimes_{j}\ket{i}_{j}\otimes\ket{R},\end{split}$
(S6)

where $\tilde{\phi}+\phi_{0}=\phi_{h}$ and the reflection coefficient
described in Eq. 1 is independent of the spin orientation. This way, every
eigenstate obtains an equivalent total phase shift, rendering just an overall
global phase shift to the surface code.

## Entanglement generation

Figure S2: Heralded efficiency, $\eta$, of the entanglement generation
protocol as a function of $\Delta/\kappa$, where
$\Delta=\omega_{X_{1}}-\omega_{X_{2}}$ is the central energy detuning, for
different linewidth ratios, $\gamma_{2}/\gamma_{1}$, and coupling strengths
$g/\kappa$. $\gamma_{1}/\kappa$ is set to 0.1. The shaded regions indicate the
maximum possible efficiency of the protocol in the ideal case with identical
systems.

In Fig. S2 we show the heralded efficiency, $\eta$, of the entangling
procedure described by Eq. 7 as a function of the characteristic energy
detuning, $\Delta=\omega_{X_{1}}-\omega_{X_{2}}$, for varying cavity decay
rates $\kappa$ and coupling strengths $g$. (We work here both in the weak- and
the strong-coupling regime to show that the entangling procedure may be
employed in either.) We consider only the case of
$\tilde{\phi_{1}}=-\tilde{\phi_{2}}$ due to higher probabilities of success,
as phase shifts that satisfy this condition for QD–spin systems exhibiting
typical variations can approach very closely $\pm\pi/2$. Looking at Eq. 7,
this maximises the probability of measuring an orthogonally polarised photon.
Also, variations in the QD linewidths may marginally enhance the efficiency,
however the effect of this decreases as $g$ is increased.

We also show in Fig. S3 the effect of spectral variations as well as side-
cavity losses, characterised by $\kappa_{s}$, on the fidelity of the entangled
state:

$\mathcal{F}=\frac{|r_{h_{1}}r_{h_{2}}-r_{0_{1}}r_{0_{2}}|^{2}}{|r_{h_{1}}r_{h_{2}}-r_{0_{1}}r_{0_{2}}|^{2}+|r_{h_{1}}r_{0_{2}}-r_{0_{1}}r_{h_{2}}|^{2}},$
(S7)

where $r_{h_{i}}$ and $r_{0_{i}}$ are the reflection coefficients for the QD-
coupled and empty cavity cases for system $i$, respectively.

Figure S3: Fidelity, $\mathcal{F}$, of the entanglement generation process as
a function of $\Delta/\kappa$, where $\Delta=\omega_{X_{1}}-\omega_{X_{2}}$ is
the central energy detuning. The QDs have linewidth ratios,
$\gamma_{2}/\gamma_{1}$, are set to 0.3 (blue), 1.0 (orange) and 1.5 (purple);
cavity loss rates, $\kappa_{s}/\kappa$, of 0.0 (solid), 0.2 (dashed) and 0.5
(dash-dotted); $\gamma_{1}/\kappa$ is set to 0.1.