# Quantum variational learning for quantum error-correcting codes

Chenfeng Cao  Department of Physics, The Hong Kong University of Science and
Technology, Clear Water Bay, Kowloon, Hong Kong, China  Chao Zhang  Department
of Physics, The Hong Kong University of Science and Technology, Clear Water
Bay, Kowloon, Hong Kong, China  Zipeng Wu  Department of Physics, The Hong
Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong
Kong, China  Markus Grassl  International Centre for Theory of Quantum
Technologies, University of Gdansk, 80-309 Gdansk, Poland  Bei Zeng
<EMAIL_ADDRESS>Department of Physics, The Hong Kong University of Science and
Technology, Clear Water Bay, Kowloon, Hong Kong, China

###### Abstract

Quantum error correction is believed to be a necessity for large-scale fault-
tolerant quantum computation. In the past two decades, various constructions
of quantum error-correcting codes (QECCs) have been developed, leading to many
good code families. However, the majority of these codes are not suitable for
near-term quantum devices. Here we present VarQEC, a noise-resilient
variational quantum algorithm to search for quantum codes with a hardware-
efficient encoding circuit. The cost functions are inspired by the most
general and fundamental requirements of a QECC, the Knill-Laflamme conditions.
Given the target noise channel (or the target code parameters) and the
hardware connectivity graph, we optimize a shallow variational quantum circuit
to prepare the basis states of an eligible code. In principle, VarQEC can find
quantum codes for any error model, whether additive or non-additive,
degenerate or non-degenerate, pure or impure. We have verified its
effectiveness by (re)discovering some symmetric and asymmetric codes, e.g.,
$((n,2^{n-6},3))_{2}$ for $n$ from 7 to 14. We also found new $((6,2,3))_{2}$
and $((7,2,3))_{2}$ codes that are not equivalent to any stabilizer code, and
extensive numerical evidence with VarQEC suggests that a $((7,3,3))_{2}$ code
does not exist. Furthermore, we found many new channel-adaptive codes for
error models involving nearest-neighbor correlated errors. Our work sheds new
light on the understanding of QECC in general, which may also help to enhance
near-term device performance with channel-adaptive error-correcting codes.

##  1 Introduction

Fault-tolerant quantum computers promise to solve some computational problems
much faster than classical machines, such as quantum chemistry simulation [1],
prime factorization [2], solving linear systems of equations [3]. However,
quantum information carried by current noisy intermediate-scale quantum (NISQ)
systems is highly fragile and can be easily altered by the environment. The
aforementioned tasks are so far out of reach.

The most promising technique to maintain coherence and protect the quantum
information from noise is quantum error-correcting codes [4, 5, 6, 7, 8]. The
main idea of quantum error correction is to encode the low-dimensional quantum
state in a larger system such that errors occurring during the computation can
be corrected due to the physical redundancy. As long as the noise rate $p$ is
below a specific threshold, QECCs can correct the error and reduce the error
probability from $\mathcal{O}(p)$ to higher orders. In recent years, the
intrinsic connections between QECCs and other areas of physics, such as
quantum gravity [9], have also been noticed.

Knill and Laflamme devised sufficient and necessary conditions (known as the
Knill-Laflamme conditions) for quantum error correction [10]. In principle, we
can find any QECC as long as we find solutions to the Knill-Laflamme
conditions. However, solving these systems of equations is extremely difficult
in the general case. Therefore many open problems in this field remain
unsolved, e.g., do all degenerate QECCs obey the Hamming bound? Which QECC has
the highest error threshold? In practice, researchers usually analyze QECCs
under the Pauli framework and have developed various QECC families, such as
surface codes [11, 12], Calderbank-Shor-Steane (CSS) codes [13, 14],
stabilizer codes [5], codeword stabilized (CWS) codes [15, 16], quantum low-
density parity-check codes [17, 18].

Up till now, no logical qubit/operation with useful fidelity was realized in
experiments since current gate noise rates are still much larger than the
requirements. Very recently, Egan et al. [19] prepared a Bacon–Shor logical
qubit with 13 trapped-ion qubits and demonstrated a logical single-qubit
Clifford gate. Further, Postler et al. [20] demonstrated a logical $T$-gate
based on the 7-qubit color code. However, the fidelities of these state-of-
the-art logical qubits are even lower than those of the physical qubits. From
a theoretical perspective, the codes used in those experiments are not device-
tailored and may not be optimal for the system. The noise channels on
different physical platforms differ significantly [21, 22, 23]. Symmetric QECC
constructions under the Pauli framework can not be directly adapted to non-
Hermitian/non-unitary noise channels. It is highly desirable to design
asymmetric or channel-adaptive QECCs with a hardware-efficient encoder. Such
device-tailored codes can protect logical information more efficiently.

Besides analytical constructions, researchers have been trying to find QECCs
with computational methods for a long time. Refs. [24, 25, 16, 26] designed
classical algorithms for finding quantum codes associated with graphs. Ref.
[27] used numerical greedy search for finding stabilizer codes. These
algorithms, however, cannot find arbitrary codes and are extremely time-
consuming. With the popularity of artificial intelligence, researchers also
started to design and optimize quantum codes with neural networks [28, 29, 30,
31]. These classical black-box models perform pretty well for certain
problems. In this work, we add a new general method to this toolbox. We devise
a hybrid quantum-classical algorithm called VarQEC for finding quantum error-
correcting codes. The cost functions therein are based on the Knill-Laflamme
conditions. We iteratively update the parameters in a variational quantum
circuit (VQC) with stochastic gradient descent. If the final cost functions
are sufficiently small, we obtain an approximate quantum code whose inaccuracy
is bounded. Compared with the classical iterative algorithm introduced in Ref.
[32], our method yields the encoding circuit, not merely the encoding
isometry. After finding a QECC and its encoder, the decoding operation can be
found via various methods like semidefinite programming [33], convex
optimization [34], or classical/quantum machine learning [35, 36, 37].

VarQEC allows for non-Hermitian or non-unitary errors and is surprisingly
effective. We numerically verify its effectiveness up to 14 qubits. For
symmetric Pauli errors, we successfully rediscover many good quantum codes,
e.g., $((5,2,3))_{2}$, $((5,6,2))_{2}$, $((6,2,3))_{2}$, $((7,2,3))_{2}$,
$((8,8,3))_{2}$, $((9,8,3))_{2}$, $((10,2^{4},3))_{2}$, $((11,2^{5},3))_{2}$,
$((12,2^{6},3))_{2}$, $((13,2^{7},3))_{2}$, $((14,2^{8},3))_{2}$,
$((10,4,4))_{2}$. Some of the $((6,2,3))_{2}$, $((7,2,3))_{2}$ codes we find
are not locally equivalent to any CWS code. It is an open question of whether
there is a quantum code with parameters $((7,3,3))_{2}$, our numerical
evidence suggests that it is non-existent. Then we apply VarQEC to search for
asymmetric codes (which detect more Pauli-$X$/$Y$ errors than Pauli-$Z$ errors
or vice versa) and make new discoveries. Furthermore, we search for channel-
adaptive codes for nearest-neighbor collective amplitude damping and nearest-
neighbor collective phase-flips, and find eligible new codes with a hardware-
efficient encoding circuit for various connectivity graphs. Since VarQEC is
capable to find a QECC with the shallowest possible encoding circuit, it is
promising to design codes with sufficient fidelity that can be tested and
implemented on near-term devices. Although only relatively small systems were
investigated in this paper, hierarchical concatenation can construct good
quantum codes with large code lengths and distances [5, 38, 39].

The paper is organized as follows. In Sec. 2, we introduce some background of
quantum error correction. In Sec. 3, we introduce our cost functions and
present propositions to support our definitions. In Sec. 4, we explain the
VarQEC algorithm in detail. In Sec. 5, we show quantum codes (re)discovered
thereby, including symmetric, asymmetric, and channel-adaptive codes for
nearest-neighbor collective amplitude damping and nearest-neighbor collective
phase-flips. Sec. 6 discusses the noise resilience feature of VarQEC. Sec. 7
discusses the barren plateaus and the noise-induced barren plateaus in VarQEC
optimization. In Sec. 8, we verify our algorithm by an experiment on an IBM
quantum device. The conclusions and future directions are summarized and
discussed in Sec. 9. The appendices give some proof details, a discussion on
overparameterization, an alternative variational ansatz, some non-CWS quantum
codes, and a list of the quantum weight enumerators of quantum codes
discovered by VarQEC.

##  2 Preliminaries

In classical computation and communication, redundancy is added when encoding
a message such that the errors can be detected and corrected. Although each
bit may flip with some probability, the encoded message can be recovered with
high probability. The philosophy behind quantum error correction is the same.
We use several low-fidelity physical qudits (e.g., qubits) to encode the
logical quantum information redundantly and nonlocally. Then quantum errors
can be detected through syndrome measurements and corrected through a unitary
operation. A $q$-ary QECC $\mathcal{C}$ is a $K$-dimensional subspace of the
$q^{n}$-dimensional Hilbert space $(\mathbb{C}^{q})^{\otimes n}$, where $n$ is
the number of physical qudits (referred to as the code length). For qubit
systems, $q=2$, $\mathcal{C}\subset(\mathbb{C}^{2})^{\otimes n}$. When $K=1$,
the code is a fixed quantum state without computational use. Throughout this
paper, we only discuss $K\geq 2$.

Knill and Laflamme developed a general theory of quantum error correction.
They obtained the sufficient and necessary conditions for an exact QECC [10]:
a quantum code with orthonormal basis states $\\{|\psi_{j}\rangle\\}$ corrects
the error set $\mathcal{E}=\\{E_{\alpha}\\}$ if and only if

$P_{c}E_{\alpha}^{\dagger}E_{\beta}P_{c}=\lambda_{\alpha\beta}P_{c},$ (1)

holds for all $E_{\alpha},E_{\beta}\in\mathcal{E}$. Here,
$P_{c}=\sum_{j}|\psi_{j}\rangle\langle\psi_{j}|$ is the orthogonal projector
onto the code space, and each $\lambda_{\alpha\beta}$ is a complex number.
Moreover, we say the quantum code is non-degenerate if the matrix
$\lambda_{\alpha\beta}$ has full rank [40].

We can understand these conditions intuitively. When $i\neq j$,
$\langle\psi_{i}|E_{\alpha}^{\dagger}E_{\beta}|\psi_{j}\rangle=0$ for any
error product $E_{\alpha}^{\dagger}E_{\beta}$. This means orthogonal logical
states remain orthogonal after the noise channel, the logical information is
not corrupted. When $i=j$,
$\langle\psi_{j}|E_{\alpha}^{\dagger}E_{\beta}|\psi_{j}\rangle=\lambda_{\alpha\beta}$
with $\lambda_{\alpha\beta}$ being a constant only determined by the error
product. This indicates that the projections between subspaces induced by
different errors are information-preserving, the errors have an orthogonal
decomposition. Therefore, we can correct the error without knowing or
destroying the quantum superposition state.

The quantum error detection conditions have a similar form: a quantum code
with code space projector $P_{c}$ can detect the error set
$\mathcal{E}=\\{E_{\mu}\\}$ if and only if

$P_{c}E_{\mu}P_{c}=\lambda_{\mu}P_{c}$ (2)

holds for all $E_{\mu}\in\mathcal{E}$.

In experiments, most quantum errors are uncorrelated single-qudit errors. A
natural measure of the capability of a QECC is the number of single-qudit
errors that it can detect. This motivated the concept of “code distance”: the
distance of a QECC is the largest possible integer $d$ such that the code can
detect any error non-trivially acting on at most $d-1$ qudits. Researchers
usually denote the code parameters of a $q$-ary QECC with code length $n$,
code dimension $K$, and code distance $d$ as $((n,K,d))_{q}$.

Comparing the Knill-Laflamme conditions and quantum error detection
conditions, we know that a distance-$d$ QECC can correct any error set
$\mathcal{E}=\\{E_{\alpha}\\}$ with each $E_{\alpha}$ non-trivially acting on
at most $\lfloor(d-1)/2\rfloor$ qudits.

For convenience, $2$-ary quantum codes are usually constructed and analyzed in
the Pauli framework. Consider an $n$-fold Pauli tensor product

$O_{\alpha}\in\\{X,Y,Z,I\\}^{\otimes n}.$ (3)

Denote the number of $X$ factors, $Y$ factors and $Z$ factors in $O_{\alpha}$
as $\operatorname{wt}_{\mathrm{X}}(O_{\alpha})$,
$\operatorname{wt}_{\mathrm{Y}}(O_{\alpha})$, and
$\operatorname{wt}_{\mathrm{Z}}(O_{\alpha})$. The weight of $O_{\alpha}$ is

$\operatorname{wt}(O_{\alpha})=\operatorname{wt}_{\mathrm{X}}(O_{\alpha})+\operatorname{wt}_{\mathrm{Y}}(O_{\alpha})+\operatorname{wt}_{\mathrm{Z}}(O_{\alpha}).$
(4)

An equivalent definition of the code distance of a QECC with projector $P_{c}$
is the largest possible integer $d$ such that

$P_{c}O_{\alpha}P_{c}=\lambda_{\alpha}P_{c}$ (5)

holds for all Pauli tensor product $O_{\alpha}$ with
$\operatorname{wt}(O_{\alpha})<d$.

In practical scenarios, Pauli-$Z$ errors are usually more prevalent than
Pauli-$X$ and Pauli-$Y$ [41]. Accordingly, we use a parameter $c_{\text{Z}}$
to characterize this noise bias and define the following
$c_{\text{Z}}$-effective weight and $c_{\text{Z}}$-effective distance.

###### Definition 1

The $c_{\text{Z}}$-effective weight of a Pauli tensor product $O_{\alpha}$ is

$\operatorname{wt}_{e}(O_{\alpha},c_{\text{Z}})=\operatorname{wt}_{\mathrm{X}}(O_{\alpha})+\operatorname{wt}_{\mathrm{Y}}(O_{\alpha})+c_{\text{Z}}\operatorname{wt}_{\mathrm{Z}}(O_{\alpha}),$
(6)

where $c_{\text{Z}}>0$. The $c_{\text{Z}}$-effective distance of a quantum
code with projector $P_{c}$ is the largest possible integer
$d_{e}(c_{\text{Z}})$ such that

$P_{c}O_{\alpha}P_{c}=\lambda_{\alpha}P_{c}$ (7)

holds for all Pauli tensor product $O_{\alpha}$ with
$\operatorname{wt}_{e}(O_{\alpha},c_{\text{Z}})<d_{e}(c_{\text{Z}})$.

This definition is a generalization of the concept of “effective distance”
introduced in Ref. [42]. An asymmetric code with code parameters
$((n,K,d_{e}(c_{\text{Z}})))_{2}$ can correct arbitrary Pauli error with
$c_{\text{Z}}$-effective weight smaller than $d_{e}(c_{\text{Z}})/2$, and
detect arbitrary Pauli error with $c_{\text{Z}}$-effective weight smaller than
$d_{e}(c_{\text{Z}})$. When Pauli-$Z$ errors occur more frequently than
Pauli-$X$/$Y$ errors, $0<c_{\text{Z}}<1$; when the relaxation times ($T_{1}$)
are much smaller than the dephasing times ($T_{2}$), Pauli-$X$/$Y$ errors
occur more frequently, $c_{\text{Z}}>1$.

Quantum codes with relatively small distances can be concatenated to construct
a code with large code length and distance, as illustrated in Fig. 1. Suppose
we have an outermost code with parameters $((n_{1},K,d_{1}))_{q}$, other outer
codes with parameters $((n_{2},q,d_{2}))_{q}$, $((n_{3},q,d_{3}))_{q}$,
$\dots$, $((n_{l-1},q,d_{l-1}))_{q}$, and an inner code with parameters
$((n_{l},q,d_{l}))_{q}$. We can construct a large code through several levels
of concatenation: the logical data is first encoded using the outermost code,
each physical qudit therein is further encoded using the
$((n_{2},q,d_{2}))_{q}$ code, and so forth. The hierarchically concatenated
quantum code has parameters

$((\prod_{j}n_{j},K,\prod_{j}d_{j}))_{q}.$ (8)

Likewise, we can concatenate asymmetric codes. A distance lower bound is given
as follows.

###### Theorem 1

Consider asymmetric outer codes with parameters
$((n_{1},K,d_{e}(c_{\text{Z}})=\delta_{1}))_{2}$,
$((n_{2},2,d_{e}(c_{\text{Z}})=\delta_{2}))_{2}$,
$((n_{3},2,d_{e}(c_{\text{Z}})=\delta_{3}))_{2}$, $\dots$,
$((n_{l-1},2,\delta_{l-1}))_{2}$, and an inner code with parameters
$((n_{l},2,\delta_{l}))_{2}$. Concatenating these codes yields a new code with
parameters

$((\prod_{j}n_{j},K,d_{e}(c_{\text{Z}})=\delta))_{2}$ (9)

where

$\delta\geq\min\\{1,c_{\text{Z}}\\}\prod_{j}\left\lceil\frac{\delta_{j}}{\max\\{1,c_{\text{Z}}\\}}\right\rceil.$
(10)

Proof  Assume the concatenated code cannot detect a Pauli tensor product
$O_{\alpha}$. For the outer code, errors occur on at least
$\left\lceil\delta_{1}/\max\\{1,c_{\text{Z}}\\}\right\rceil$ qubits. Each of
these qubits is connected to a block of the first inner code
$((n_{2},2,d_{e}(c_{\text{Z}})=\delta_{2}))_{2}$ and for every such block,
errors occur on at least
$\left\lceil\delta_{2}\max\\{1,c_{\text{Z}}\\}\right\rceil$ qubits. From
similar arguments, errors occur on at least
$\left\lceil\delta_{j}\max\\{1,c_{\text{Z}}\\}\right\rceil$ qubits in the
$j$-th block. The weight of $O_{\alpha}$ is bounded by

$\operatorname{wt}(O_{\alpha})\geq\prod_{j}\left\lceil\delta_{j}/\max\\{1,c_{\text{Z}}\\}\right\rceil.$
(11)

Hence, the $c_{\text{Z}}$-effective weight of $O_{\alpha}$ is at least

$\min\\{1,c_{\text{Z}}\\}\prod_{j}\left\lceil\delta_{j}/\max\\{1,c_{\text{Z}}\\}\right\rceil.$
(12)

The concatenated code can detect any Pauli tensor product with
$c_{\text{Z}}$-effective weight smaller than this value, we conclude

$\delta\geq\min\\{1,c_{\text{Z}}\\}\prod_{j}\left\lceil\frac{\delta_{j}}{\max\\{1,c_{\text{Z}}\\}}\right\rceil.$
(13)

$\blacksquare$

Figure 1: Schematic illustration of quantum code concatenation. After finding
quantum codes with encoders $U_{1},U_{2},U_{3},\dots$, we hierarchically
concatenate these encoders to obtain a large-distance quantum code.

##  3 Theoretical Basis

A lot of methods for constructing QECCs are using the stabilizer formalism,
but there are not that many outside the Pauli framework. This work aims to
search for quantum codes based on the most fundamental principle, i.e., the
Knill-Laflamme conditions and the quantum error detection conditions. A
crucial tool in our scheme is the variational quantum circuit which consists
of multiple layers of parameterized quantum gates.

The primary ingredient of a variational algorithm is the cost function(s). We
define the cost functions of VarQEC as follows.

######  Definition 2 (Cost functions)

Consider an error set $\mathcal{E}=\\{E_{\mu}\\}$ and a length-$n$ quantum
code with parameterized orthogonal basis states

$\\{|\psi_{1}(\boldsymbol{\theta})\rangle,|\psi_{2}(\boldsymbol{\theta})\rangle,\dots,|\psi_{K}(\boldsymbol{\theta})\rangle\\}.$
(14)

We define the $\ell_{1}$-norm cost function

$\displaystyle C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})\equiv$
$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\Big{(}\sum_{1\leq i<j\leq
K}\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}$ (15)
$\displaystyle+\sum_{j=1}^{K}\big{|}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}/2\Big{)}$

and the $\ell_{2}$-norm cost function

$\displaystyle C^{\ell_{2}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})\equiv$
$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\Big{(}\sum_{1\leq i<j\leq
K}\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}^{2}$ (16)
$\displaystyle+\sum_{j=1}^{K}\big{|}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}^{2}/4\Big{)}$

where $\overline{\langle
E_{\mu}\rangle}=\sum_{j=1}^{K}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle/K$.

Clearly, $C^{\ell_{1}}_{n,K,\mathcal{E}}$ and $C^{\ell_{2}}_{n,K,\mathcal{E}}$
are always non-negative and have the same zero-points. When
$C^{\ell_{1}}_{n,K,\mathcal{E}}\leq 1$,
$C^{\ell_{2}}_{n,K,\mathcal{E}}\leq(C^{\ell_{1}}_{n,K,\mathcal{E}})^{2}$. When
$C^{\ell_{1}}_{n,K,\mathcal{E}}=0$, the quantum code can perfectly detect the
error set $\mathcal{E}$.

To find symmetric codes with code parameters $((n,K,d))_{2}$, we use the Pauli
error model and choose

$\mathcal{E}=\\{O_{\alpha}|\operatorname{wt}(O_{\alpha})<d\\},$ (17)

where $O_{\alpha}$s are Pauli tensor products. Likewise, when searching for
asymmetric codes with code parameters $((n,K,d_{e}(c_{\text{Z}})))_{2}$, we
choose

$\mathcal{E}=\\{O_{\alpha}|\operatorname{wt_{e}}(O_{\alpha},c_{\text{Z}})<d_{e}(c_{\text{Z}})\\}.$
(18)

To find channel-adaptive codes for a general noise channel
$\mathcal{N}(\rho)=\sum_{\alpha}E_{\alpha}\rho E_{\alpha}^{\dagger}$, we
choose

$\mathcal{E}=\\{E^{\dagger}_{\alpha}E_{\beta}|E_{\alpha},E_{\beta}\text{ are
Kraus operators of }\mathcal{N}\\}.$ (19)

Note that the error set $\mathcal{E}$ in principle can include non-unitary and
non-Hermitian errors. For such errors, we can either twirl them to Pauli
errors or simulate them directly by adding ancilla qubits and performing
positive-operator valued measures (POVMs).

In practice, due to the inexact realization of an encoding isometry, quantum
error correction/detection conditions are not exactly satisfied, and QECCs
cannot protect the information from errors perfectly. Nevertheless, QECCs can
still detect and correct most errors. Such approximate quantum error
correction schemes hold great promise [43, 44]. A parameter $\varepsilon$
characterizes the inaccuracy of an approximate code. If a QECC is
$\varepsilon$-correctable for a noise channel $\mathcal{N}$, its worst-case
entanglement fidelity is greater than $1-\varepsilon$ with appropriate
recovery [45]. Bény et al. proposed an approximate version of the Knill-
Laflamme conditions for such approximate codes.

######  Lemma 1 (Corollary 2, Ref. [46])

A code defined by the projector $P_{c}$ is $\varepsilon$-correctable under a
noise channel $\mathcal{N}(\rho)=\sum_{\alpha}E_{\alpha}\rho
E_{\alpha}^{\dagger}$, if and only if

$P_{c}E_{\alpha}^{\dagger}E_{\beta}P_{c}=\lambda_{\alpha\beta}P_{c}+P_{c}B_{\alpha\beta}P_{c},$
(20)

where $\lambda_{\alpha\beta}$ are the components of a non-negative Hermitian
operator with trace one, $B_{\alpha\beta}$ is a Hermitian operator, and the
Bures distance [47] between two channels
$\Lambda(\rho)=\sum_{\alpha\beta}\lambda_{\alpha\beta}\operatorname{Tr}(\rho)|\alpha\rangle\langle\beta|$
and
$(\Lambda+\mathcal{B})(\rho)=\Lambda(\rho)+\sum_{\alpha\beta}\operatorname{Tr}\left(\rho
B_{\alpha\beta}\right)|\alpha\rangle\langle\beta|$ satisfies

$d(\Lambda+\mathcal{B},\Lambda)\leq\varepsilon.$ (21)

Based on this lemma, we modify Corollary 5 of Ref. [45] and give a proposition
to support our definitions.

###### Proposition 2

Consider an $n$-qubit noise channel
$\mathcal{N}(\rho)=\sum_{\alpha}E_{\alpha}\rho E_{\alpha}^{\dagger}$, and a
quantum error-correcting code

$\mathcal{C}=\text{span}\\{|\psi_{1}\rangle,|\psi_{2}\rangle,\dots,|\psi_{K}\rangle\\}.$
(22)

We choose the error product set
$\mathcal{E}=\\{E^{\dagger}_{\alpha}E_{\beta}|E_{\alpha},E_{\beta}\text{ are
Kraus operators of }\mathcal{N}\\}$. Denote the cost function Eq. (15) of the
basis states as $C^{\ell_{1}}_{n,K,\mathcal{E}}$. Then the code $\mathcal{C}$
is $\varepsilon$-correctable under $\mathcal{N}$ with $\varepsilon$ bounded by

$\varepsilon\leq K\sqrt{2C^{\ell_{1}}_{n,K,\mathcal{E}}}.$ (23)

Proof  Let
$\lambda_{\alpha\beta}=\sum_{j}\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle/K$.

To satisfy Eq. (20), we set

$\displaystyle B_{\alpha\beta}=$ $\displaystyle\sum_{i\neq
j}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle|\psi_{i}\rangle\langle\psi_{j}|$
(24)
$\displaystyle+\sum_{j}\big{(}\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle-\lambda_{\alpha\beta}\big{)}|\psi_{j}\rangle\langle\psi_{j}|.$

Then

$\displaystyle d(\Lambda+\mathcal{B},\Lambda)$ $\displaystyle\leq
K\|\mathcal{B}\|_{1}^{1/2}$ (25) $\displaystyle\leq
K\Big{(}\sum_{\alpha,\beta}\left\|B_{\alpha\beta}\right\|_{1}\Big{)}^{1/2}$
$\displaystyle\leq K\Big{(}\sum_{\alpha,\beta}\Big{(}\sum_{i\neq
j}|\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle|+$
$\displaystyle\quad\quad\sum_{j}|\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle-\lambda_{\alpha\beta}|\Big{)}\Big{)}^{1/2}$
$\displaystyle=K\sqrt{2C^{\ell_{1}}_{n,K,\mathcal{E}}}.$

According to Lemma 1, the inaccuracy $\varepsilon$ of code $\mathcal{C}$ is
upper bounded by $K\sqrt{2C^{\ell_{1}}_{n,K,\mathcal{E}}}$. $\blacksquare$

In short, given a noise channel $\mathcal{N}$, as long as we minimize the
channel-adaptive cost function to a sufficiently small value, we rigorously
find an approximate channel-adaptive code with small inaccuracy. Similar
bounds for symmetric or asymmetric quantum codes are given as follows.

###### Proposition 3

Consider an $n$-qubit noise channel
$\mathcal{N}(\rho)=\sum_{\alpha}E_{\alpha}\rho E_{\alpha}^{\dagger}$ where
each $E_{\alpha}$ non-trivially acts on no more than $\lfloor(d-1)/2\rfloor$
qubits, and a quantum error-correcting code

$\mathcal{C}=\text{span}\\{|\psi_{1}\rangle,|\psi_{2}\rangle,\dots,|\psi_{K}\rangle\\}.$
(26)

We choose $\mathcal{E}=\\{O_{\alpha}|\operatorname{wt}(O_{\alpha})<d\\}$,
where $O_{\alpha}$s are Pauli tensor products. Denote the cost function Eq.
(15) of the basis states as $C^{\ell_{1}}_{n,K,\mathcal{E}}$, the number of
Kraus operators of $\mathcal{N}$ as $m$. Then the code $\mathcal{C}$ is
$\varepsilon$-correctable under $\mathcal{N}$ with $\varepsilon$ bounded by

$\varepsilon\leq 2^{n/4+d/2}K\sqrt{mC^{\ell_{1}}_{n,K,\mathcal{E}}}.$ (27)

Proof  The proof is given in Appendix A. $\blacksquare$

###### Proposition 4

Consider an $n$-qubit noise channel
$\mathcal{N}(\rho)=\sum_{\alpha}E_{\alpha}\rho E_{\alpha}^{\dagger}$ with each
$E_{\alpha}$ proportional to a Pauli error with $c_{\text{Z}}$-effective
weight smaller than $d_{e}(c_{\text{Z}})/2$, and a quantum error-correcting
code

$\mathcal{C}=\text{span}\\{|\psi_{1}\rangle,|\psi_{2}\rangle,\dots,|\psi_{K}\rangle\\}.$
(28)

We choose
$\mathcal{E}=\\{O_{\alpha}|\operatorname{wt_{e}}(O_{\alpha},c_{\text{Z}})<d_{e}(c_{\text{Z}})\\}$,
where $O_{\alpha}$s are Pauli tensor products. Denote the cost function Eq.
(15) of the basis states as $C^{\ell_{1}}_{n,K,\mathcal{E}}$, the number of
Kraus operators of $\mathcal{N}$ as $m$. Then the code $\mathcal{C}$ is
$\varepsilon$-correctable under $\mathcal{N}$ with $\varepsilon$ bounded by

$\varepsilon\leq K\sqrt{2mC^{\ell_{1}}_{n,K,\mathcal{E}}}.$ (29)

Proof  The proof is given in Appendix B. $\blacksquare$

Note that Propositions 3 and 4 give pretty loose bounds. The true code
inaccuracy, which depends on the particular noise channel, is usually
significantly smaller.

##  4 Algorithm

Variational quantum circuits (VQCs) have been widely used in near-term quantum
algorithms for various tasks [48, 49], such as ground state preparation [50,
51], eigenenergy estimation [52, 53], quantum data compression [54, 55],
quantum circuit compiling [56, 57]. Give a pure product state as input, one
iteratively updates the circuit parameters based on measurement results, and
finally outputs the desired state. In VarQEC, the output states serve as the
basis states of a quantum code, and its encoder is given by the quantum
circuit. The structure of our algorithm is illustrated in Fig. 2.

Figure 2: Schematic illustration of VarQEC. The encoder is trained via mini-
batch learning: we iteratively sample errors from an error set, run the
variational quantum circuit $U(\boldsymbol{\theta})$ and do measurements, then
update $\boldsymbol{\theta}$.

Suppose we have a NISQ device with a hardware connectivity graph $G$. The
vertices denote qubits, and the edges denote adjacent qubit pairs. One can
apply single-qubit rotations to each qubit and two-qubit gates to adjacent
qubits. We aim to find a $K$-dimensional QECC that can detect an error set
$\mathcal{E}=\\{E_{\mu}\\}$, and the encoding circuit should be as shallow as
possible.

Before running the algorithm, we design a multilayered VQC which is hardware-
efficient for the connectivity graph. Denote the number of VQC layers as $L$,
the maximum acceptable number of layers as $L_{\mathrm{max}}$, the evolution
of the VQC as $U(\boldsymbol{\theta})$ where $\boldsymbol{\theta}$ are the
circuit parameters. We start from $L=1$ and sample the initial
$\boldsymbol{\theta}$ randomly. Also, we delicately select
$k=\lceil\log(K)\rceil$ physical qubits to prepare the logical data, where the
logarithm is with respect to base 2. These $k$ qubits should be scattered
instead of concentrated since we hope the remaining qubits are connected to
them by very few edges.

First, we initialize the selected qubits to one of the $K$ binary strings
$|\mathbf{0}\rangle$, $|\mathbf{1}\rangle$, $\dots$, $|\mathbf{K-1}\rangle$,
and initialize the remaining qubits to $|0\rangle^{\otimes(n-k)}$. These
product states span the input code space

$\mathcal{C}_{\mathrm{in}}=\text{span}\\{|\mathbf{0}\rangle|0\rangle^{\otimes(n-k)},\dots,|\mathbf{K-1}\rangle|0\rangle^{\otimes(n-k)}\\}.$
(30)

$\mathcal{C}_{\mathrm{in}}$ is a QECC with distance $d=1$.

The cost functions can be estimated by running specific circuits and doing
measurements. To estimate $\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle$, we
prepare the initial state $|\mathbf{j-1}\rangle|0\rangle^{\otimes(n-k)}$,
evolve the system with the VQC $U(\boldsymbol{\theta})$, then measure the
local observable $E_{\mu}$. If errors $E_{\mu 1}$, $E_{\mu 2}$, $\dots$
commute, they can be measured simultaneously in a single shot. To estimate
$\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}$, we start from
$|\mathbf{j-1}\rangle|0\rangle^{\otimes(n-k)}$, then sequentially evolve the
system with $U(\boldsymbol{\theta})$, $E_{\mu}$, and
$U^{\dagger}(\boldsymbol{\theta})$, then measure the final state in the
computational basis. The measurements are assisted by post-selection: we first
measure the $n-k$ auxiliary qubits, and if the result is $|0\rangle^{n-k}$, we
measure the remaining $k$ qubits. Denote the probability of obtaining the
binary string $|\mathbf{i-1}\rangle|0\rangle^{\otimes(n-k)}$ as $p_{ij}$,
$\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}=\sqrt{p_{ij}}$.
Theoretically, this step will also yield
$\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle$. However, since VarQEC is a NISQ
algorithm, we prefer to use a shallower circuit to estimate cost function
terms whenever possible.

In the above description, we assume the error set $\mathcal{E}$ only consists
of Pauli errors. It does not matter if $\mathcal{E}$ includes non-unitary or
non-Hermitian terms. Adding ancilla qubits or Pauli twirling can handle it.
See Sec. 5.3.1 for a detailed example.

The optimization of $\boldsymbol{\theta}$ consists of two stages. The first
and the main stage is mini-batch learning. After sampling the initial
$\boldsymbol{\theta}$, we minimize $C^{\ell_{2}}_{n,K,\mathcal{E}}$ with mini-
batch gradient descent. The schematic is shown in Fig. 2. Within each
iteration, we sample a subset $\mathcal{E}_{S}\subset\mathcal{E}$, estimate
the corresponding partial $\ell_{2}$-norm cost function

$\displaystyle C^{\ell_{2}}_{n,K,\mathcal{E}_{S}}(\boldsymbol{\theta})\equiv$
$\displaystyle\sum_{E_{\mu}\in\mathcal{E}_{S}}\Big{(}\sum_{1\leq i<j\leq
K}\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}^{2}$ (31)
$\displaystyle+\sum_{j=1}^{K}\big{|}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}^{2}/4\Big{)}$

and its gradient

$\nabla\boldsymbol{\theta}=\frac{\partial
C^{\ell_{2}}_{n,K,\mathcal{E}_{S}}(\boldsymbol{\theta})}{\partial\boldsymbol{\theta}}$
(32)

via measurements, then perform a single gradient descent step with a learning
rate $\eta$:

$\boldsymbol{\theta}\leftarrow\boldsymbol{\theta}-\eta\nabla\boldsymbol{\theta}.$
(33)

The required number of measurements to estimate
$C^{\ell_{2}}_{n,K,\mathcal{E}_{S}}(\boldsymbol{\theta})$ up to additive error
$\epsilon$ is of order $\mathcal{O}(K^{2}|\mathcal{E}_{S}|^{2}/\epsilon^{2})$.
The gradient can be estimated through finite-differencing or by combining the
chain rule and the parameter shift rule [58]. Mini-batch gradient descent
allows for a more robust convergence and avoids being trapped in a local
minimum. We repeat sampling and gradient descent until convergence. The reason
that we minimize $C^{\ell_{2}}_{n,K,\mathcal{E}}$ first is because it
converges much faster than $C^{\ell_{1}}_{n,K,\mathcal{E}}$. In addition,
$C^{\ell_{2}}_{n,K,\mathcal{E}}$ is differentiable but
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ is not.

If the error set $\mathcal{E}$ consists of too many terms, a promising
alternative method is to construct “classical shadows” [59] for each basis
state $|\psi_{j}\rangle$, then use the shadows to estimate the cost functions
classically. The shadow tomography technique can help us implement large-batch
optimization with a smaller measurement overhead.

After adequate mini-batch learning, if $C^{\ell_{2}}_{n,K,\mathcal{E}}$ is
relatively small (e.g., $C^{\ell_{2}}_{n,K,\mathcal{E}}<0.01$), we estimate
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ and fine-tune the parameters
$\boldsymbol{\theta}$ with respect to it since
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ is directly related to the inaccuracy of the
code (see Propositions 2, 3, 4). In this work, we use Powell’s method [60], a
gradient-free optimizer, for fine-tuning. If $C^{\ell_{1}}_{n,K,\mathcal{E}}$
is smaller than an acceptable cost tolerance $C^{\ell_{1}}_{\mathrm{tol}}$, we
stop the optimization and output the final parameters
$\boldsymbol{\theta}_{\mathrm{opt}}$. Throughout this paper, we set the
tolerance as

$C^{\ell_{1}}_{\mathrm{tol}}\equiv 1\times 10^{-6}.$ (34)

In the ideal case, we obtain the optimal parameters

$\boldsymbol{\theta}_{\mathrm{opt}}=\arg\min_{\boldsymbol{\theta}}C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}).$
(35)

The output QECC

$\displaystyle\mathcal{C}_{\mathrm{out}}(\boldsymbol{\theta}_{\mathrm{opt}})=$
$\displaystyle\text{span}\\{$ (36)
$\displaystyle|\psi_{1}\rangle=U(\boldsymbol{\theta}_{\mathrm{opt}})|\mathbf{0}\rangle|0\rangle^{\otimes(n-k)},$
$\displaystyle|\psi_{2}\rangle=U(\boldsymbol{\theta}_{\mathrm{opt}})|\mathbf{1}\rangle|0\rangle^{\otimes(n-k)},$
$\displaystyle\dots,$
$\displaystyle|\psi_{K}\rangle=U(\boldsymbol{\theta}_{\mathrm{opt}})|\mathbf{K-1}\rangle|0\rangle^{\otimes(n-k)}$
$\displaystyle\qquad\quad\\}.$

is the target approximate quantum code with small inaccuracy. The variational
quantum circuit $U(\boldsymbol{\theta}_{\mathrm{opt}})$ serves as the encoding
circuit. Further, we can remove redundant gates from the VQC.

If $C^{\ell_{1}}_{n,K,\mathcal{E}}$ is greater than
$C^{\ell_{1}}_{\mathrm{tol}}$, we increase the circuit depth $L$ and repeat
the optimization steps. If $C^{\ell_{1}}_{n,K,\mathcal{E}}$ is always greater
than the tolerance even when $L=L_{\mathrm{max}}$, we fail to find an eligible
code. The detailed procedure is illustrated in Algorithm 1.

A natural question arises: can a fixed-depth VQC find any $((n,K))_{2}$
quantum code? Haug et al. used the quantum Fisher information matrix to assess
the expressive power of a VQC with a fixed input state $|0\rangle^{\otimes n}$
[61]. We generalize this notion to multiple inputs to assess the expressive
power of a VQC in VarQEC. If a VQC is capable of finding any $((n,K))_{2}$
quantum code, we say it is overparameterized with respect to code parameters
$((n,K))_{2}$. See Appendix C for more details.

When the VQC $U(\boldsymbol{\theta})$ is underparameterized for $((n,K))_{2}$,
the set of reachable output codes forms a low-dimensional submanifold of the
complex Grassmannian $\mathbf{Gr}(K,2^{n})$,

$\\{\mathcal{C}_{\mathrm{out}}(\boldsymbol{\theta})|\boldsymbol{\theta}\\}\subseteq\mathbf{Gr}(K,2^{n}).$
(37)

Input: Error set $\mathcal{E}$, hardware-efficient VQC
$U(\boldsymbol{\theta})$ with $L$ layers, acceptable number of layers
$L_{\mathrm{max}}$, acceptable cost tolerance $C^{\ell_{1}}_{\mathrm{tol}}$.

Output: An approximate quantum code with a hardware-efficient encoder that
detects $\mathcal{E}$.

$L\leftarrow 1$.

while  _$L\leq L_{\mathrm{max}}$ and
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})>C^{\ell_{1}}_{\mathrm{tol}}$_
do

while  _$C^{\ell_{2}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})$ has not
converged_ do

Sample a subset $\mathcal{E}_{S}\subset\mathcal{E}$.

Prepare the $K$ input strings.

Run $U(\boldsymbol{\theta})$, output $\\{|\psi_{j}\rangle\\}$.

Measure observables $E_{\mu}\in\mathcal{E}_{S}$.

Prepare the $K$ input strings.

Run $U^{\dagger}(\boldsymbol{\theta})E_{\mu}U(\boldsymbol{\theta})$ for
$E_{\mu}\in\mathcal{E}_{S}$.

Do projective measurements.

Estimate $C^{\ell_{2}}_{n,K,\mathcal{E}_{S}}(\boldsymbol{\theta})$.

Vary $\boldsymbol{\theta}$, repeat the above steps to estimate
$\partial{C^{\ell_{2}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})}/\partial{\boldsymbol{\theta}}$.

Perform a gradient descent step, update $\boldsymbol{\theta}$.

end while

if  _$C^{\ell_{2}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}) <0.01$_ then

while  _$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})$ has not
converged_ do

Prepare the $K$ input strings.

Run $U(\boldsymbol{\theta})$, output $\\{|\psi_{j}\rangle\\}$.

Measure observables $E_{\mu}\in\mathcal{E}$.

Prepare the $K$ input strings.

Run $U^{\dagger}(\boldsymbol{\theta})E_{\mu}U(\boldsymbol{\theta})$ for
$E_{\mu}\in\mathcal{E}$.

Do projective measurements.

Estimate $C^{\ell_{1}}_{n,K,\mathcal{E}_{S}}(\boldsymbol{\theta})$.

Vary $\boldsymbol{\theta}$, repeat the above steps to estimate
$\partial{C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})}/\partial{\boldsymbol{\theta}}$.

Minimize $C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})$, update
$\boldsymbol{\theta}$.

end while

end if

$L\leftarrow L+1$.

end while

$\boldsymbol{\theta}_{\mathrm{opt}}\leftarrow\boldsymbol{\theta}$.

Return : $\boldsymbol{\theta}_{\mathrm{opt}}$,
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}_{\mathrm{opt}})$.

Algorithm 1 VarQEC

The VarQEC algorithm searches this submanifold for an eligible code. When
$U(\boldsymbol{\theta})$ is overparameterized for $((n,K))_{2}$, it can
explore all relevant directions and the set of reachable output codes is
equivalent to $\mathbf{Gr}(K,2^{n})$, i.e., VarQEC is capable to find
arbitrary $((n,K))_{2}$ quantum code. The required number of periodic bounded
real parameters to overparameterize a VQC is at least $2K(2^{n}-K)$ since the
complex dimension of $\mathbf{Gr}(K,2^{n})$ is $K(2^{n}-K)$.

In Ref. [62], Johnson et al. proposed a related algorithm named QVECTOR, which
samples a random 2-design unitary and optimizes parameterized encoding and
decoding circuits simultaneously to improve the quantum average fidelity.
Compared with QVECTOR, VarQEC can find not only channel-adaptive codes but
also quantum codes with specific code parameters. VarQEC does not need a deep
random circuit, which is a daunting challenge on NISQ devices, to sample a
bunch of input states. We train the encoder without considering the decoder.
The optimization is less likely to be trapped in a local minimum. The cost
functions are estimated by measuring some local observables. We can rigorously
obtain an $\varepsilon$-correctable approximate QECC with arbitrarily small
$\varepsilon$. The noise models in our methods are also flexible and can be
artificially assigned.

##  5 Results

###  5.1 Symmetric codes

We verify the validity of our algorithm by rediscovering some symmetric codes
with well-known code parameters. The cost functions are defined in Eqs. (15),
(16). For code parameters $((n,K,d))_{2}$, the total number of Pauli errors
$O_{\alpha}$ to consider is

$|\\{O_{\alpha}\\}|=\sum_{j=0}^{d-1}\left(\begin{array}[]{c}n\\\
j\end{array}\right)3^{j}.$ (38)

Without loss of generality, we use the complete bipartite connectivity graph:
denote the qubits selected for the input as $\\{Q_{0},Q_{1},\dots,Q_{k-1}\\}$
($k=\lceil\log(K)\rceil$), the unselected qubits as
$\\{Q_{k},Q_{k+1},\dots,Q_{n-1}\\}$, the graph consists of $k(n-k)$ edges that
connect every selected qubit and every unselected qubit, qubits in the same
set are not directly connected. For such graphs, the initial logical data can
spread to each qubit rapidly since the graph diameter is only $2$. The
variational quantum circuit has alternating layers of single-qubit rotations
$R_{x}$-$R_{z}$ acting on all qubits and Ising-type interactions $R_{zz}$
acting on adjacent qubits. Denote the number of layers as $L$. The VQC
evolution is of the form

$U(\boldsymbol{\theta})=U_{E}(\boldsymbol{\theta}_{E})\prod_{l=1}^{L}U_{l}(\boldsymbol{\theta}_{l}),$
(39)

where $\boldsymbol{\theta}_{l}$ and $\boldsymbol{\theta}_{E}$ are elements in
$\boldsymbol{\theta}$, $U_{l}(\boldsymbol{\theta}_{l})$ denotes the $l$-th
layer evolution, $U_{E}(\boldsymbol{\theta}_{E})$ denotes the rightmost
$R_{x}$-$R_{z}$ rotations which are used to search the manifold of locally
equivalent quantum codes. Since $R_{z}$ and $R_{zz}$ gates in the last layer
commute, and $R_{z}$-$R_{x}$-$R_{z}$ rotations can realize arbitrary single-
qubit unitary, locally equivalent QECCs can be found by the same VQC. In
principle, any $n$-qubit unitary evolution can be realized by this ansatz with
a sufficiently large number of layers since $\\{R_{x},R_{z},R_{zz}\\}$ is a
universal quantum gate set. The connectivity graph and the periodic-structured
VQC ansatz for $n=5,k=2$ are shown in Fig. 3(a,b). In general, with the
increase of $L$, the achievable quantum codes form a higher dimensional
submanifold of $\mathbf{Gr}(K,2^{n})$, as shown in Fig. 3(c). When the VQC is
overparameterized ($L$ is no less than a critical number $L_{\mathrm{crit}}$)
for code parameters $((n,K))_{2}$, VarQEC can explore the whole
$\mathbf{Gr}(K,2^{n})$ manifold.

An alternative variational circuit for finding additive quantum codes is
discussed in Appendix D.

Figure 3: Schematic of a connectivity graph, the periodic-structured
variational ansatz, and the achievable quantum codes. (a) The bipartite
connectivity graph with five physical qubits. Gray lines connect adjacent
qubits. $\\{Q_{0},Q_{1}\\}$ are the selected qubits to prepare the logical
data. (b) The corresponding variational quantum circuit (VQC) with $L$ layers.
Within each layer, we apply $R_{x}$-$R_{z}$ rotations to each qubit and apply
$R_{zz}$ gates to adjacent qubits. (c) With the increase of $L$, VarQEC is
capable to find quantum codes in a higher-dimensional manifold until
overparameterization ($L=L_{\mathrm{crit}}$).

We apply our algorithm to search for $((n,K,d))_{2}$ codes where the code
length $n$ ranges from $3$ to $12$, the code dimension $K$ ranges from $2$ to
$8$, the code distance $d$ ranges from $2$ to $4$. Fig. 4 shows
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}_{\mathrm{opt}})$ as a
function of code parameters $n$, $K$, $d$. We rediscover quantum codes with
parameters

$\displaystyle((4,4,2))_{2},((5,6,2))_{2},$ (40)
$\displaystyle((5,2,3))_{2},((6,2,3))_{2},$
$\displaystyle((7,2,3))_{2},((8,8,3))_{2},$
$\displaystyle((9,8,3))_{2},((10,4,4))_{2},$ $\displaystyle((11,4,4))_{2}.$

The $((5,2,3))_{2}$ and $((8,8,3))_{2}$ codes are non-degenerate, the
$((6,2,3))_{2}$ codes are degenerate, and both cases are possible for
$((7,2,3))_{2}$. There is an obvious phase transition between achievable and
(probably) non-achievable code parameters. Further, we fix $d=3$ and
rediscover larger codes with parameters

$\displaystyle((10,2^{4},3))_{2},((11,2^{5},3))_{2},$ (41)
$\displaystyle((12,2^{6},3))_{2},((13,2^{7},3))_{2},$
$\displaystyle((14,2^{8},3))_{2}.$

All these codes can be found by a shallow VQC, e.g., a $5$-layer VQC can
encode $((5,2,3))_{2}$, $((12,2^{6},3))_{2}$, $((14,2^{8},3))_{2}$; a
$4$-layer VQC can encode $((6,2,3))_{2}$, $((8,8,3))_{2}$; a $3$-layer VQC
suffices to encode $((7,2,3))_{2}$. In our experiments, either
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}_{\mathrm{opt}})<1\times
10^{-6}$ or
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}_{\mathrm{opt}})\geq 1$
holds. Fig. 5 shows some cost curves at the mini-batch learning stage. Within
each iteration, we sample $20\%$ of $\\{O_{\alpha}\\}$ as the batch and
perform a stochastic gradient descent with learning rate $\eta=1\times
10^{-2}$.

Figure 4: Minimum cost function
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta}_{\mathrm{opt}})$ for
different code length $n$, code dimension $K$, and code distance $d$. (a)
$n=3$. (b)$n=4$. (c)$n=5$. (d)$n=6$. (e)$n=7$. (f)$n=8$. (g)$n=9$. (h)$n=10$.
(i)$n=11$. (j)$n=12$.

Figure 5: Learning curves of VarQEC for finding symmetric codes with
achievable code parameters (a-h)$((5,2,3))_{2}$, $((6,2,3))_{2}$,
$((7,2,3))_{2}$, $((8,8,3))_{2}$, $((11,2^{5},3))_{2}$, $((12,2^{6},3))_{2}$,
$((13,2^{7},3))_{2}$, $((14,2^{8},3))_{2}$, and (probably) non-achievable code
parameters (i) from bottom to top: $((7,3,3))_{2}$,
$((4,2,3))_{2}$,$((9,2^{4},3))_{2}$,$((10,2^{5},3))_{2}$,$((11,2^{6},3))_{2}$,$((12,2^{7},3))_{2}$,$((13,2^{8},3))_{2}$.

In the following, we verify the local equivalence (LE) between two quantum
codes with $K$-dimensional projectors $P_{c}$ and $P^{\prime}_{c}$ by sampling
permutations of qubits $\Pi_{q}$ and numerically minimizing the LE-cost
function

$C_{LE}=|\operatorname{Tr}(U(\boldsymbol{\phi})\Pi_{q}P_{c}\Pi^{-1}_{q}U^{\dagger}(\boldsymbol{\phi})P^{\prime}_{c})-K|^{2},$
(42)

where

$\displaystyle U(\boldsymbol{\phi})=$
$\displaystyle\exp({-i\sum_{j=1}^{n}\phi_{j,1}Z_{j}})\exp({-i\sum_{j=1}^{n}\phi_{j,2}X_{j}})$
(43) $\displaystyle\cdot\exp({-i\sum_{j=1}^{n}\phi_{j,3}Z_{j}})$

is a product of single-qubit unitaries with $3n$ parameters
$\boldsymbol{\phi}$. If there exist $\Pi_{q}$ and $\boldsymbol{\phi}$ such
that $C_{LE}<1\times 10^{-10}$, we say $P_{c}$ and $P^{\prime}_{c}$ are
(locally) equivalent.

The minimum code length that protects a logical qubit against arbitrary one-
qubit errors is $n=5$. The $((5,2,3))_{2}$ code we rediscover is equivalent to
the perfect code devised in Ref. [63]. This code is unique and translational
invariant. The $((5,6,2))_{2}$ code we rediscover is equivalent to the
original non-additive CWS code devised in Ref. [64]. For parameters
$((6,2,3))_{2}$, we sample different initial VQC parameters
$\boldsymbol{\theta}$ and find a mass of non-additive codes that are not
mutually equivalent. This is consistent with our observation that an infinite
family of non-equivalent $((6,2,3))_{2}$ codes exist. For parameters
$((7,2,3))_{2}$, we find non-equivalent quantum codes and some of them are not
equivalent to CWS codes. See Appendix E for more discussions on
$((6,2,3))_{2}$ and $((7,2,3))_{2}$. The $((8,8,3))_{2}$ code we rediscover is
equivalent to the additive code stabilized by

$\begin{array}[]{llllllllll}g_{1}&=&X&X&X&X&X&X&X&X\\\
g_{2}&=&Z&Z&Z&Z&Z&Z&Z&Z\\\ g_{3}&=&I&X&Y&Z&Z&Y&X&I\\\
g_{4}&=&Z&Y&Z&Y&X&I&X&I\\\ g_{5}&=&X&Y&Y&X&I&Z&Z&I\end{array}$ (44)

up to permutation of qubits.

It is an open question whether a $((7,3,3))_{2}$ QECC exists. We have not yet
found such a code with VarQEC, even if using an overparameterized VQC ($L=31$)
that is capable of finding any $((7,3))_{2}$ quantum code and sampling 20000
optimization starting points. This strongly indicates that a quantum code with
parameters $((7,3,3))_{2}$ is nonexistent.

###  5.2 Asymmetric codes

In quantum experiments, the decoherence time of a physical qubit is mainly
influenced by two factors: the relaxation time $T_{1}$ and the dephasing time
$T_{2}$. Relaxation leads to all Pauli errors, whereas dephasing only leads to
phase-flips (Pauli-$Z$ errors). Denote the probabilities of $X$, $Y$, and $Z$
errors as $p_{x}$, $p_{y}$, $p_{z}$ respectively. Usually, $p_{x}=p_{y}\neq
p_{z}$. The asymmetry between $X/Y$ and $Z$ errors motivates people to
construct asymmetric QECCs that handle them differently [65, 66]. Asymmetric
codes are more resource-efficient since they can detect/correct more
Pauli-$X$/$Y$ errors than Pauli-$Z$ errors or vice versa in response to
demand. Researchers have extended several constructions from symmetric codes
to asymmetric codes [66, 67, 68, 69, 70, 71, 72]. Note that the classification
of symmetric and asymmetric codes depends on the error detecting/correcting
capability instead of the code construction method.

For a system with $X/Y$-error probabilities $p_{x}=p_{y}$ and $Z$-error
probability $p_{z}$. We set the bias parameter $c_{\text{Z}}$ as

$c_{\text{Z}}=\frac{\log p_{z}}{\log p_{x}}.$ (45)

such that $p_{z}=p_{x}^{c_{\text{Z}}}$.

In most scenarios, dephasing is dominating and phase-flip errors are more
prevalent than $X/Y$ errors. Accordingly, $0<c_{\text{Z}}<1$. First, we fix
$c_{\text{Z}}=1/2$ (i.e., $p_{z}\approx p_{x}^{1/2}$) and apply VarQEC to find
$((n,K,d_{e}(1/2)))_{2}$ codes that encodes one logical qubit ($K=2$) or one
logical qutrit ($K=3$). We discover asymmetric codes

$\displaystyle((6,2,d_{e}(\frac{1}{2})=2))_{2},$ (46)
$\displaystyle((7,3,d_{e}(\frac{1}{2})=2))_{2}.$

They can detect more $Z$ errors than $X/Y$ errors, specifically, detect the
error set

$\displaystyle\mathcal{E}_{1/2}^{\\{2\\}}=\\{I\\}\cup\\{$ $\displaystyle
X_{j},Y_{j},Z_{j},X_{i}Z_{j},Y_{i}Z_{j},Z_{i}Z_{j}Z_{k}\\}$ (47)

with indices $i,j,k\in[1,n]$.

We now consider the opposite situation where $X/Y$ errors are more prevalent
than $Z$. In the extreme case, $T_{2}\to+\infty$, the only source of
decoherence is qubit relaxation. This process at finite temperature is modeled
by the generalized amplitude damping channel. Its Kraus representation has
operators

$\displaystyle A_{0}=$ $\displaystyle\sqrt{p}\left(\begin{array}[]{cc}1&0\\\
0&\sqrt{1-\gamma}\end{array}\right)$ (50) $\displaystyle=$
$\displaystyle\sqrt{p}I-\frac{\sqrt{p}\gamma}{4}(I-Z)+\mathcal{O}\left(\sqrt{p}\gamma^{2}\right),$
$\displaystyle A_{1}=$
$\displaystyle\sqrt{p}\left(\begin{array}[]{cc}0&\sqrt{\gamma}\\\
0&0\end{array}\right)=\frac{\sqrt{p\gamma}}{2}(X+iY),$ (53)
$\displaystyle\quad A_{2}=$
$\displaystyle\sqrt{1-p}\left(\begin{array}[]{cc}\sqrt{1-\gamma}&0\\\
0&1\end{array}\right)$ (56) $\displaystyle=$
$\displaystyle\sqrt{1-p}I-\frac{\sqrt{1-p}\gamma}{4}(I+Z)$
$\displaystyle+\mathcal{O}\left(\sqrt{1-p}\gamma^{2}\right),$ $\displaystyle
A_{3}=$ $\displaystyle\sqrt{1-p}\left(\begin{array}[]{cc}0&0\\\
\sqrt{\gamma}&0\end{array}\right)=\frac{\sqrt{\gamma-p\gamma}}{2}(X-iY),$ (59)

where $\gamma$ is the damping rate, $p$ is a constant determined by the
temperature. $A_{0}$ and $A_{2}$ introduce Pauli-$Z$ errors of order
$\mathcal{O}(\gamma)$, $A_{1}$ and $A_{3}$ introduce Pauli-$X$ and -$Y$ errors
of order $\mathcal{O}(\sqrt{\gamma})$. When $\gamma$ is small,
$c_{\text{Z}}=\log p_{z}/\log p_{x}\approx 2$.

Now we fix $c_{\text{Z}}=2$ and apply VarQEC to find asymmetric codes with
$2$-effective distance $3$. We rediscover codes with parameters

$\displaystyle((5,2,d_{e}(2)=3))_{2},$ (60)
$\displaystyle((6,4,d_{e}(2)=3))_{2},$ $\displaystyle((7,8,d_{e}(2)=3))_{2}.$

These codes were introduced in Ref. [42]. They can detect more $X/Y$ errors
than $Z$ errors, i.e., the error set

$\mathcal{E}_{2}^{\\{3\\}}=\\{I\\}\cup\left\\{X_{j},Y_{j},Z_{j},X_{i}X_{j},X_{i}Y_{j},Y_{i}Y_{j}\right\\}$
(61)

with indices $i,j\in[1,n]$.

Furthermore, we find new codes with $2$-effective distance $4$ with $K=2$ or
$K=3$, i.e.,

$\displaystyle((6,2,d_{e}(2)=4))_{2},$ (62)
$\displaystyle((8,3,d_{e}(2)=4))_{2}.$

Some $((6,2,d_{e}(2)=4))_{2}$ codes are equivalent to the additive
$((6,2,3))_{2}$ code stabilized by

$\begin{array}[]{llllllllllllll}g_{1}&=&X&I&X&Y&Z&X\\\ g_{2}&=&Z&I&I&I&I&Z\\\
g_{3}&=&I&X&X&X&X&I\\\ g_{4}&=&I&Z&I&Y&X&Z\\\ g_{5}&=&I&I&Z&X&Y&Z.\end{array}$
(63)

They can detect the error set

$\displaystyle\mathcal{E}_{2}^{\\{4\\}}=\mathcal{E}_{2}^{\\{3\\}}\cup\\{$
$\displaystyle X_{i}Z_{j},Y_{i}Z_{j},X_{i}X_{j}X_{k},X_{i}X_{j}Y_{k},$ (64)
$\displaystyle X_{i}Y_{j}Y_{k},Y_{i}Y_{j}Y_{k}\\}.$

with indices $i,j,k\in[1,n]$. For the generalized amplitude damping channel,
$((6,2,d_{e}(2)=4))_{2}$ and $((8,3,d_{e}(2)=4))_{2}$ can detect up to three
$A_{1}$/$A_{3}$ errors or one $A_{0}$/$A_{2}$ error, and correct one
$A_{1}$/$A_{3}$ error. Assisted by post-selection [73], these codes hold the
promise to achieve lower logical error rate than codes with $d_{e}(2)=3$.

###  5.3 Channel-adaptive codes

In the previous sections, we have only discussed uncorrelated errors,
symmetric or asymmetric. This section considers quantum channels with
correlated noise. We apply VarQEC to find the corresponding channel-adaptive
codes.

Correlated errors are ubiquitous in quantum computing experiments. When two
adjacent qubits are not sufficiently separated, the errors occurring on them
can be highly correlated [22]. These spatially correlated errors invalidate
many well-known quantum codes and dim the hope of fault-tolerant quantum
computing. Suppose we ignore the exact connectivity graph and the noise type.
In that case, we need at least $11$ physical qubits to protect one qubit of
information from general correlated errors (i.e., the double error-correcting
$((11,2,5))_{2}$ code) [74]. Even so, the encoding isometry may not be
hardware-efficient. In the following, we investigate two correlated noise
channels in detail and introduce channel-adaptive codes discovered by VarQEC.

####  5.3.1 Nearest-neighbor collective amplitude damping

The first testbed is the nearest-neighbor collective amplitude damping
channel. Suppose we have $n$ qubits in a ring, as shown in Fig. 6. Every two
neighboring qubits collectively interact with a single environment and exhibit
collective dynamics of amplitude damping [75, 76]. The corresponding Kraus
operators are

$\displaystyle K_{0}=$
$\displaystyle\sqrt{\frac{\gamma_{01}}{2}}|00\rangle(\langle 01|+\langle 10|)$
(65) $\displaystyle+\sqrt{\frac{\gamma_{12}}{2}}(|01\rangle+|10\rangle)\langle
11|,$ $\displaystyle K_{1}=$ $\displaystyle\sqrt{\gamma_{02}}|00\rangle\langle
11|,$ $\displaystyle K_{2}=$
$\displaystyle\sqrt{\frac{1-\gamma_{01}}{4}}(|01\rangle+|10\rangle)(\langle
01|+\langle 10|)$
$\displaystyle+\sqrt{1-\gamma_{02}-\gamma_{12}}|11\rangle\langle 11|$
$\displaystyle+\frac{1}{2}(|01\rangle-|10\rangle)(\langle 01|-\langle 10|)$
$\displaystyle+|00\rangle\langle 00|,$

where $\gamma_{01}$, $\gamma_{02}$, $\gamma_{12}$ are damping rates. For a
short decay time $\tau$, $\gamma_{01}$ and $\gamma_{12}$ are of order
$\mathcal{O}(\tau)$, $\gamma_{02}$ is of order $\mathcal{O}(\tau^{2})$. Each
error acts on two neighbouring qubits $Q_{j}$-$Q_{j+1}$. To find quantum codes
that approximately correct one nearest-neighbor collective amplitude damping
error, we expand the above Kraus operators with respect to $\tau$, abandon
trivial/high-order terms and obtain

$\displaystyle K^{\prime}_{0}$
$\displaystyle=\frac{1}{\sqrt{2}}|00\rangle(\langle 01|+\langle
10|)+\frac{1}{\sqrt{2}}(|01\rangle+|10\rangle)\langle 11|,$ (66)
$\displaystyle K^{\prime}_{1}$ $\displaystyle=|00\rangle\langle 11|,$
$\displaystyle K^{\prime}_{2}$
$\displaystyle=\frac{1}{2}(|01\rangle+|10\rangle)(\langle 01|+\langle
10|)+|11\rangle\langle 11|.$

Each $K^{\prime}_{0}$ contributes one factor of $\sqrt{\tau}$, each
$K^{\prime}_{1}$/$K^{\prime}_{2}$ contributes one factor of $\tau$. Suppose
$E_{\alpha}$ and $E_{\beta}$ are products of the identity, $K^{\prime}_{0}$,
$K^{\prime}_{1}$, and $K^{\prime}_{2}$. The target error set (in VarQEC)

$\mathcal{E}=\left\\{E^{\dagger}_{\alpha}E_{\beta}\right\\}$ (67)

consists of terms with total order less than $\tau^{3/2}$.

Figure 6: Schematic of nearest-neighbor collective amplitude damping. (a)
Qubits in a ring, neighboring two qubits collectively interact with a single
environment. (b) Decay processes.

Note that here, some error products $E^{\dagger}_{\alpha}E_{\beta}$ are non-
unitary and non-Hermitian. To compute cost functions
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ and $C^{\ell_{2}}_{n,K,\mathcal{E}}$ (Eqs.
(15), (16)), we need to estimate

$\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}\ |\psi_{j}\rangle$ (68)

and

$\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}\
|\psi_{j}\rangle\big{|}$ (69)

for various $i,j,\alpha,\beta$ ($i\neq j$).

$\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}\ |\psi_{j}\rangle$ is a complex
number that can be obtained as follows: we prepare the state
$|\psi_{j}\rangle$ and measure two Hermitian observables
$(E^{\dagger}_{\alpha}E_{\beta}+E^{\dagger}_{\beta}E_{\alpha})/2$ and
$(E^{\dagger}_{\alpha}E_{\beta}-E^{\dagger}_{\beta}E_{\alpha})/2i$. The first
expectation value gives the real part of
$\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}\ |\psi_{j}\rangle$ and the
second expectation value gives its imaginary part.

We estimate $\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}\
|\psi_{j}\rangle\big{|}$ with $i\neq j$ using POVMs. Specifically, we prepare
the state $|\psi_{j}\rangle$, add an ancilla qubit and implement the operation

$\displaystyle\Lambda_{\alpha\beta}(|\psi_{j}\rangle)=$ $\displaystyle
E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\langle\psi_{j}|E^{\dagger}_{\beta}E_{\alpha}\otimes|0\rangle\langle
0|_{\text{anc}}$ (70)
$\displaystyle+E_{\text{aux}}|\psi_{j}\rangle\langle\psi_{j}|E^{\dagger}_{\text{aux}}\otimes|1\rangle\langle
1|_{\text{anc}},$

where $E_{\text{aux}}$ is an auxiliary Kraus operator such that
$E^{\dagger}_{\beta}E_{\alpha}E^{\dagger}_{\alpha}E_{\beta}+E^{\dagger}_{\text{aux}}E_{\text{aux}}=I$.
Then we measure the ancilla qubit in the computational basis and post-select
the cases of $|0\rangle$. Measuring the ancilla qubit in the $|0\rangle$ state
indicates that the error $E^{\dagger}_{\alpha}E_{\beta}$ has occurred. The
corresponding probability is

$p_{0}=\operatorname{Tr}(E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\langle\psi_{j}|E^{\dagger}_{\beta}E_{\alpha})$
(71)

and the corresponding state is

$\frac{E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\langle\psi_{j}|E^{\dagger}_{\beta}E_{\alpha}}{p_{0}}.$
(72)

For these postselected states, we apply the inverse of the VQC and do
projective measurements. The conditional probability of obtaining the binary
string $|\mathbf{i-1}\rangle|0\rangle^{\otimes(n-k)}$ is

$\displaystyle p_{ij}=$
$\displaystyle\frac{\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\big{|}^{2}}{p_{0}}.$
(73)

Therefore, we can estimate
$\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\big{|}$
by $\sqrt{p_{ij}p_{0}}$.

Suppose 0 or 1 error occurs during a short decay time $\tau$, we apply VarQEC
and find quantum codes with length and dimension

$\displaystyle((4,3))_{2},((5,2))_{2}$ (74)
$\displaystyle((6,5))_{2},((7,8))_{2}$
$\displaystyle((8,9))_{2},((9,16))_{2}.$

These codes can reduce the error from $\mathcal{O}(\sqrt{\tau})$ to
$\mathcal{O}(\tau)$.

####  5.3.2 Nearest-neighbor collective phase-flips

The second noise channel we consider is a combined channel of nearest-neighbor
collective phase-flips and single-qubit errors. The channel consists of two
stages. In the first stage, a local depolarizing error with noise rate $p$

$\mathcal{N}_{\mathrm{DP}_{j}}(\rho)=(1-\frac{3p}{4})\rho+\frac{p}{4}(X_{j}\rho
X_{j}+Y_{j}\rho Y_{j}+Z_{j}\rho Z_{j})$ (75)

occurs on each qubit. In other words, Pauli errors $X,Y,Z$ occur on each qubit
with probability $p/4$. Different local errors act independently. We denote
the corresponding global noise channel as

$\mathcal{N}_{1}=\prod_{j=1}^{n}\mathcal{N}_{\mathrm{DP}_{j}}$ (76)

In the second stage, nearest-neighbor collective phase-flip errors $ZZ$ with
noise rate $p_{zz}$

$\mathcal{N}_{\mathrm{Z}_{i}\mathrm{Z}_{j}}(\rho)=(1-p)\rho+p_{\mathrm{zz}}Z_{i}Z_{j}\rho
Z_{i}Z_{j}$ (77)

occur on adjacent qubit pairs $Q_{i}$-$Q_{j}$. We denote the corresponding
global noise channel as

$\mathcal{N}_{2}=\prod_{\langle
i,j\rangle}\mathcal{N}_{\mathrm{Z}_{i}\mathrm{Z}_{j}}.$ (78)

The overall process is

$\mathcal{N}=\mathcal{N}_{2}\circ\mathcal{N}_{1}.$ (79)

Directly applying VarQEC to $\mathcal{N}$ is not resource efficient since the
Kraus representation of $\mathcal{N}$ consists of $\mathcal{O}(\exp(n))$
operators. For practical purposes, we apply our algorithm to the following
channel instead,

$\displaystyle\mathcal{N}^{\prime}(\rho)=$
$\displaystyle(1-\sum_{j}\frac{3p}{4}-\sum_{\langle
i,j\rangle}p_{\mathrm{zz}})\rho$ (80)
$\displaystyle+\sum_{j}\frac{p}{4}(X_{j}\rho X_{j}+Y_{j}\rho Y_{j}+Z_{j}\rho
Z_{j})$ $\displaystyle+\sum_{\langle i,j\rangle}p_{\mathrm{zz}}Z_{i}Z_{j}\rho
Z_{i}Z_{j}.$

The second term takes summation over all qubits. The last term takes summation
over all adjacent qubit pairs $\langle i,j\rangle$. Its Kraus operators are

$\displaystyle\mathcal{E}^{\prime}=\Big{\\{}$
$\displaystyle\sqrt{(1-\sum_{j}\frac{3p}{4}-\sum_{\langle
i,j\rangle}p_{\mathrm{zz}})}I,$ (81)
$\displaystyle\sqrt{\frac{p}{4}}X_{j},\sqrt{\frac{p}{4}}Y_{j},\sqrt{\frac{p}{4}}Z_{j},\sqrt{p_{\mathrm{zz}}}Z_{i}Z_{j}\Big{\\}}.$

where qubit-$i$ and qubit-$j$ are adjacent. $\mathcal{N}^{\prime}$ is the
first-order approximation of $\mathcal{N}$ with respect to the error
parameters $p$ and $p_{zz}$. The Kraus representation of
$\mathcal{N}^{\prime}$ consists of only poly($n$) operators. $\mathcal{N}$ and
$\mathcal{N}^{\prime}$ are equivalent in the zero-noise limit,

$\lim_{p,p_{\mathrm{zz}}\rightarrow 0}\mathcal{N}^{\prime}=\mathcal{N}.$ (82)

Figure 7: Hardware connectivity graphs with $6\sim 9$ vertices (physical
qubits). Filled circles represent the initial $k$ qubits to prepare the
logical data. For these graphs, there exist channel-adaptive codes to protect
$k$ qubit(s) of information from general one-qubit errors and nearest-neighbor
collective phase-flips. The code length $n$, the code dimension $K$, and the
number of VQC layers $L$ are (a) $n=6,K=2,L=5$; (b) $n=6,K=2,L=6$; (c)
$n=7,K=2,L=2$; (d) $n=7,K=2,L=2$; (e) $n=8,K=4,L=4$; (f) $n=8,K=4,L=4$; (g)
$n=9,K=4,L=3$; (h) $n=9,K=4,L=2$.

Suppose for $\mathcal{N}^{\prime}$, we find an $\varepsilon$-correctable
approximate code with $\varepsilon\ll 1$. Namely, with appropriate recovery
$\mathcal{R}$, the entanglement fidelity is

$F_{e}(\mathcal{R}\mathcal{N}^{\prime})\geq 1-\varepsilon.$ (83)

Then for the original noise channel $\mathcal{N}$, the entanglement fidelity
naturally has the form

$\displaystyle F_{e}(\mathcal{R}\mathcal{N})=$ $\displaystyle
1-\mathcal{O}(\varepsilon p)-\mathcal{O}(\varepsilon p_{\mathrm{zz}})$ (84)
$\displaystyle-\mathcal{O}(p^{2})-\mathcal{O}(p_{\mathrm{zz}}^{2}).$

The QECC can push the first-order errors down to an extremely small level. To
find quantum codes that correct multiple errors, we can choose a higher-order
approximation and similarly implement VarQEC.

Given a connectivity graph $G$ with edge number $|E(G)|$ and maximum vertex
degree $\Delta(G)$. In the following, we set

$p_{\mathrm{zz}}=0.99/(3n+|E(G)|),\quad p=4p_{\mathrm{zz}}.$ (85)

For a generic input state $\rho$, the probability of receiving the same state
after going through the noise channel is about $\sim 0.01$. The target error
list to detect in VarQEC is

$\mathcal{E}=\left\\{E^{\dagger}_{\alpha}E_{\beta}|E_{\alpha},E_{\beta}\in\mathcal{E}^{\prime}\right\\}.$
(86)

Still, we use the VQC ansatz with alternating layers of single-qubit rotations
$R_{x}$-$R_{z}$ acting on all qubits and Ising-type interactions $R_{zz}$
acting on adjacent qubits. The circuit depth of a VQC with $L$ layers is of
order $\mathcal{O}(L\Delta(G))$.

After adequate optimization, we find approximate channel-adaptive codes for
$\mathcal{N}=\mathcal{N}_{2}\circ\mathcal{N}_{1}$ with hardware connectivity
graphs shown in Fig. 7. The codes for graphs (a,b,h) are degenerate, and the
others are non-degenerate. Six physical qubits suffice to encode one logical
qubit, and eight physical qubits suffice to encode two logical qubits.

Note that up to a local unitary transformation, these codes can correct an
arbitrary single-qubit error followed by an adjacent $U\otimes U$ error for
any fixed $U\in\operatorname{U}(2)$ with eigenvalues $\\{-1,1\\}$.

We investigated the codes for graphs (c,d) in more detail. Clearly, they have
code parameters $((7,2,3))_{2}$. We calculate their quantum weight enumerators
[77], which were defined by

$A(z)=\sum_{j=0}^{n}A_{j}z^{j},\quad B(z)=\sum_{j=0}^{n}B_{j}z^{j}$ (87)

with coefficients

$A_{j}=\frac{1}{K^{2}}\sum_{\operatorname{wt}(O_{\alpha})=j}\operatorname{Tr}(O_{\alpha}P_{c})\operatorname{Tr}(O_{\alpha}^{\dagger}P_{c}),$
(88)
$B_{j}=\frac{1}{K}\sum_{\operatorname{wt}(O_{\alpha})=j}\operatorname{Tr}(O_{\alpha}P_{c}O_{\alpha}^{\dagger}P_{c}).\mkern
44.0mu$ (89)

These two codes are locally equivalent and therefore have the same weight
enumerators, i.e.,

$A(z)=1+2z^{3}+9z^{4}+24z^{5}+22z^{6}+6z^{7},\mkern 26.0mu$ (90)
$B(z)=1+17z^{3}+45z^{4}+78z^{5}+82z^{6}+33z^{7}.$ (91)

Further, we verified that they are locally equivalent to a non-degenerate
additive code stabilized by

$\begin{array}[]{llllllllllllll}g_{1}&=&X&I&Z&X&X&I&X\\\
g_{2}&=&Z&I&I&X&X&X&Z\\\ g_{3}&=&I&X&Z&X&Z&Z&Z\\\ g_{4}&=&I&Z&Z&I&Z&Y&Z\\\
g_{5}&=&I&I&Y&X&Z&I&X\\\ g_{6}&=&I&I&I&Z&Y&Y&X\end{array}$ (92)

up to permutation of qubits. This additive code can correct arbitrary single-
qubit errors and 2-qubit collective phase-flips occurring on any qubit pairs,
i.e., the error set

$\displaystyle\mathcal{E}=\Big{\\{}I,X_{j},Y_{j},Z_{j},Z_{i}Z_{j}\Big{\\}}.$
(93)

with indices $i,j\in[1,n]$.

According to the quantum Hamming bound, for one logical qubit, no non-
degenerate quantum code with code length $n<7$ can correct arbitrary single-
qubit errors as well as 2-qubit collective phase-flips since

$2^{n}\geq K(3n+\frac{n(n-1)}{2})$ (94)

with $K=2$ only holds when $n\geq 7$.

Two $((7,2,3))_{2}$ stabilizer codes were investigated in detail. One is the
famous Steane code [14] based on the Calderbank-Shor-Steane (CSS)
construction. The other is a non-CSS code found by numerical greedy search,
called the bare code [27]. Their weight enumerators are as follows,

$\displaystyle A^{\\{\mathrm{Steane}\\}}(z)$
$\displaystyle=1+21z^{4}+42z^{6},$ $\displaystyle
B^{\\{\mathrm{Steane}\\}}(z)$ $\displaystyle=1+21z^{3}+21z^{4}$
$\displaystyle\quad+126z^{5}+42z^{6}+45z^{7},$ (95)

and

$\displaystyle A^{\\{\mathrm{bare}\\}}(z)=$ $\displaystyle
1+5z^{2}+11z^{4}+47z^{6},$ $\displaystyle B^{\\{\mathrm{bare}\\}}(z)=$
$\displaystyle 1+5z^{2}+36z^{3}$ $\displaystyle\quad+11z^{4}+96z^{5}+47z^{6}.$
(96)

QECCs with different weight enumerators are not locally and translationally
equivalent. Our code is different from the Steane and the bare $((7,2,3))_{2}$
codes. See Appendix F more weight enumerators.

The Steane and the bare codes cannot correct nearest-neighbor collective
phase-flips. For the combined channel of nearest-neighbor collective phase-
flips with noise rate $p_{\text{zz}}$ and single-qubit errors with noise rate
$p$, the entanglement fidelity of our code is of the form

$\displaystyle F_{e}(\mathcal{R}\mathcal{N})=$ $\displaystyle
1-\mathcal{O}(p^{2})-\mathcal{O}(p_{\mathrm{zz}}^{2})$ (97)

whereas the entanglement fidelity of the Steane and the bare codes is of the
form

$\displaystyle F_{e}(\mathcal{R}\mathcal{N})=$ $\displaystyle
1-\mathcal{O}(p_{\mathrm{zz}})-\mathcal{O}(p^{2})-\mathcal{O}(p_{\mathrm{zz}}^{2}).$
(98)

Although our code was written in a quantum simulator that has not been open-
sourced yet, we rewrote some example implementations with Qiskit, an open-
source software development kit. They are available on GitHub [78].

##  6 Noise Resilience

Although the previously introduced results are obtained by numerical
simulation, VarQEC is a hybrid quantum-classical algorithm meant to be run on
NISQ devices where quantum gates are inevitably noisy. In this section, we
demonstrate that VarQEC is pretty resilient to random gate errors. As long as
the error rate $p_{\mathrm{gate}}$ is below a reasonable threshold, VarQEC can
find an efficient encoding circuit that prepares the correct code. This
resilience is essentially analogous to the noise resilience in variational
quantum compiling [56].

We start from the simplest noise model, global depolarizing, and introduce the
following theorem.

###### Theorem 5

Suppose the variational quantum circuit in VarQEC is accompanied by global
depolarizing noise acting continuously throughout the circuit. If the ideal
circuit is capable of finding an eligible quantum code, after adequate
optimization with the noisy circuit, the output parameters
$\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}$ are still correct.

Proof  Consider the cost functions in Eqs. (15), (16). Due to the global
depolarizing noise, when we run the VQC $U(\boldsymbol{\theta})$ to prepare a
basis state $|\psi_{j}\rangle$, we instead obtain

$\rho_{j}=(1-\epsilon_{1})|\psi_{j}\rangle\langle\psi_{j}|+\epsilon_{1}\frac{I}{2^{n}};$
(99)

when we apply $U^{\dagger}(\boldsymbol{\theta})E_{\mu}U(\boldsymbol{\theta})$
to an initial binary string $|\mathbf{j-1}\rangle|\mathbf{0}\rangle$ to
prepare the output state $|\psi_{j,\mu}\rangle$, we instead obtain

$\rho_{j,\mu}=(1-\epsilon_{2})|\psi_{j,\mu}\rangle\langle\psi_{j,\mu}|+\epsilon_{2}\frac{I}{2^{n}}.$
(100)

Noise rates $\epsilon_{1}$ and $\epsilon_{2}$ are unknown constants determined
by the circuit depth. After adequate optimization with the noisy VQC, we
obtain the pseudo-optimal parameters

$\displaystyle\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}=$
$\displaystyle\arg\min_{\boldsymbol{\theta}}$ (101)
$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\Big{(}\sum_{1\leq i<j\leq
K}\sqrt{\langle\mathbf{i-1}|\langle\mathbf{0}|\rho_{j,\mu}|\mathbf{i-1}\rangle|\mathbf{0}\rangle}$
$\displaystyle+\sum_{j=1}^{K}\big{|}\operatorname{Tr}(\rho_{j}E_{\mu})-\sum_{i=1}^{K}\operatorname{Tr}(\rho_{i}E_{\mu})/K\big{|}/2\Big{)}$
$\displaystyle=$ $\displaystyle\arg\min_{\boldsymbol{\theta}}$
$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\Big{(}\sum_{1\leq i<j\leq
K}\sqrt{(1-\epsilon_{2})\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}^{2}+\frac{\epsilon_{2}}{2^{n}}}$
$\displaystyle+\sum_{j=1}^{K}\frac{1-\epsilon_{1}}{2}\big{|}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}\Big{)}.$

Since the ideal variational quantum circuit is capable of finding an eligible
quantum code, each term in the cost function Eq. (15) can be minimized to 0
(i.e., $\big{|}\langle\psi_{i}|E_{\mu}|\psi_{j}\rangle\big{|}=0$,
$\big{|}\langle\psi_{j}|E_{\mu}|\psi_{j}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}=0$). Comparing Eq. (15) and Eq. (101), we conclude that

$\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}=\boldsymbol{\theta}_{\mathrm{opt}}.$
(102)

$\blacksquare$

To sum up, VarQEC is perfectly resilient to global depolarizing noise, i.e.,
it can find the correct encoding circuit in the presence of global
depolarizing.

Figure 8: Gate error model. $R_{zz}$ is accompanied by local depolarizing
noise $\mathcal{N}_{\mathrm{DP}}$ and collective phase-flip error
$\mathcal{N}_{\mathrm{ZZ}}$ both before and after.

In practical scenarios, circuit noise is more complicated and single-qubit
errors dominate. Now we consider a more realistic model. Suppose each 2-qubit
$R_{zz}$ gate in the VQC is accompanied by local depolarizing noise and
collective phase flips, as illustrated in Fig. 8. Before the ideal unitary
$R_{zz}$, the two qubits goes through $\mathcal{N}_{\mathrm{DP}}^{\otimes
2}\circ\mathcal{N}_{\mathrm{ZZ}}$, after the ideal $R_{zz}$, the system goes
through $\mathcal{N}_{\mathrm{ZZ}}\circ\mathcal{N}_{\mathrm{DP}}^{\otimes 2}$.
In the following, for gate error rate $p_{\mathrm{gate}}$, we set the error
rate of each $\mathcal{N}_{\mathrm{DP}}$ as $p_{\mathrm{gate}}/2$, the error
rate of each $\mathcal{N}_{\mathrm{ZZ}}$ as $p_{\mathrm{gate}}/8$.

Still, we use VarQEC to find channel-adaptive codes for noise channel
$\mathcal{N}$ (Eq. (79)) with hardware connectivity graphs (c,d) shown in Fig.
7. The difference is that this time the VQC is noisy. After optimization, we
obtain the pseudo-optimal parameters
$\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}$. It is interesting to note that
if we transfer $\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}$ to an ideal VQC,
the corresponding cost function
$C^{\ell_{1}}_{n,K,\mathcal{N}}(\boldsymbol{\theta}^{\prime}_{\mathrm{opt}})$
can be much smaller than the one we estimated with the noisy VQC. Namely, we
find a roughly correct encoder even if we use a noisy VQC in our algorithm.
The comparison of cost functions for different gate error rates is given in
Fig. 9(a). The cost reduction for both graphs is obvious. Two-qubit gate error
rates on state-of-the-art NISQ computers are about $\sim 10^{-2}$ [79]. One
can run our algorithm on current hardware directly.

Figure 9: Noise resilience of VarQEC using VQCs with connectivity graphs (c,d)
in Fig. 7. (a) The noisy- and ideal-VQC cost functions versus gate error rate.
$\boldsymbol{\theta}^{\prime}_{\mathrm{opt}}$ were obtained by optimizing a
noisy VQC. (b) Average $\lambda$s (see Eq. (104)) versus the number of VQC
layers for graph (c). (c) Average $\lambda$s versus the number of VQC layers
for graph (d). The shaded areas represent the standard deviation of 100
samples.

Suppose the input state of a quantum circuit is $|\psi_{\mathrm{in}}\rangle$,
the target unitary evolution is $U_{\mathrm{ideal}}$. The ideal output state
is

$|\psi_{\mathrm{ideal}}\rangle=U_{\mathrm{ideal}}|\psi_{\mathrm{in}}\rangle.$
(103)

However, due to quantum gate errors, the output state $\rho_{\mathrm{out}}$ is
a mixed state. We express $\rho_{\mathrm{out}}$ as a summation of three terms,

$\displaystyle\rho_{\mathrm{out}}$
$\displaystyle=\mathcal{N}_{\mathrm{circuit}}(|\psi_{\mathrm{in}}\rangle)$
(104)
$\displaystyle=\lambda_{0}|\psi_{\mathrm{ideal}}\rangle\langle\psi_{\mathrm{ideal}}|+\lambda_{1}\frac{I}{2^{n}}+\lambda_{2}\rho_{2},$

where $\mathcal{N}_{\mathrm{circuit}}$ denotes that channel of the noisy
quantum circuit, $\lambda_{1}$ is the smallest eigenvalue of
$\rho_{\mathrm{out}}$ multiplied by $2^{n}$, $I/2^{n}$ is the maximally mixed
state, $\rho_{2}$ is a density operator orthogonal to
$|\psi_{\mathrm{ideal}}\rangle$, i.e.,

$\operatorname{Tr}(\rho_{1}|\psi_{\mathrm{ideal}}\rangle\langle\psi_{\mathrm{ideal}}|)=0.$
(105)

The latter two terms of Eq. (104) are both induced by gate errors, but they
have different effects on the noise resilience of our algorithm. The second
term is a global white noise, as we analyzed in Theorem 5, it does not affect
the optimal parameters. However, the third term $\lambda_{2}\rho_{2}$ non-
trivially alters the optimization landscape and introduces some local minima.
Usually, both the second term and the third term are not negligible.
Nevertheless, we are certain about the trend: with the increase of circuit
depth, the second term will dominate the third term eventually [80, 81].

For VQCs corresponding to graphs (c,d), we fix gate error rate $0.01$, and try
different numbers of layers with randomly sampled $\boldsymbol{\theta}$. The
average value of $\lambda^{\prime}$s are shown in Fig. 9(b,c). Each point is
averaged over 100 samples. Compared with the one-dimensional ring (graph (c)),
vertices in the complete graph (graph (d)) are more tightly connected, local
errors can be transformed into global white noise more rapidly. For both
graphs, $\lambda_{1}\ll\lambda_{2}$ when $L$ is relatively small and
$\lambda_{1}\gg\lambda_{2}$ when $L$ is relatively large. With the decrease of
gate error rate and the increase of circuit depth, VarQEC will become more
resilient to noise. Additionally, one might also consider estimating cost
functions in VarQEC more precisely with error mitigation techniques like
virtual distillation [82, 83].

##  7 Barren Plateaus

The barren plateau (BP) [84, 85] and the noise-induced barren plateau (NIBP)
[86] are two daunting challenges in variational quantum optimization. In this
section, we numerically investigate their effects in the VarQEC algorithm.

The barren plateau is a phenomenon where the gradients vanish exponentially
with the increasing number of qubits [84]. It occurs when the VQCs form a
unitary 2-design, regardless of whether the VQC is noisy or noiseless. Ref.
[85] connected the locality of the cost function and the trainability of the
corresponding VQC. If the cost function is local and the circuit depth is of
order $\mathcal{O}(\log(n))$, the BP does not occur (i.e., the VQC is
trainable). However, if the cost function is global or the circuit depth is of
order $\mathcal{O}(\text{poly}(n))$, a BP occurs in the optimization
landscape, and the VQC is untrainable.

In near-term quantum computation, dominating errors always only act on several
local qubits. Accordingly, the cost functions $C^{\ell_{1}}_{n,K,\mathcal{E}}$
(Eq. (15)) and $C^{\ell_{2}}_{n,K,\mathcal{E}}$ (Eq. (16)) are merely
influenced by local errors $E_{\mu}$. Therefore, we expect the same conclusion
to hold for VarQEC: the BP does not occur when the circuit depth is of order
$\mathcal{O}(\log(n))$ and occurs when the circuit depth is of order
$\mathcal{O}(\text{poly}(n))$.

Without loss of generality, here we use the star connectivity graph $S_{n-1}$
($S_{7}$ is illustrated in Fig. 10(b) inset) and focus on
$C^{\ell_{2}}_{n,2,\mathcal{E}}$ with
$\mathcal{E}=\left\\{O_{\alpha}\mid\mathrm{wt}\left(O_{\alpha}\right)<3\right\\}$,
i.e., searching for QECCs that encode one logical qubit information and
correct an arbitrary single-qubit error. Fig. 10(a) plots the partial
derivative of the off-diagonal cost

$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\sum_{1\leq i<j\leq
K}\big{|}\langle\mathbf{i}|\langle\mathbf{0}|U^{\dagger}(\boldsymbol{\theta})E_{\mu}U(\boldsymbol{\theta})|\mathbf{j}\rangle|\mathbf{0}\rangle\big{|}^{2}$
(106)

and the diagonal cost

$\displaystyle\sum_{E_{\mu}\in\mathcal{E}}\sum_{j=1}^{K}\big{|}\langle\mathbf{j}|\langle\mathbf{0}|U^{\dagger}(\boldsymbol{\theta})E_{\mu}U(\boldsymbol{\theta})|\mathbf{j}\rangle|\mathbf{0}\rangle-\overline{\langle
E_{\mu}\rangle}\big{|}^{2}/4.$ (107)

with respect to a randomly selected circuit parameter $\theta_{j}$. When the
number of VQC layers is $L=3$ or $L=\lceil\log(n)\rceil$, the circuit is
trainable. However, when $L=n$, both off-diagonal and diagonal gradients decay
exponentially with the increasing number of qubits.

Figure 10: Barren plateaus and noise-induced barren plateaus in VarQEC. (a)
Partial derivatives of the off-diagonal and diagonal parts of
$C^{\ell_{2}}_{n,K,\mathcal{E}}$ with respect to a random circuit parameter
for different system sizes and circuit depths. Each point is averaged over
1000 samples. (b) Partial derivatives of $C^{\ell_{2}}_{n,K,\mathcal{E}}$ with
respect to a random parameter for gate noise rates (from top to bottom)
$p=0,5\times 10^{-3},0.01,0.02,0.03,0.04,0.05$. Each point is averaged over
1000 samples, and the shaded areas represent the standard deviations. Inset:
connectivity graph of $S_{7}$.

The noise-induced barren plateau refers to a conceptually different phenomenon
where cost gradients vanish exponentially with $L$ due to hardware noise
accumulation [86]. Consequently, the gradients vanish exponentially with $n$
if $L$ grows linearly with $n$. Unlike the noise-free BP, NIPB only occurs
when the VQC is noisy, regardless of whether the circuits form a unitary
2-design. Still, we consider the local noise model illustrated in Fig. 8,
system size $n=8$, number of layers $L=1,5,10,15,20,25,30$, noise rate
$p=0,5\times 10^{-3},0.01,0.02,0.03,0.04,0.05$. The numerical results for the
gradients are shown in Fig. 10(b). With the increase of $L$, the partial
derivatives of $C^{\ell_{2}}_{n,K,\mathcal{E}}$ with respect to a random
parameter decay exponentially, and the decay factor is determined by the noise
rate. This illustrates that although VarQEC can find a roughly correct encoder
after adequate training with a noisy VQC (noise resilience), the required
training time grows exponentially with the number of circuit layers.

BPs and NIBPs manifest themselves in VarQEC when the circuit depth gets large.
Nevertheless, we do not need to worry too much about them. From a practical
standpoint, we are more interested in QECCs with a shallow (even constant
depth) encoding circuit. The gradients of cost functions tend to be large when
searching for these codes. In addition, there are more and more effective
strategies to mitigate BPs, e.g., cost function partitioning and meta-learning
[87] as well as optimization guided by classical shadows [88]. These protocols
can be applied to VarQEC reasonably.

##  8 Experiment on an IBM machine

Now we experimentally demonstrate VarQEC with a real superconducting quantum
machine, $ibm\\_quito$ [89]. The connectivity graph of $ibm\\_quito$ is shown
in Fig. 11(a). Our goal is to find a 4-qubit approximate QECC to correct one
amplitude damping error [43] using physical qubits $Q_{0},Q_{1},Q_{2},Q_{3}$.

The Kraus operators of the amplitude damping channel are

$\displaystyle A_{0}$ $\displaystyle=\left(\begin{array}[]{cc}1&0\\\
0&\sqrt{1-\gamma}\end{array}\right)$ (108)
$\displaystyle=I-\frac{\gamma}{4}(I-Z)+\mathcal{O}\left(\gamma^{2}\right),$
$\displaystyle A_{1}$
$\displaystyle=\left(\begin{array}[]{cc}0&\sqrt{\gamma}\\\
0&0\end{array}\right)=\frac{\sqrt{\gamma}}{2}(X+iY).$

Each $(I-Z)$ term contributes a factor of $\gamma$ and each $(X+iY)$ term
contributes a factor of $\sqrt{\gamma}$. To correct a single amplitude damping
error, we only need to consider error products with total order less than
$\gamma^{3/2}$:

$\displaystyle\mathcal{E}=\\{$ $\displaystyle
I,X_{j}+iY_{j},X_{j}-iY_{j},(X_{i}-iY_{i})(X_{j}+iY_{j}),$ (109)
$\displaystyle I_{j}-Z_{j}\\}.$

The variational quantum circuit we use is illustrated in Fig. 11(b). When the
rotation angle $\theta=\pm\pi/2$, the VQC serves as an exact encoder. Since
$Q_{2}$ and $Q_{3}$ are not directly connected, the IBM compiler adds 2
additional SWAP gates (each realized by 3 CNOT gates) to implement CNOT
between $Q_{2}$ and $Q_{3}$). The hardware-efficient VQC after compiling is
shown in Fig. 11(c).

Due to hardware constraints, we slightly modify the VarQEC algorithm and
enhance it with quantum error mitigation (EM) as follows. Suppose the initial
parameter $\theta=0.1$, we iteratively apply the VQC to input states
$|0000\rangle$ and $|0010\rangle$, do quantum state tomography on the output
mixed states and record their density matrices $\rho_{1}$ and $\rho_{2}$. Then
we classically extract their dominating eigenstates

$|\tilde{\psi}_{1}\rangle=\lim_{M\rightarrow\infty}\frac{\rho_{1}^{M}}{\operatorname{Tr}(\rho_{1}^{M})},|\tilde{\psi}_{2}\rangle=\lim_{M\rightarrow\infty}\frac{\rho_{2}^{M}}{\operatorname{Tr}(\rho_{2}^{M})},$
(110)

estimate the cost functions $C^{\ell_{2}}_{n,K,\mathcal{E}}$ and
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ of logical basis states
$\\{|\tilde{\psi}_{1}\rangle,(|\tilde{\psi}_{2}\rangle-\langle\tilde{\psi}_{1}|\tilde{\psi}_{2}\rangle|\tilde{\psi}_{1}\rangle)/c\\}$,
where $c$ is a normalization factor.

The cost gradients are estimated by finite differencing:

$\frac{\partial
C_{4,2,\mathcal{E}}(\theta)}{\partial\theta}\approx\frac{C_{4,2,\mathcal{E}}(\theta+\delta\theta)-C_{4,2,\mathcal{E}}(\theta-\delta\theta)}{2\delta\theta}$
(111)

with $\delta\theta=0.05$. In the first stage (first 15 iterations), we
minimize $C^{\ell_{2}}_{n,K,\mathcal{E}}$ with learning rate $\eta=1$ until
$C^{\ell_{2}}_{n,K,\mathcal{E}}<0.01$. Then we switch to
$C^{\ell_{1}}_{n,K,\mathcal{E}}$ and minimize it with a smaller learning rate
$\eta=0.05$. The training curves of the estimated
$C^{\ell_{2}}_{n,K,\mathcal{E}}$ with/without error mitigation and its real
value are shown in Fig. 11(d). After adequate training (25 iterations), the
parameter $\theta$ converges to about $1.63$, slightly greater than the ideal
angle $\pi/2$ (indicated by the dashed line in the inset). Nevertheless, this
difference is acceptable, the VQC still encodes an approximate amplitude
damping code.

We implement a total of $152$ quantum circuits for this experiment: $100$ for
estimating the gradients and $52$ for estimating the cost functions.

Figure 11: Experimental results of VarQEC for finding an approximate amplitude
damping code. (a) The hardware connectivity of $ibm\\_quito$.
$Q_{0},Q_{1},Q_{2},Q_{3}$ are used in the experiment. $Q_{2}$ encodes the
initial logical information. (b-c) The original and the compiled variational
quantum circuits. (d) The estimated $\ell_{2}$-norm cost functions
with/without error mitigation (EM) and its real value during variational
learning. Inset: the rotation angle $\theta$ during learning.

##  9 Conclusions and Outlooks

In this work, we proposed VarQEC, an effective variational quantum algorithm
for finding various quantum error-correcting codes. VarQEC is capable of
finding arbitrary quantum codes since the cost functions therein are based on
the most general requirement of a QECC, the Knill-Laflamme conditions. We
demonstrated its efficacy by discovering/rediscovering some symmetric,
asymmetric, and channel-adaptive codes, e.g., $((5,2,3))_{2}$,
$((5,6,2))_{2}$, $((6,2,3))_{2}$, $((7,2,3))_{2}$, $((12,2^{6},3))_{2}$,
$((14,2^{8},3))_{2}$, $((10,4,4))_{2}$, $((6,2,d_{e}(2)=4))_{2}$,
$((8,3,d_{e}(2)=4))_{2}$. Some discovered codes are equivalent to stabilizer
ones and some are not. We investigated them in detail. In particular, VarQEC
provided numerical evidence that a quantum code with parameters
$((7,3,3))_{2}$ does not exist. It is worth mentioning that the channel-
adaptive codes with optimized encoding circuits found by our method can then
be used as inner codes on the physical level in a concatenation scheme.
Stabilizer QECCs for qudits can be used as outer codes.

VarQEC is robust to hardware noise; therefore, it is particularly promising in
the NISQ era. A problem worth studying further is how to choose the most
resource-efficient variational quantum circuit in VarQEC. There is reason to
believe that the optimal VQC ansatz is code-dependent. For example, when the
target quantum code is translational-invariant, one may use a VQC with a
certain amount of symmetry, where different gates can share the same
parameter. If we slightly modify the cost functions, VarQEC can be used for
finding some QECC variants like the hybrid quantum-classical codes [90],
estimating the zero-error capacity of noisy quantum channels [91], and solving
quantum marginal problems [92].

VarQEC can also be directly revised to a classical algorithm. When a NISQ
processor is not accessible, one can replace the VQCs with classical
variational ansatzes like tensor networks [93, 94, 95] or neural network
quantum states [96], and then similarly implement optimization and search for
eligible quantum codes merely with a classical computer. However, the encoding
circuits can not be naturally obtained.

We thank Song Cheng and Sirui Lu for helpful discussions. MG acknowledges
support by the Foundation for Polish Science (IRAP project, ICTQT, contract
no. MAB/2018/5, co-financed by EU within Smart Growth Operational Programme).
BZ is supported by General Research Fund (no. GRF/16305121).

## References

  * [1] N. Cody Jones, James D. Whitfield, Peter L. McMahon, Man-Hong Yung, Rodney Van Meter, Alán Aspuru-Guzik, and Yoshihisa Yamamoto.  “Faster quantum chemistry simulation on fault-tolerant quantum computers”.  New Journal of Physics 14, 115023 (2012).
  * [2] Peter W. Shor.  “Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer”.  SIAM J. Comput. 26, 1484–1509 (1997).
  * [3] Aram W. Harrow, Avinatan Hassidim, and Seth Lloyd.  “Quantum algorithm for linear systems of equations”.  Phys. Rev. Lett. 103, 150502 (2009).
  * [4] Peter W. Shor.  “Scheme for reducing decoherence in quantum computer memory”.  Phys. Rev. A 52, R2493–R2496 (1995).
  * [5] Daniel Gottesman.  “Stabilizer codes and quantum error correction” (1997).  arXiv:quant-ph/9705052.
  * [6] Daniel A. Lidar and Todd A. Brun.  “Quantum error correction”.  Cambridge University Press. (2013).
  * [7] Bei Zeng, Xie Chen, Duan-Lu Zhou, and Xiao-Gang Wen.  “Quantum information meets quantum matter: From quantum entanglement to topological phases of many-body systems”.  Springer. (2019).
  * [8] Steven M. Girvin.  “Introduction to quantum error correction and fault tolerance” (2021).  arXiv:2111.08894.
  * [9] Fernando Pastawski, Beni Yoshida, Daniel Harlow, and John Preskill.  “Holographic quantum error-correcting codes: toy models for the bulk/boundary correspondence”.  Journal of High Energy Physics 2015, 149 (2015).
  * [10] Emanuel Knill and Raymond Laflamme.  “Theory of quantum error-correcting codes”.  Phys. Rev. A 55, 900–911 (1997).
  * [11] A. Yu Kitaev.  “Quantum computations: algorithms and error correction”.  Russian Mathematical Surveys 52, 1191–1249 (1997).
  * [12] Austin G. Fowler, Matteo Mariantoni, John M. Martinis, and Andrew N. Cleland.  “Surface codes: Towards practical large-scale quantum computation”.  Phys. Rev. A 86, 032324 (2012).
  * [13] A. R. Calderbank and Peter W. Shor.  “Good quantum error-correcting codes exist”.  Phys. Rev. A 54, 1098–1105 (1996).
  * [14] Andrew Steane.  “Multiple-particle interference and quantum error correction”.  Proceedings of the Royal Society of London. Series A: Mathematical, Physical and Engineering Sciences 452, 2551–2577 (1996).
  * [15] Andrew Cross, Graeme Smith, John A. Smolin, and Bei Zeng.  “Codeword stabilized quantum codes”.  In 2008 IEEE International Symposium on Information Theory.  Pages 364–368.  (2008).
  * [16] Isaac Chuang, Andrew Cross, Graeme Smith, John Smolin, and Bei Zeng.  “Codeword stabilized quantum codes: Algorithm and structure”.  Journal of Mathematical Physics 50, 042109 (2009).
  * [17] Nikolas P. Breuckmann and Jens Niklas Eberhardt.  “Quantum low-density parity-check codes”.  PRX Quantum 2, 040101 (2021).
  * [18] Pavel Panteleev and Gleb Kalachev.  “Asymptotically good quantum and locally testableclassical ldpc codes”.  In Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing.  Pages 375–388.  Association for Computing Machinery (2022).
  * [19] Laird Egan, Dripto M. Debroy, Crystal Noel, Andrew Risinger, Daiwei Zhu, Debopriyo Biswas, Michael Newman, Muyuan Li, Kenneth R. Brown, Marko Cetina, and Christopher Monroe.  “Fault-tolerant control of an error-corrected qubit”.  Nature 598, 281–286 (2021).
  * [20] Lukas Postler, Sascha Heußen, Ivan Pogorelov, Manuel Rispler, Thomas Feldker, Michael Meth, Christian D. Marciniak, Roman Stricker, Martin Ringbauer, Rainer Blatt, Philipp Schindler, Markus Müller, and Thomas Monz.  “Demonstration of fault-tolerant universal quantum gate operations”.  Nature 605, 675–680 (2022).
  * [21] Christopher M. Dawson, Henry L. Haselgrove, and Michael A. Nielsen.  “Noise thresholds for optical quantum computers”.  Phys. Rev. Lett. 96, 020501 (2006).
  * [22] C. D. Wilen, S. Abdullah, N. A. Kurinsky, C. Stanford, L. Cardani, G. D’Imperio, C. Tomei, L. Faoro, L. B. Ioffe, C. H. Liu, A. Opremcak, B. G. Christensen, J. L. DuBois, and R. McDermott.  “Correlated charge noise and relaxation errors in superconducting qubits”.  Nature 594, 369–373 (2021).
  * [23] Qihao Guo, Yuan-Yuan Zhao, Markus Grassl, Xinfang Nie, Guo-Yong Xiang, Tao Xin, Zhang-Qi Yin, and Bei Zeng.  “Testing a quantum error-correcting code on various platforms”.  Science Bulletin 66, 29–35 (2021).
  * [24] Sixia Yu, Qing Chen, and C. H. Oh.  “Graphical quantum error-correcting codes” (2007).  arXiv:0709.1780.
  * [25] Dan Hu, Weidong Tang, Meisheng Zhao, Qing Chen, Sixia Yu, and C. H. Oh.  “Graphical nonbinary quantum error-correcting codes”.  Phys. Rev. A 78, 012306 (2008).
  * [26] Akshaya Jayashankar, Anjala M. Babu, Hui Khoon Ng, and Prabha Mandayam.  “Finding good quantum codes using the cartan form”.  Phys. Rev. A 101, 042307 (2020).
  * [27] Muyuan Li, Mauricio Gutiérrez, Stanley E. David, Alonzo Hernandez, and Kenneth R. Brown.  “Fault tolerance with bare ancillary qubits for a [[7,1,3]] code”.  Phys. Rev. A 96, 032341 (2017).
  * [28] Thomas Fösel, Petru Tighineanu, Talitha Weiss, and Florian Marquardt.  “Reinforcement learning with neural networks for quantum feedback”.  Phys. Rev. X 8, 031084 (2018).
  * [29] Paul Baireuther, Thomas E. O’Brien, Brian Tarasinski, and Carlo W. J. Beenakker.  “Machine-learning-assisted correction of correlated qubit errors in a topological code”.  Quantum 2, 48 (2018).
  * [30] Philip Andreasson, Joel Johansson, Simon Liljestrand, and Mats Granath.  “Quantum error correction for the toric code using deep reinforcement learning”.  Quantum 3, 183 (2019).
  * [31] Hendrik Poulsen Nautrup, Nicolas Delfosse, Vedran Dunjko, Hans J. Briegel, and Nicolai Friis.  “Optimizing quantum error correction codes with reinforcement learning”.  Quantum 3, 215 (2019).
  * [32] M. Reimpell and R. F. Werner.  “Iterative optimization of quantum error correcting codes”.  Phys. Rev. Lett. 94, 080501 (2005).
  * [33] Andrew S. Fletcher, Peter W. Shor, and Moe Z. Win.  “Optimum quantum error recovery using semidefinite programming”.  Phys. Rev. A 75, 012338 (2007).
  * [34] Andrew S. Fletcher.  “Channel-adapted quantum error correction” (2007).  arXiv:0706.3400.
  * [35] Ryan Sweke, Markus S. Kesselring, Evert P. L. van Nieuwenburg, and Jens Eisert.  “Reinforcement learning decoders for fault-tolerant quantum computation”.  Machine Learning: Science and Technology 2, 025005 (2020).
  * [36] Ye-Hua Liu and David Poulin.  “Neural belief-propagation decoders for quantum error-correcting codes”.  Phys. Rev. Lett. 122, 200501 (2019).
  * [37] David F. Locher, Lorenzo Cardarelli, and Markus Müller.  “Quantum error correction with quantum autoencoders” (2022).  arXiv:2202.00555.
  * [38] Emanuel Knill and Raymond Laflamme.  “Concatenated quantum codes” (1996).  arXiv:quant-ph/9608012.
  * [39] Markus Grassl, Peter Shor, Graeme Smith, John Smolin, and Bei Zeng.  “Generalized concatenated quantum codes”.  Phys. Rev. A 79, 050306 (2009).
  * [40] Daniel Gottesman.  “An introduction to quantum error correction”.  In Proceedings of Symposia in Applied Mathematics.  Volume 58, pages 221–236.  (2002).
  * [41] P. Aliferis, F. Brito, D. P. DiVincenzo, J. Preskill, M. Steffen, and B. M. Terhal.  “Fault-tolerant computing with biased-noise superconducting qubits: a case study”.  New Journal of Physics 11, 013061 (2009).
  * [42] Tyler Jackson, Markus Grassl, and Bei Zeng.  “Concatenated codes for amplitude damping”.  In 2016 IEEE International Symposium on Information Theory (ISIT).  Pages 2269–2273.  (2016).
  * [43] Debbie W. Leung, M. A. Nielsen, Isaac L. Chuang, and Yoshihisa Yamamoto.  “Approximate quantum error correction can lead to better codes”.  Phys. Rev. A 56, 2567–2573 (1997).
  * [44] Benjamin Schumacher and Michael D. Westmoreland.  “Approximate quantum error correction”.  Quantum Information Processing 1, 5–12 (2002).
  * [45] Fernando G. S. L. Brandão, Elizabeth Crosson, M. Burak Şahinoğlu, and John Bowen.  “Quantum error correcting codes in eigenstates of translation-invariant spin chains”.  Phys. Rev. Lett. 123, 110502 (2019).
  * [46] Cédric Bény and Ognyan Oreshkov.  “General conditions for approximate quantum error correction and near-optimal recovery channels”.  Phys. Rev. Lett. 104, 120501 (2010).
  * [47] Donald Bures.  “An extension of Kakutani’s theorem on infinite product measures to the tensor product of semifinite w*-algebras”.  Transactions of the American Mathematical Society 135, 199–212 (1969).
  * [48] M. Cerezo, Andrew Arrasmith, Ryan Babbush, Simon C. Benjamin, Suguru Endo, Keisuke Fujii, Jarrod R. McClean, Kosuke Mitarai, Xiao Yuan, Lukasz Cincio, and Patrick J. Coles.  “Variational quantum algorithms”.  Nature Reviews Physics 3, 625–644 (2021).
  * [49] Kishor Bharti, Alba Cervera-Lierta, Thi Ha Kyaw, Tobias Haug, Sumner Alperin-Lea, Abhinav Anand, Matthias Degroote, Hermanni Heimonen, Jakob S. Kottmann, Tim Menke, Wai-Keong Mok, Sukin Sim, Leong-Chuan Kwek, and Alán Aspuru-Guzik.  “Noisy intermediate-scale quantum algorithms”.  Rev. Mod. Phys. 94, 015004 (2022).
  * [50] Alberto Peruzzo, Jarrod McClean, Peter Shadbolt, Man-Hong Yung, Xiao-Qi Zhou, Peter J. Love, Alán Aspuru-Guzik, and Jeremy L. O’Brien.  “A variational eigenvalue solver on a photonic quantum processor”.  Nature Communications 5, 4213 (2014).
  * [51] Abhinav Kandala, Antonio Mezzacapo, Kristan Temme, Maika Takita, Markus Brink, Jerry M. Chow, and Jay M. Gambetta.  “Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets”.  Nature 549, 242–246 (2017).
  * [52] Yunseong Nam, Jwo-Sy Chen, Neal C. Pisenti, Kenneth Wright, Conor Delaney, Dmitri Maslov, Kenneth R. Brown, Stewart Allen, Jason M. Amini, Joel Apisdorf, Kristin M. Beck, Aleksey Blinov, Vandiver Chaplin, Mika Chmielewski, Coleman Collins, Shantanu Debnath, Kai M. Hudek, Andrew M. Ducore, Matthew Keesan, Sarah M. Kreikemeier, Jonathan Mizrahi, Phil Solomon, Mike Williams, Jaime David Wong-Campos, David Moehring, Christopher Monroe, and Jungsang Kim.  “Ground-state energy estimation of the water molecule on a trapped-ion quantum computer”.  npj Quantum Information 6, 33 (2020).
  * [53] Chenfeng Cao, Yunlong Yu, Zipeng Wu, Nic Shannon, Bei Zeng, and Robert Joynt.  “Mitigating algorithmic errors in quantum optimization through energy extrapolation”.  Quantum Science and Technology (2022).
  * [54] Jonathan Romero, Jonathan P Olson, and Alan Aspuru-Guzik.  “Quantum autoencoders for efficient compression of quantum data”.  Quantum Science and Technology 2, 045001 (2017).
  * [55] Chenfeng Cao and Xin Wang.  “Noise-assisted quantum autoencoder”.  Phys. Rev. Applied 15, 054012 (2021).
  * [56] Kunal Sharma, Sumeet Khatri, M. Cerezo, and Patrick J. Coles.  “Noise resilience of variational quantum compiling”.  New Journal of Physics 22, 043006 (2020).
  * [57] Xiaosi Xu, Simon C. Benjamin, and Xiao Yuan.  “Variational circuit compiler for quantum error correction”.  Phys. Rev. Applied 15, 034068 (2021).
  * [58] K. Mitarai, M. Negoro, M. Kitagawa, and K. Fujii.  “Quantum circuit learning”.  Phys. Rev. A 98, 032309 (2018).
  * [59] Hsin-Yuan Huang, Richard Kueng, and John Preskill.  “Predicting many properties of a quantum system from very few measurements”.  Nature Physics 16, 1050–1057 (2020).
  * [60] M. J. D. Powell.  “An efficient method for finding the minimum of a function of several variables without calculating derivatives”.  The Computer Journal 7, 155–162 (1964).
  * [61] Tobias Haug, Kishor Bharti, and M. S. Kim.  “Capacity and quantum geometry of parametrized quantum circuits”.  PRX Quantum 2, 040309 (2021).
  * [62] Peter D. Johnson, Jonathan Romero, Jonathan Olson, Yudong Cao, and Alán Aspuru-Guzik.  “QVECTOR: an algorithm for device-tailored quantum error correction” (2017).  arXiv:1711.02249.
  * [63] Raymond Laflamme, Cesar Miquel, Juan Pablo Paz, and Wojciech Hubert Zurek.  “Perfect quantum error correcting code”.  Phys. Rev. Lett. 77, 198–201 (1996).
  * [64] Eric M. Rains, R. H. Hardin, Peter W. Shor, and N. J. A. Sloane.  “A nonadditive quantum code”.  Phys. Rev. Lett. 79, 953–954 (1997).
  * [65] A. M. Steane.  “Simple quantum error-correcting codes”.  Phys. Rev. A 54, 4741–4751 (1996).
  * [66] Lev Ioffe and Marc Mézard.  “Asymmetric quantum error-correcting codes”.  Phys. Rev. A 75, 032345 (2007).
  * [67] Pradeep Kiran Sarvepalli, Andreas Klappenecker, and Martin Rotteler.  “Asymmetric quantum LDPC codes”.  In 2008 IEEE International Symposium on Information Theory.  Pages 305–309.  (2008).
  * [68] Pradeep Kiran Sarvepalli, Andreas Klappenecker, and Martin Rötteler.  “Asymmetric quantum codes: constructions, bounds and performance”.  Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences 465, 1645–1672 (2009).
  * [69] Martianus Frederic Ezerman, San Ling, and Patrick Sole.  “Additive asymmetric quantum codes”.  IEEE Transactions on Information Theory 57, 5536–5550 (2011).
  * [70] Martianus Frederic Ezerman, Somphong Jitman, San Ling, and Dmitrii V. Pasechnik.  “CSS-like constructions of asymmetric quantum codes”.  IEEE Transactions on Information Theory 59, 6732–6754 (2013).
  * [71] Tyler Jackson, Markus Grassl, and Bei Zeng.  “Codeword stabilized quantum codes for asymmetric channels”.  In 2016 IEEE International Symposium on Information Theory (ISIT).  Pages 2264–2268.  (2016).
  * [72] J. Pablo Bonilla Ataides, David K. Tuckett, Stephen D. Bartlett, Steven T. Flammia, and Benjamin J. Brown.  “The xzzx surface code”.  Nature Communications 12, 2172 (2021).
  * [73] Prithviraj Prabhu and Ben W. Reichardt.  “Distance-four quantum codes with combined postselection and error correction” (2021).  arXiv:2112.03785.
  * [74] A. R. Calderbank, E. M. Rains, P. M. Shor, and N. J. A. Sloane.  “Quantum error correction via codes over GF(4)”.  IEEE Transactions on Information Theory 44, 1369–1387 (1998).
  * [75] Yusuke Hama.  “Quantum circuits for collective amplitude damping in two-qubit systems” (2020).  arXiv:2012.02410.
  * [76] Markus Grassl, Linghang Kong, Zhaohui Wei, Zhang-Qi Yin, and Bei Zeng.  “Quantum error-correcting codes for qudit amplitude damping”.  IEEE Transactions on Information Theory 64, 4674–4685 (2018).
  * [77] Peter Shor and Raymond Laflamme.  “Quantum analog of the macwilliams identities for classical coding theory”.  Phys. Rev. Lett. 78, 1600–1602 (1997).
  * [78] Chenfeng Cao.  “VarQEC GitHub repository”.  https://github.com/caochenfeng/VarQEC-public (2022).
  * [79] Zijun Chen, Kevin J. Satzinger, Juan Atalaya, Alexander N. Korotkov, Andrew Dunsworth, Daniel Sank, Chris Quintana, Matt McEwen, Rami Barends, Paul V. Klimov, Sabrina Hong, Cody Jones, Andre Petukhov, Dvir Kafri, Sean Demura, Brian Burkett, Craig Gidney, Austin G. Fowler, Alexandru Paler, Harald Putterman, Igor Aleiner, Frank Arute, Kunal Arya, Ryan Babbush, Joseph C. Bardin, Andreas Bengtsson, Alexandre Bourassa, Michael Broughton, Bob B. Buckley, David A. Buell, Nicholas Bushnell, Benjamin Chiaro, Roberto Collins, William Courtney, Alan R. Derk, Daniel Eppens, Catherine Erickson, Edward Farhi, Brooks Foxen, Marissa Giustina, Ami Greene, Jonathan A. Gross, Matthew P. Harrigan, Sean D. Harrington, Jeremy Hilton, Alan Ho, Trent Huang, William J. Huggins, L. B. Ioffe, Sergei V. Isakov, Evan Jeffrey, Zhang Jiang, Kostyantyn Kechedzhi, Seon Kim, Alexei Kitaev, Fedor Kostritsa, David Landhuis, Pavel Laptev, Erik Lucero, Orion Martin, Jarrod R. McClean, Trevor McCourt, Xiao Mi, Kevin C. Miao, Masoud Mohseni, Shirin Montazeri, Wojciech Mruczkiewicz, Josh Mutus, Ofer Naaman, Matthew Neeley, Charles Neill, Michael Newman, Murphy Yuezhen Niu, Thomas E. O’Brien, Alex Opremcak, Eric Ostby, Bálint Pató, Nicholas Redd, Pedram Roushan, Nicholas C. Rubin, Vladimir Shvarts, Doug Strain, Marco Szalay, Matthew D. Trevithick, Benjamin Villalonga, Theodore White, Z. Jamie Yao, Ping Yeh, Juhwan Yoo, Adam Zalcman, Hartmut Neven, Sergio Boixo, Vadim Smelyanskiy, Yu Chen, Anthony Megrant, Julian Kelly, and Google Quantum AI.  “Exponential suppression of bit or phase errors with cyclic error correction”.  Nature 595, 383–387 (2021).
  * [80] Alexander M. Dalzell, Nicholas Hunter-Jones, and Fernando G. S. L. Brandão.  “Random quantum circuits transform local noise into global white noise” (2021).  arXiv:2111.14907.
  * [81] Abhinav Deshpande, Bill Fefferman, Alexey V. Gorshkov, Michael J. Gullans, Pradeep Niroula, and Oles Shtanko.  “Tight bounds on the convergence of noisy random circuits to uniform” (2021).  arXiv:2112.00716.
  * [82] William J. Huggins, Sam McArdle, Thomas E. O’Brien, Joonho Lee, Nicholas C. Rubin, Sergio Boixo, K. Birgitta Whaley, Ryan Babbush, and Jarrod R. McClean.  “Virtual distillation for quantum error mitigation”.  Phys. Rev. X 11, 041036 (2021).
  * [83] Bálint Koczor.  “Exponential error suppression for near-term quantum devices”.  Phys. Rev. X 11, 031057 (2021).
  * [84] Jarrod R. McClean, Sergio Boixo, Vadim N. Smelyanskiy, Ryan Babbush, and Hartmut Neven.  “Barren plateaus in quantum neural network training landscapes”.  Nature Communications 9, 4812 (2018).
  * [85] M. Cerezo, Akira Sone, Tyler Volkoff, Lukasz Cincio, and Patrick J. Coles.  “Cost function dependent barren plateaus in shallow parametrized quantum circuits”.  Nature Communications 12, 1791 (2021).
  * [86] Samson Wang, Enrico Fontana, M. Cerezo, Kunal Sharma, Akira Sone, Lukasz Cincio, and Patrick J. Coles.  “Noise-induced barren plateaus in variational quantum algorithms”.  Nature Communications 12, 6961 (2021).
  * [87] Taylor L. Patti, Khadijeh Najafi, Xun Gao, and Susanne F. Yelin.  “Entanglement devised barren plateau mitigation”.  Phys. Rev. Research 3, 033090 (2021).
  * [88] Stefan H. Sack, Raimel A. Medina, Alexios A. Michailidis, Richard Kueng, and Maksym Serbyn.  “Avoiding barren plateaus using classical shadows”.  PRX Quantum 3, 020365 (2022).
  * [89] 5 qubit backend: IBM Q team.  “IBM Q 5 Quito backend specification v1.1.34”.  Retrieved from https://quantum-computing.ibm.com (2022).
  * [90] Markus Grassl, Sirui Lu, and Bei Zeng.  “Codes for simultaneous transmission of quantum and classical information”.  In 2017 IEEE International Symposium on Information Theory (ISIT).  Pages 1718–1722.  (2017).
  * [91] Runyao Duan.  “Super-activation of zero-error capacity of noisy quantum channels” (2009).  arXiv:0906.2527.
  * [92] Xiao-Dong Yu, Timo Simnacher, Nikolai Wyderka, H. Chau Nguyen, and Otfried Gühne.  “A complete hierarchy for the pure state marginal problem in quantum mechanics”.  Nature Communications 12, 1012 (2021).
  * [93] Román Orús.  “Tensor networks for complex quantum systems”.  Nature Reviews Physics 1, 538–550 (2019).
  * [94] J. Ignacio Cirac, David Pérez-García, Norbert Schuch, and Frank Verstraete.  “Matrix product states and projected entangled pair states: Concepts, symmetries, theorems”.  Rev. Mod. Phys. 93, 045003 (2021).
  * [95] Song Cheng, Chenfeng Cao, Chao Zhang, Yongxiang Liu, Shi-Yao Hou, Pengxiang Xu, and Bei Zeng.  “Simulating noisy quantum circuits with matrix product density operators”.  Phys. Rev. Research 3, 023005 (2021).
  * [96] Giuseppe Carleo and Matthias Troyer.  “Solving the quantum many-body problem with artificial neural networks”.  Science 355, 602–606 (2017).
  * [97] Carl W. Helstrom.  “Quantum detection and estimation theory”.  Journal of Statistical Physics 1, 231–252 (1969).
  * [98] Dominik Šafránek.  “Simple expression for the quantum Fisher information matrix”.  Phys. Rev. A 97, 042322 (2018).
  * [99] Jing Liu, Haidong Yuan, Xiao-Ming Lu, and Xiaoguang Wang.  “Quantum fisher information matrix and multiparameter estimation”.  Journal of Physics A: Mathematical and Theoretical 53, 023001 (2019).
  * [100] Johannes Jakob Meyer.  “Fisher Information in Noisy Intermediate-Scale Quantum Applications”.  Quantum 5, 539 (2021).
  * [101] John Milnor and James D Stasheff.  “Characteristic classes. annals of mathematics studies, volume 76”.  Princeton University Press. (2016).

## Appendices

##  Appendix A Proof of Proposition 3

Proof  From the completeness relation of the Kraus operators
$\\{E_{\alpha}\\}$,

$\displaystyle\sum_{\alpha=1}^{m}E_{\alpha}^{\dagger}E_{\alpha}=I,$ (112)

we know

$\displaystyle\operatorname{Tr}(\sum_{\alpha=1}^{m}E_{\alpha}E_{\alpha}^{\dagger})=$
$\displaystyle\sum_{\alpha=1}^{m}\operatorname{Tr}(E_{\alpha}E_{\alpha}^{\dagger})$
(113) $\displaystyle=$
$\displaystyle\sum_{\alpha=1}^{m}\operatorname{Tr}(E_{\alpha}^{\dagger}E_{\alpha})$
$\displaystyle=$
$\displaystyle\operatorname{Tr}(\sum_{\alpha=1}^{m}E_{\alpha}^{\dagger}E_{\alpha})$
$\displaystyle=$ $\displaystyle 2^{n}.$

Each $E_{\alpha}E^{\dagger}_{\alpha}$ and $E^{\dagger}_{\alpha}E_{\alpha}$ are
positive semidefinite. Denote the eigenvalues of
$E_{\alpha}E_{\alpha}^{\dagger}$ as
$\xi^{\alpha}_{1}\geq\xi^{\alpha}_{2}\geq\dots\geq\xi^{\alpha}_{2^{n}}\geq 0$,
the eigenvalues of $E_{\beta}E_{\beta}^{\dagger}$ as
$\xi^{\beta}_{1}\geq\xi^{\beta}_{2}\geq\dots\geq\xi^{\beta}_{2^{n}}\geq 0$,
$\sum_{\alpha,j}\xi^{\alpha}_{j}=\sum_{\beta,j}\xi^{\beta}_{j}=2^{n}$.

Then we have

$\displaystyle\operatorname{Tr}\Big{(}\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}(E^{\dagger}_{\alpha}E_{\beta})^{\dagger}E^{\dagger}_{\alpha}E_{\beta}\Big{)}$
(114) $\displaystyle=$
$\displaystyle\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}\operatorname{Tr}(E_{\alpha}E^{\dagger}_{\alpha}E_{\beta}E^{\dagger}_{\beta})$
$\displaystyle\leq$
$\displaystyle\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}\sum_{j=1}^{2^{n}}\xi^{\alpha}_{j}\xi^{\beta}_{j}$
$\displaystyle\leq$
$\displaystyle\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}\sum_{i=1}^{2^{n}}\sum_{j=1}^{2^{n}}\xi^{\alpha}_{i}\xi^{\beta}_{j}$
$\displaystyle=$ $\displaystyle 2^{2n}.$

The first inequality uses von Neumann’s trace inequality.

Each $E_{\alpha}$ non-trivially acts on no more than $\lfloor(d-1)/2\rfloor$
qubits, therefore, each error product $E^{\dagger}_{\alpha}E_{\beta}$ non-
trivially acts on no more than $(d-1)$ qubits. We expand
$E^{\dagger}_{\alpha}E_{\beta}$ in the Pauli basis,

$E^{\dagger}_{\alpha}E_{\beta}=\sum_{\gamma}\chi_{\gamma}^{\alpha\beta}O_{\gamma}^{\alpha\beta},$
(115)

where each $O_{\gamma}^{\alpha\beta}$ is a Pauli tensor product with weight
less than $d$, $O_{\gamma}^{\alpha\beta\dagger}O_{\gamma}^{\alpha\beta}=I$,
$|\\{O_{\gamma}^{\alpha\beta}\\}|\leq 4^{d-1}m^{2}$. Then

$\displaystyle\operatorname{Tr}\left((E_{\alpha}^{\dagger}E_{\beta})^{\dagger}E_{\alpha}^{\dagger}E_{\beta}\right)=$
$\displaystyle\sum_{\gamma}\operatorname{Tr}\Big{(}|\chi_{\gamma}^{\alpha\beta}|^{2}O_{\gamma}^{\alpha\beta\dagger}O_{\gamma}^{\alpha\beta}\Big{)}$
(116) $\displaystyle=$
$\displaystyle\sum_{\gamma}|\chi_{\gamma}^{\alpha\beta}|^{2}\operatorname{Tr}(O_{\gamma}^{\alpha\beta\dagger}O_{\gamma}^{\alpha\beta})$
$\displaystyle=$ $\displaystyle
2^{n}\sum_{\gamma}|\chi_{\gamma}^{\alpha\beta}|^{2},$
$\operatorname{Tr}\Big{(}\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}(E^{\dagger}_{\alpha}E_{\beta})^{\dagger}E^{\dagger}_{\alpha}E_{\beta}\Big{)}=2^{n}\sum_{\alpha,\beta,\gamma}|\chi_{\gamma}^{\alpha\beta}|^{2}.$
(117)

According to Eq. (114), we have

$\sum_{\alpha,\beta,\gamma}|\chi_{\gamma}^{\alpha\beta}|^{2}\leq 2^{n}.$ (118)

For the basis states
$\\{|\psi_{1}\rangle,|\psi_{2}\rangle,\dots,|\psi_{K}\rangle\\}$,

$\displaystyle\sum_{\alpha,\beta}\sum_{1\leq i<j\leq
K}\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\big{|}$
(119) $\displaystyle=$ $\displaystyle\sum_{\alpha,\beta,\gamma}\sum_{1\leq
i<j\leq
K}|\chi_{\gamma}^{\alpha\beta}|\big{|}\langle\psi_{i}|O_{\gamma}^{\alpha\beta}|\psi_{j}\rangle\big{|}$
$\displaystyle\leq$
$\displaystyle\sum_{\alpha,\beta,\gamma}|\chi_{\gamma}^{\alpha\beta}|\sum_{1\leq
i<j\leq
K}\sum_{\operatorname{wt}(O_{\alpha^{\prime}})<d}\big{|}\langle\psi_{i}|O_{\alpha^{\prime}}|\psi_{j}\rangle\big{|}$
$\displaystyle\leq$ $\displaystyle 2^{n/2+d-1}m\sum_{1\leq i<j\leq
K}\sum_{\operatorname{wt}(O_{\alpha^{\prime}})<d}\big{|}\langle\psi_{i}|O_{\alpha^{\prime}}|\psi_{j}\rangle\big{|}.$

Similarly, we have

$\displaystyle\sum_{\alpha,\beta}\sum_{j=1}^{K}\big{|}\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle-\overline{\langle
E^{\dagger}_{\alpha}E_{\beta}\rangle}\big{|}/2$ (120) $\displaystyle\leq$
$\displaystyle
2^{n/2+d-1}m\sum_{\operatorname{wt}(O_{\alpha^{\prime}})<d}\sum_{j=1}^{K}\big{|}\langle\psi_{j}|O_{\alpha^{\prime}}|\psi_{j}\rangle-\overline{\langle
O_{\alpha^{\prime}}\rangle}\big{|}/2.$

Denote
$\mathcal{E}^{\prime}=\\{E^{\dagger}_{\alpha}E_{\beta}|E_{\alpha},E_{\beta}\text{
are Kraus operators of }\mathcal{N}\\}$, we have

$C^{\ell_{1}}_{n,K,\mathcal{E}^{\prime}}\leq
2^{n/2+d-1}mC^{\ell_{1}}_{n,K,\mathcal{E}}.$ (121)

According to Proposition 2, the code is $\varepsilon$-correctable with
$\varepsilon$ bounded by

$\varepsilon\leq K\sqrt{2C^{\ell_{1}}_{n,K,\mathcal{E}^{\prime}}}\leq
2^{n/4+d/2}K\sqrt{mC^{\ell_{1}}_{n,K,\mathcal{E}}}.$ (122)

$\blacksquare$

##  Appendix B Proof of Proposition 4

Proof  Since each $E_{\alpha}$ is proportional to a Pauli error, we have

$E_{\alpha}^{\dagger}E_{\alpha}=E_{\alpha}E_{\alpha}^{\dagger}.$ (123)

Further, from the completeness relation of the Kraus operators
$\\{E_{\alpha}\\}$,

$\sum_{\alpha=1}^{m}E_{\alpha}^{\dagger}E_{\alpha}=I,$ (124)

we obtain the completeness relation of the error products,
$\\{E^{\dagger}_{\alpha}E_{\beta}\\}$

$\sum_{\beta=1}^{m}\sum_{\alpha=1}^{m}(E^{\dagger}_{\alpha}E_{\beta})^{\dagger}E^{\dagger}_{\alpha}E_{\beta}=\sum_{\beta=1}^{m}E_{\beta}^{\dagger}E_{\beta}=I.$
(125)

The $c_{\text{Z}}$-effective weight of each $E_{\alpha}$ smaller than
$d_{e}(c_{\text{Z}})/2$, therefore, each error product
$E^{\dagger}_{\alpha}E_{\beta}$ is proportional to a Pauli tensor product with
$c_{\text{Z}}$-effective weight

$\operatorname{wt}_{e}(E^{\dagger}_{\alpha}E_{\beta},c_{\text{Z}})<d_{e}(c_{\text{Z}}).$
(126)

Denote

$E^{\dagger}_{\alpha}E_{\beta}=\chi^{\alpha\beta}O^{\alpha\beta},$ (127)

where $O^{\alpha\beta}$ is a Pauli tensor product.

According to Eq. (125), we have the normalization condition

$\sum_{\alpha,\beta}|\chi^{\alpha\beta}|^{2}=1.$ (128)

For the basis states
$\\{|\psi_{1}\rangle,|\psi_{2}\rangle,\dots,|\psi_{K}\rangle\\}$,

$\displaystyle\sum_{\alpha,\beta}\sum_{1\leq i<j\leq
K}\big{|}\langle\psi_{i}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle\big{|}$
(129) $\displaystyle=$ $\displaystyle\sum_{\alpha,\beta}\sum_{1\leq i<j\leq
K}|\chi^{\alpha\beta}|\big{|}\langle\psi_{i}|O^{\alpha\beta}|\psi_{j}\rangle\big{|}$
$\displaystyle\leq$
$\displaystyle\sum_{\alpha,\beta}|\chi^{\alpha\beta}|\sum_{1\leq i<j\leq
K}\sum_{\operatorname{wt}_{e}(O_{\alpha\textquoteright},c_{\text{Z}})<d_{e}(c_{\text{Z}})}\big{|}\langle\psi_{i}|O_{\alpha^{\prime}}|\psi_{j}\rangle\big{|}$
$\displaystyle\leq$ $\displaystyle m\sum_{1\leq i<j\leq
K}\sum_{\operatorname{wt}_{e}(O_{\alpha\textquoteright},c_{\text{Z}})<d_{e}(c_{\text{Z}})}\big{|}\langle\psi_{i}|O_{\alpha^{\prime}}|\psi_{j}\rangle\big{|}.$

Similarly, we have

$\displaystyle\sum_{\alpha,\beta}\sum_{j=1}^{K}\big{|}\langle\psi_{j}|E^{\dagger}_{\alpha}E_{\beta}|\psi_{j}\rangle-\overline{\langle
E^{\dagger}_{\alpha}E_{\beta}\rangle}\big{|}/2$ (130) $\displaystyle\leq$
$\displaystyle
m\sum_{\operatorname{wt}_{e}(O_{\alpha\textquoteright},c_{\text{Z}})<d_{e}(c_{\text{Z}})}\sum_{j=1}^{K}\big{|}\langle\psi_{j}|O_{\alpha^{\prime}}|\psi_{j}\rangle-\overline{\langle
O_{\alpha^{\prime}}\rangle}\big{|}/2.$

Denote
$\mathcal{E}^{\prime}=\\{E^{\dagger}_{\alpha}E_{\beta}|E_{\alpha},E_{\beta}\text{
are Kraus operators of }\mathcal{N}\\}$, we have

$C^{\ell_{1}}_{n,K,\mathcal{E}^{\prime}}\leq mC^{\ell_{1}}_{n,K,\mathcal{E}}.$
(131)

According to Proposition 2, the code is $\varepsilon$-correctable with
$\varepsilon$ bounded by

$\varepsilon\leq K\sqrt{2C^{\ell_{1}}_{n,K,\mathcal{E}^{\prime}}}\leq
K\sqrt{2mC^{\ell_{1}}_{n,K,\mathcal{E}}}.$ (132)

$\blacksquare$

##  Appendix C Parameter Dimension and Overparameterization

The quantum Fisher information matrix (QFIM) is an essential concept in
quantum metrology [97, 98, 99]. In recent years, its applications in NISQ
algorithms and quantum machine learning have also been noticed [100, 61]. Ref.
[61] uses the QFIM to assess the expressive power of a VQC with the fixed
input state $|0\rangle^{\otimes n}$. In VarQEC, however, we use $K$ orthogonal
input states to find an $((n,K))_{2}$ quantum code. In this section, we
generalize the notion of QFIM to multiple input states to quantify the
expressive power of a VQC for preparing an $((n,K))_{2}$ quantum code. Based
on that, we discuss the parameter dimension and the overparameterization of a
VQC encoder.

Suppose the VQC encoder has parameters

$\boldsymbol{\theta}=(\theta_{1},\theta_{2},\dots,\theta_{N}).$ (133)

For a fixed pure input state, one relates the QFIM
$\mathcal{F}(\boldsymbol{\theta})$ to the distance in the space of pure
quantum states by

$\operatorname{Dist}(|\psi(\boldsymbol{\theta})\rangle,|\psi(\boldsymbol{\theta}+d\boldsymbol{\theta})\rangle)^{2}=\sum_{l,m}\mathcal{F}_{l,m}(\boldsymbol{\theta})d\theta_{l}d\theta_{m},$
(134)

where
$\operatorname{Dist}(|\psi(\boldsymbol{\theta})\rangle,|\psi(\boldsymbol{\theta}^{\prime})\rangle)=1-|\langle\psi(\boldsymbol{\theta})|\psi(\boldsymbol{\theta}^{\prime})\rangle|^{2}$.
The QFIM is an $N$ by $N$ matrix

$\mathcal{F}_{lm}(\boldsymbol{\theta})=4\operatorname{Re}\left[\left\langle\partial_{l}\psi|\partial_{m}\psi\right\rangle-\left\langle\partial_{l}\psi|\psi\right\rangle\left\langle\psi|\partial_{m}\psi\right\rangle\right].$
(135)

where $|\partial_{l}\psi\rangle$ denotes
$\partial|\psi(\boldsymbol{\theta})\rangle/\partial\theta_{l}$. In this case,
the parameter dimension $D_{c}$ for a VQC is defined as the number of
independent parameters that the VQC can express in the space of output states.
Numerical evidence shows that $D_{c}$ is usually equivalent to the rank of
QFIM for hardware-efficient VQCs with periodic and non-correlated random
parameters $\boldsymbol{\theta}$ [61].

In VarQEC, the inputs are $K$ orthogonal pure states. Denote the projector
onto the output space as $P_{c}$. We relate $\mathcal{F}(\boldsymbol{\theta})$
to the distance in the space of $K$-dimensional projectors,

$\operatorname{Dist}_{K}(P_{c}(\boldsymbol{\theta}),P_{c}(\boldsymbol{\theta}+d\boldsymbol{\theta}))^{2}=\sum_{l,m}\mathcal{F}_{l,m}(\boldsymbol{\theta})d\theta_{l}d\theta_{m},$
(136)

where the distance

$\displaystyle\operatorname{Dist}_{K}(P_{c}(\boldsymbol{\theta}),$
$\displaystyle P_{c}(\boldsymbol{\theta}^{\prime}))=$ (137)
$\displaystyle\Bigg{(}\frac{\operatorname{Tr}\sqrt{\sqrt{P_{c}(\boldsymbol{\theta})}P_{c}(\boldsymbol{\theta}^{\prime})\sqrt{P_{c}(\boldsymbol{\theta})}}}{K}\Bigg{)}^{2}$

is defined as the fidelity between the normalized mixed states of projectors
$P_{c}(\boldsymbol{\theta})$ and $P_{c}(\boldsymbol{\theta}^{\prime})$.
Suppose the projector $P_{c}(\boldsymbol{\theta})$ has eigen decomposition

$P_{c}(\boldsymbol{\theta})=\sum_{j=1}^{K}|\psi_{j}\rangle\langle\psi_{j}|$
(138)

and denote the basis of its orthogonal complement as
$\\{|\psi_{j}\rangle\\}_{j=K+1,K+2,\dots,2^{n}}$, the QFIM under our framework
is of the form

$\displaystyle\mathcal{F}_{lm}(\boldsymbol{\theta})=2\frac{\partial^{2}}{\partial\delta_{l}\partial\delta_{m}}\operatorname{Dist}_{K}(P_{c}(\boldsymbol{\theta}),P_{c}(\boldsymbol{\theta+\delta}))|_{\boldsymbol{\delta=0}}$
(139) $\displaystyle=$ $\displaystyle\frac{2}{K^{2}}\sum_{\min{\\{i,j\\}}\leq
K}\frac{\operatorname{Re}\left(\left\langle\psi_{i}\left|\partial_{l}P_{c}\right|\psi_{j}\right\rangle\left\langle\psi_{j}\left|\partial_{m}P_{c}\right|\psi_{i}\right\rangle\right)}{\langle\psi_{i}|P_{c}|\psi_{i}\rangle+\langle\psi_{j}|P_{c}|\psi_{j}\rangle}.$

We remark that the derivation of QFIM for projectors is the same as for
density matrices [98]. Therefore, a similar formula can be used to compute the
QFIM of a VQC with mixed inputs/outputs.

Through sampling random parameters $\boldsymbol{\theta}$ from the interval
$[0,2\pi)^{N}$ and computing the QFIM, we can estimate the parameter dimension
$D_{c}$ by $\operatorname{rank}(\mathcal{F}(\boldsymbol{\theta}))$. The VarQEC
algorithm searches a $D_{c}$-dimensional submanifold of the complex
Grassmannian $\mathbf{Gr}(K,2^{n})$.

Figure 12: The bipartite connectivity graph for finding a quantum code with
parameters $((7,3,3))_{2}$. Qubits $Q_{0}$ and $Q_{1}$ are selected to prepare
the logical data. Figure 13:
$\operatorname{Rank}(\mathcal{F}(\boldsymbol{\theta}))$ versus the number of
VQC layers for the connectivity graph shown in Fig. 12. For code dimensions
$K=1,2,3,4$, the maximum ranks are $D_{c}^{\mathrm{max}}=254,504,750,992$, and
the required numbers of VQC layers to achieve overparameterization are
$L_{\mathrm{crit}}=10,21,31,41$.

Without loss of generality, we consider the connectivity graph shown in Fig.
12. For $K=1,2,3,4$, we randomly sample parameters $\boldsymbol{\theta}$ and
plot $\operatorname{rank}(\mathcal{F}(\boldsymbol{\theta}))$ as a function of
the number of VQC layers $L$ in Fig. 13. Almost no parameterized gate is
redundant when the circuit is underparameterized ($D_{c}/N\approx 1$). With
the increase of $L$, $\operatorname{rank}(\mathcal{F}(\boldsymbol{\theta}))$
increases approximately linearly until achieving its maximum
$D_{c}^{\mathrm{max}}$. The maximum parameter dimension for code length $n$
and code dimension $K$ is of the form

$D_{c}^{\mathrm{max}}=2K(2^{n}-K).$ (140)

This agrees with the fact that the dimension of the complex Grassmannian
$\mathbf{Gr}(K,2^{n})$ is $K(2^{n}-K)$ [101]. When
$D_{c}=D_{c}^{\mathrm{max}}$, the VQC can explore the whole
$\mathbf{Gr}(K,2^{n})$ manifold and prepare arbitrary $((n,K))_{2}$ quantum
code. The required number of layers to saturate the maximum parameter
dimension is approximately

$L_{\text{crit}}=\Big{\lceil}\frac{2K(2^{n}-K)-2n}{2n+|E(G)|}\Big{\rceil},$
(141)

where $|E(G)|$ is the number of edges of the connectivity graph.

To find a quantum code with parameters $((7,3,3))_{2}$, we sample $100$
different initial values of $\boldsymbol{\theta}$ and implement VarQEC with an
overparameterized VQC ($L=31$). However, the cost function
$C^{\ell_{1}}_{n,K,\mathcal{E}}(\boldsymbol{\theta})$ is always greater than
1. A $((7,3,3))_{2}$ code is improbable to exist.

##  Appendix D A variational quantum encoder for additive codes

The VQC with bipartite connectivity performs well in most cases. However, for
some code parameters (e.g., $((10,4,4))_{2}$), it needs a large bunch of
samples of the initial $\boldsymbol{\theta}$ to find an eligible code. Here we
propose AC-VQC, another variational quantum circuit with all-to-all
connectivity, to complement the bipartite ansatz.

The AC-VQC is especially resource-efficient in finding encoding circuits of
additive codes. The structure of an AC-VQC is similar to the circuit of the
quantum Fourier transform, as shown in Fig. 14. We start from two physical
qubits ($Q_{0},Q_{1}$) and apply a 2-qubit parameterized unitary operator
$U_{01}$ to them. Then, we add another qubit ($Q_{2}$), apply 2-qubit
parameterized unitary operators $U_{02}$/$U_{12}$ to the new one and each of
the qubits that already exist ($Q_{0}$-$Q_{2}$, $Q_{1}$-$Q_{2}$). Repeat the
steps until the system size equals $n$. In the end, we apply single-qubit
rotations $R_{z}$ and $R_{x}$ to all qubits to explore the manifold of locally
equivalent codes. The initial $k$ qubits prepare the logical data. The total
circuit depth is of order $\mathcal{O}(\sum_{j=1}^{n-1}j)=\mathcal{O}(n^{2})$.

Figure 14: Schematic of AC-variational quantum circuit with $n=5$, $k=2$.
Physical qubits are added layer by layer.

##  Appendix E Non-CWS Quantum Codes with Parameters $((6,2,3))_{2}$,
$((7,2,3))_{2}$

The $((5,2,3))_{2}$ code is known to be unique. However, the classification
and construction of $((6,2,3))_{2}$ and $((7,2,3))_{2}$ quantum codes are
unclear. Some are said to be “non-CWS” since they are not locally equivalent
to CWS codes. Here we present a general construction of non-CWS quantum codes
based on stabilizer ones.

###### Theorem 6

If there exists a quantum code $\mathcal{C}$ with parameters
$((n,2^{k},d))_{q}$, then there exist degenerate $((n^{\prime},2^{k},d))_{q}$
codes $\\{\mathcal{C}^{\prime}\\}$ with $n^{\prime}>n$ that are not locally
equivalent to a CWS code.

Proof  For $n^{\prime}>n+1$, we can directly obtain non-CWS codes by taking
the tensor product with a non-stabilizer state.

For $n^{\prime}=n+1$, we take the tensor product of the code $\mathcal{C}$
with a fixed (stabilizer) state, then apply a non-Clifford entangling unitary
operation to one of the original qudits and the additional qudit. This will
conjugate the Pauli-stabilizers to non-local stabilizers. The resulting code
is a non-CWS degenerate code with parameters $((n^{\prime},2^{k},d))_{q}$.
$\blacksquare$

For example, we start from the $((5,2,3))_{2}$ code ($Q_{0}$,$Q_{1}$,$\dots$,
$Q_{4}$) and initialize an addition qubit ($Q_{5}$) in state $|0\rangle$, then
apply the transformation $U$ on $Q_{5}$, controlled by $Q_{4}$ with

$U=\frac{1}{5}\left(\begin{array}[]{cc}3&4\\\ -4&3\end{array}\right).$ (142)

The resulting code is a non-CWS degenerate $((6,2,3))_{2}$ code with basis
states

$\displaystyle|\psi_{1}\rangle=$
$\displaystyle\frac{\sqrt{2}}{20}(5|000000\rangle-5i|001100\rangle-3i|010010\rangle$
(143) $\displaystyle+4i|010011\rangle+3|011110\rangle-4|011111\rangle$
$\displaystyle-3|100110\rangle+4|100111\rangle-3i|101010\rangle$
$\displaystyle+4i|101011\rangle-5i|110100\rangle-5|111000\rangle,$
$\displaystyle|\psi_{2}\rangle=$
$\displaystyle\frac{\sqrt{2}}{20}(3|00110\rangle-4|00111\rangle-3i|01010\rangle$
(144) $\displaystyle+4i|01011\rangle-5i|10100\rangle+5|11000\rangle$
$\displaystyle+5|100000\rangle+5i|101100\rangle+3i|110010\rangle$
$\displaystyle-4i|110011\rangle+3|111110\rangle-4|111111\rangle.\mkern 14.0mu$

Its weight enumerators are

$\displaystyle A(z)=$ $\displaystyle
1+\frac{9}{25}z+\frac{16}{25}z^{2}+\frac{311}{25}z^{4}+\frac{391}{25}z^{5}+\frac{48}{25}z^{6},$
(145) $\displaystyle B(z)=$ $\displaystyle
1+\frac{9}{25}z+\frac{16}{25}z^{2}+\frac{654}{25}z^{3}+\frac{193}{5}z^{4}$
(146) $\displaystyle+\frac{937}{25}z^{5}+\frac{594}{25}z^{6}.$

Likewise, non-CWS $((7,2,3))_{2}$ codes can be constructed based on
$((6,2,3))_{2}$ stabilizer codes.

Another class of non-CWS $((6,2,3))_{2}$ codes are unitarily related to the
additive $((6,2,3))_{2}$ code stabilized by

$\begin{array}[]{llllllllllllll}g_{1}&=&Y&I&Z&X&X&Y\\\ g_{2}&=&Z&X&I&X&I&Z\\\
g_{3}&=&I&Z&X&X&X&X\\\ g_{4}&=&I&I&I&I&Z&Z\\\ g_{5}&=&Z&Z&Z&Z&I&I.\end{array}$
(147)

Here “unitarily related” means they can be transformed to this code when
allowing permutations of qubits and a unitary transformation of the form
$U=\otimes_{j=1}^{5}U_{j}$ where $U_{1}$,$U_{2}$,$U_{3}$,$U_{4}$ are single-
qubit unitaries and $U_{5}$ is a 2-qubit unitary. In our numerical
experiments, all the $((6,2,3))_{2}$ codes discovered by VarQEC are unitarily
related to this $((6,2,3))_{2}$ stabilizer code or the $((5,2,3))_{2}$ perfect
code, some are related to both.

Consider a quantum code $\mathcal{C}$ that is capable of correcting an error
set $\mathcal{E}$. If linearly independent errors in $\mathcal{E}$ map
$\mathcal{C}$ to linearly independent subspaces, we say $\mathcal{C}$ is non-
degenerate with respect to $\mathcal{E}$. If linearly independent errors in
$\mathcal{E}$ map $\mathcal{C}$ to mutually orthogonal subspaces, we say
$\mathcal{C}$ is pure with respect to $\mathcal{E}$ [74]. A pure code must be
non-degenerate. For additive codes and CWS codes, “non-degenerate” and “pure”
are equivalent [74]. However, we note that some of our $((7,2,3))_{2}$ codes
are non-degenerate but impure. Here we give a “trivial” construction of non-
degenerate and impure $((7,2,3))_{2}$ codes. Still, we start with the
$((5,2,3))_{2}$ code on qubits $Q_{0},Q_{1},\ldots,Q_{4}$ and add two
additional qubits $Q_{5}$, $Q_{6}$ in a fixed state $|00\rangle$. Then we can
apply either a three-qubit unitary on, e.g., $Q_{4}$, $Q_{5}$, $Q_{6}$, or two
two-qubit unitaries on, e.g., $Q_{3}$, $Q_{5}$ and $Q_{4}$, $Q_{6}$. When
these unitaries are non-Clifford, the resulting code is a non-CWS degenerate
and impure code. We give a detailed example here. The following basis states
span a non-degenerate but impure $((7,2,3))_{2}$ code:

$\displaystyle|\psi_{1}\rangle=$
$\displaystyle\frac{1}{20}(-4\omega^{3}|0000011\rangle+3\omega^{2}|0000100\rangle-3\omega|0001110\rangle-4\omega|0001111\rangle+3\omega^{3}|0010110\rangle$
(148)
$\displaystyle+4\omega^{3}|0010111\rangle-4\omega|0011011\rangle+3|0011100\rangle+3\omega^{3}|0100110\rangle+4\omega^{3}|0100111\rangle-4\omega|0101011\rangle$
$\displaystyle+3\omega|0101100\rangle-4\omega^{3}|0110011\rangle+3\omega^{2}|0110100\rangle-3\omega|0111110\rangle-4\omega|0111111\rangle-4\omega^{3}|1000011\rangle$