Quantum Autoencoders via Quantum Adders with Genetic Algorithms
L. Lamata,1 U. Alvarez-Rodriguez,1 J. D. Martı́n-Guerrero,2 M. Sanz,1 and E. Solano1, 3

arXiv:1709.07409v1 [quant-ph] 21 Sep 2017

1

Department of Physical Chemistry, University of the Basque Country UPV/EHU, Apartado 644, 48080, Bilbao, Spain
2
IDAL, Electronic Engineering Department, University of Valencia,
Avgda. Universitat s/n, 46100 Burjassot, Valencia, Spain
3
IKERBASQUE, Basque Foundation for Science, Maria Diaz de Haro 3, 48011, Bilbao, Spain
The quantum autoencoder is a recent paradigm in the field of quantum machine learning, which
may enable an enhanced use of resources in quantum technologies. To this end, quantum neural
networks with less nodes in the inner than in the outer layers were considered. Here, we propose
a useful connection between approximate quantum adders and quantum autoencoders. Specifically,
this link allows us to employ optimized approximate quantum adders, obtained with genetic algorithms, for the implementation of quantum autoencoders for a variety of initial states. Furthermore,
we can also directly optimize the quantum autoencoders via genetic algorithms. Our approach opens
a different path for the design of quantum autoencoders in controllable quantum platforms.

Introduction.— Quantum machine learning is an
emerging field that aims at enhancing machine learning methods with quantum technologies [1–4]. The synergy works two-fold: either through genuine quantum
effects, such as entanglement, to speed up the calculations of machine learning [1, 2], or to employ classical
machine learning to improve quantum processes [5, 6].
In this respect, an advanced protocol has been considered, inspired in the classical autoencoder techniques of
deep learning [7], namely, a quantum autoencoder [8, 9].
Other topics related to biomimetic quantum technologies
in general, which have emerged in recent years, involve
quantum artificial life [10, 11], quantum reinforcement
learning in quantum technologies [12], quantum memristors [13–16], quantum Helmholtz and Boltzmann machines [17–19], and quantum machine learning with timedelay equations [20, 21].
A quantum autoencoder, see Fig. 1, is a quantum device which can reorganize the quantum information of a
subset of a Hilbert space spanned by a basis of initial nqubit states onto a subset of a Hilbert space spanned by
n0 < n qubit states. Therefore, in this way, one may encode the information into a smaller amount of resources,
which may be useful in different quantum technologies.
Quantum autoencoders, at variance with previous results
on compression of quantum information [22, 23], aim
at reshuffling the information to employ less resources,
similarly to defragmentation in classical computing. To
achieve this reordering, one may employ a feedforward
quantum neural network [8], which requires a smaller
amount of qubits in the inner layer than in the input and
output layers. Via gradient descent techniques, we can
optimize the intermediate transition unitary operations
between layers such that, for each input state, the output state has almost perfect overlap with it. Therefore,
the first part of the network (encoder), which reorganizes
the input states onto the inner layer of qubits, contains
the desired solution to the problem due to the discarding
of superfluous information. Classical autoencoders usually employ that useful information to make feasible the

|

1i

|

2i

M1
U1

|0i

M2
U2
M2

FIG. 1. Scheme of a 2-qubit quantum autoencoder as proposed in Refs. [8, 9]. It is based on a quantum neural network
where the outer layers (two-qubit input and output states)
contain one more qubit than the inner layer (single-qubit state
in between the unitary gates U1 and U2 ) and the former are
connected to the latter via the encoder U1 and the decoder
U2 . These operations are optimized, via, e.g., gradient descent techniques, with controllable parameters by means of a
classical feedback loop, in order that the output state maximizes the overlap with the input state. M1 is a dummy measurement, while M2 is a computational basis measurement on
the output two-qubit state that is employed to close the feedback loop. After convergence, U1 is the optimized encoding
operation.

training of deep neural networks.
In the last years, the design and implementation of
approximate quantum adders [24–32] has emerged with
unexpected connections. Recently, it was proven that
a quantum operation that adds two unknown quantum
states is forbidden in general [24, 25]. Since then, important results in optimized approximate or probabilistic
quantum adders have been analyzed, and in some cases
implemented, which may find applications to different
aspects of quantum technologies [24–32].
In this article, we propose and analyze a connection between a quantum autoencoder and an approximate quantum adder, see Fig. 2. The main insight in this respect is
the realization that, provided a perfect quantum adder, a
perfect quantum autoencoder and perfect quantum compressor would be attained. The reason for this is that,
given a hypothetical unitary operation U able to add

2

|

1i

|

2i

|0i

Memory1
Uautadd

Memory2

|

out i

⇠|

1i

+|

2i

FIG. 2. Scheme of our proposed 2-qubit quantum autoencoder. It is based on a 3-qubit device composed of an optimized approximate quantum adder operation Uautadd that
acts on the input states, |ψ1 i and |ψ2 i, as well as an ancilla
qubit |0i. The approximate quantum adding operation produces a state with large overlap to |ψ1 i + |ψ2 i, allowing for an
encoding of the initial 2-qubit quantum information subspace
into a single-qubit subspace, to a certain fidelity. The memory
units allow for maintaining entanglement of the three output
qubits and, after possible local operations on |ψout i, under
†
proper circumstances, to invert the encoding via Uautadd
.

two unknown quantum states, U |ψ1 i|ψ2 i ∝ |ψ1 i + |ψ2 i,
a trivial encoding would be produced. In this sense, U
would allow us to map the quantum information of tensor
products of two, or by iteration of n, single-qubit states
onto a single qubit. Then, in order to decode the state,
one would apply the inverse of U , i.e., U † , retrieving the
initial state. By linearity, this would also apply to superpositions of the initial entries. As proved in Ref. [24], an
ideal quantum adder is forbidden by the laws of quantum mechanics. Another complementary proof is given
by this connection, because if an ideal and universal nqubit quantum adder existed, reorganization, as well as
compression of quantum information from n-qubit states
to a single one would be feasible, which is clearly forbidden in general because of different Hilbert-space dimensionality and because it would violate Schumacher’s
theorem [22]. Despite this, one can employ the insight
obtained on approximate quantum adders optimized with
genetic algorithms [30] to propose quantum autoencoders
that rely on the previous optimization. A further possibility is to optimize the protocol of quantum autoencoders via genetic algorithms, using similar techniques
as in previous works [5, 30]. In this article, we will follow both approaches. We firstly consider a quantum autoencoder based on an approximate quantum adder that
adds perfectly the elements of the computational basis,
but non-perfectly the superpositions. Later on, we consider quantum autoencoders optimized with genetic algorithms that employ a restricted amount of gates and
in this context achieve also high fidelities.
A decomposition of approximate quantum adders in
terms of single and two-qubit gates can be obtained according to diverse criteria. Some adders may be obtained

by defining them to add optimally the computational basis states, and extended by linearity to superpositions
of these. Other quantum adders can be optimized by
genetic algorithms in the context of limited available
amount of gates. By employing the proposed protocol
of Fig. 2, we describe now how to implement a quantum
autoencoder based on each of these cases. For simplicity,
the unitary gate denoted as Uautadd in the figure will be
called U in the following example.
The basis quantum adder.— This quantum adder was
defined [24, 30] to perfectly add the basis states, and
approximately the superposition states, according to
U |000i = |000i, U |010i = |01+i, U |100i = |10+i,
U |110i = |001i, U |001i = |110i,
U |101i = |10−i, U |111i = |111i,

U |011i = |01−i,

(1)

where the first two qubits in the lhs are the addend states,
the third one is an ancillary qubit, and the last qubit
in the rhs is the outcome state of the addition. In the
protocol the initial ancilla is always the |0i state, but the
previous definition of the U quantum adder includes all
possible states for univocally defining the gate.
The fidelity of the quantum adder U is defined in terms
of the output state ρout as
F = Tr(|Ψid ihΨid | ρout ),

(2)
†

ρout = Tr12 (U |ψ1 ihψ1 | ⊗ |ψ2 ihψ2 | ⊗ |0ih0|U )

where |Ψid i ∝ |ψ1 i + |ψ2 i is the ideal outcome of the
sum, and the trace is taken over the first two qubits.
In Ref. [30], a subset of all possible input states were
considered in order to make the approximate quantum
adder consistent, namely, |ψi i, i = 1, 2 were defined as


cos θi
|ψi i =
,
(3)
sin θi
and the angles θi ∈ {0, π/2}.
The average fidelity of this region is 94.9%, while the
lowest fidelity is 85.4%.
Quantum autoencoder based on approximate quantum
adders.— We propose a quantum autoencoder based on
this approximate quantum adder following the scheme of
Fig. 2. For any input, two-qubit product state in the considered region defined by Eq. (3), i) apply the quantum
adder given by U onto this state and an ancilla |0i state,
ii) store the first two outputs onto quantum memories,
and employ the approximate addition of the input states
onto |ψout i for any desired quantum task, including quantum communication and single-qubit gates, iii) retrieve
the decoded, modified, two-qubit state via application of
U † onto the memory qubits and the output state. By
linearity, the protocol can be extended to superpositions
of the input states. A criterion that should hold for consistency is that the two memory qubits should be in the

3
same quantum state for the considered input states after the quantum adding operation. This way, the effect
of any local operation on the encoded |ψout ii that acts
differently on the latter for different i, where i refers to
the specific input |ψ1 ii |ψ2 ii state considered, can be efficiently retrieved onto the corresponding two-qubit gate
on {|ψ1 ii |ψ2 ii } via U † . For cases in which, for different
i, the memory qubit states differ, the encoding operation will work up to a certain fidelity, which will decrease
with the distance between these memory states and also
depend on the specific adding operation and input states.
We point out that in the case of a quantum autoencoder based on an approximate quantum adder, the usage of quantum memories for the output first two entries
is necessary. The reason is that the inverse operation
of the adder, U † , may retrieve the input two-qubit subspace with higher fidelity, as far as the |ψout i state is
controllably modified in the process. In order to map
an original two-qubit gate in the initial subspace onto
the single-qubit one, one has to encode it according to
the specific quantum adder employed. In the case here
proposed, for example, if one wants to apply a CPHASE
gate onto the inputs |00i and |11i, one would employ
the mapping of Eq. (1). Realizing that in this case both
memory qubits would take the same values for both input states, i.e., |00i, one would just need to apply a phase
gate on |ψout i to introduce a minus sign between |0i and
|1i single-qubit states. Later on, one would apply the
inverse adding operation, U † , retrieving the input states
with a minus sign on the |11i state, as corresponds to the
correct application of the CPHASE gate.
In general, the encoding of a desired two-qubit gate operation onto a single qubit gate in the compressed space
will depend both on the gate and on the subspace on
which it acts. Clearly, a two-qubit gate acting on the
complete two-qubit Hilbert space cannot be mapped onto
a single-qubit gate without losing information. But the
previous example can be useful to illustrate that, in some
cases, the complexity of a two-qubit gate implementation
may be reduced to a single-qubit gate. This may be useful, for example, if we have full availability of a universal quantum computer in some lab, where we can implement the quantum adder and store the memory qubits,
but only availability of single-qubit gates in some other
lab, to which we send the |ψout i qubit via a quantum
communication channel. Another possibility where this
approach can be useful is a situation in which one considers quantum information encoded in qudits but has only
access to single-qubit gates. In these cases, the encoding
via approximate quantum adders may also prove fruitful. This formalism could also be employed as a useful
transducer between a processing and a storage unit.
Quantum autoencoders via genetic algorithms.— As
pointed out above, approximate quantum adders can be
also optimized with genetic algorithms. Following the
previous approach for the basis adder, these quantum

adders can be also employed to define quantum autoencoders. The formalism of genetic algorithms allows one
to define the maximum number of gates in the desired
decomposition, as well as its structure of single- and twoqubit gates [5, 30]. Therefore, it can be useful for practical purposes in current or near future quantum implementations with trapped ions, superconducting circuits,
and quantum photonics, which employ a limited amount
of resources. In order to define a quantum autoencoder
via an optimized quantum adder, we propose to follow
the scheme on Fig. 2, where now the unitary gate Uautadd
will be given by the corresponding quantum adding operation.
An alternative approach is to directly optimize the
quantum autoencoders with genetic algorithms following the scheme of Fig. 1, instead of previously employed
optimization methods, e.g., gradient descent. An advantage of genetic algorithms is that local minima can
in principle be better avoided in some situations. The
first step is to design a function that relates the “genetic code” of each “individual” in the program to a specific autoencoder, either Uautadd or the pair of U1 and
U2 in the more general case. The genetic code is represented with a 3 × g matrix where g is the number
of gates. Accordingly, each row provides specific information about the gate to implement. The interaction
type and phase are encoded in the first two columns,
while the third one determines the qubit to act upon.
The universal set of gates we are working with is given
by single-qubit rotations and the Mølmer-Sørensen gate:
{Rx (θ), Ry (θ), Rz (θ), e−iσy ⊗σy θ/2 }. In each loop a new
generation is bred, where the individuals are hierarchically recombined, mutated and selected according to the
fidelity of the corresponding autoencoder. We have followed this approach for a certain set of cases via numerical simulations, and obtained consistent results. Namely,
when compressing a set of two-qubit states which contains at most two linearly-independent states, the compression is optimal and the protocol converges to fidelity one onto a single-qubit subspace. When trying
to compress four orthogonal two-qubit states onto two
single-qubit ones, a 50% average fidelity is obtained. For
three orthogonal states, an average fidelity of 2/3 is obtained. For non orthogonal four-qubit or three-qubit
states, the fidelity will be larger than for the corresponding orthogonal ones, the difference depending on the overlap with each other. More precisely, in order to test
the validity of our algorithm we have analyzed an optimized autoencoder for a nontrivial case involving a set
of three states: |ψi1 = cos π3 |00i + sin π3 |01i, |ψi2 = |01i,
|ψi3 = cos π8 |10i − i sin π8 |11i. We have achieved an average fidelity of 87.51% in the general case of U1 6= U2†
for a reduced number of gates. See the following quantum circuit diagrams for the specific decomposition of
the autoencoder in quantum gates. We point out that an

4
interesting feature of genetic algorithms is precisely that
they already provide the sequence of elementary gates
generating the solution.
|ψ1 i

Rx

|ψ2 i

Rx

MS

Rz

MS

Ry

|ψ1 i
|ψ2 i

(4)

Rz

MS
Rx

Rz

(5)
Ry

Rx

Here, Rx,y,z represent the single qubit rotations, while
M S is the Mølmer-Sørensen gate. The diagrams show
the type of obtained interactions, not specifying the
phases, for U1 and U2 respectively. The algorithm we
employed is a variant of a previous program [5, 30, 33].
In the following, we describe possible implementations
with trapped ions, superconducting circuits, and quantum photonics.
Trapped Ions.— In trapped-ion quantum platforms,
linear chains of ions are confined via electromagnetic
fields [34]. Both internal electronic states, and quantized
motional degrees of freedom, are available for quantum
control. The Hamiltonian describing the coupling between an ion and a laser, involving internal states and a
motional mode, in the Lamb-Dicke regime, is given by


H = ~Ωσ + 1 + iη ae−iνt + a† eiνt ei(φ−δt) + H.c. (6)
Here, σ + is the spin raising operator, η the Lamb-Dicke
parameter, Ω is the Rabi frequency, a and a† the motional
annihilation and creation operators, ν the trap frequency,
φ the laser field phase, and δ the detuning between the
laser and qubit frequencies.
In our proposal, each two-qubit state can be encoded
either in four metastable levels of a single ion or two
levels of a pair of ions, and an additional ion serves as
an ancillary qubit in the case of autoencoder with quantum adder. The necessary entangling gates can be implemented with Mølmer-Sørensen gates and sequences of
single-qubit gates [35], allowing us to implement our approximate quantum adders and therefore the quantum
autoencoders. The memory qubits can be stored in longlived internal electronic states.
Superconducting Circuits.— Superconducting circuits
are made of superconducting elements as microwave cavities, as well as nonlinear elements, i.e., Josephson junctions, which allow one to design effective quantum twolevel systems [36]. Via standard circuit quantization, one
often can obtain a Hamiltonian resembling the JaynesCummings model,
H = ωa† a +

ω0 z
σ + g(aσ + + a† σ − ),
2

(7)

where ω is the microwave mode frequency, g is the
photon-qubit coupling constant, and ω0 is the qubit frequency, which is encoded in the quantum excitations of
the effective two-level system.
Transmon qubits have long coherence times, and therefore they can be most appropriate for this kind of encoding. Entangling gates can be carried out with fidelities around 99%, e.g., via capacitive coupling, or via resonators, as in Eq. (7) when considering more than one
qubit. In Ref. [30], an optimized approximate quantum
adder obtained via genetic algorithms was carried out
experimentally in the IBM Quantum Experience processor, obtaining a good agreement with theoretical simulations. Therefore, it is expected that quantum autoencoders based on approximate quantum adders, or on direct optimization via genetic algorithms, may be achieved
with current technology.
Quantum Photonics.— Quantum photonic platforms
can be most appropriate for implementing quantum autoencoders via quantum adders, given that probabilistic
quantum adders have been already performed in some
photonic laboratories, e.g., Ref. [26]. In this quantum
platform, qubits may be encoded in polarization or dual
rail states, and gates performed via linear optics elements
in combination with ancillary qubits and detectors [37].
The fact that photons are the best quantum information
carriers for long quantum communication, makes them
interesting for implementing quantum autoencoders via
quantum adders and genetic algorithms, given that having to transmit a smaller amount of quantum information
through a quantum channel can save resources.
Conclusions.— We have proposed and analyzed a connection between approximate quantum adders and quantum autoencoders, which may be useful to reorganize or
compress quantum information while employing less resources. This connection allows one to implement optimized approximate quantum adders with genetic algorithms that are mapped onto quantum autoencoders, as
well as a direct optimization of quantum autoencoders
with genetic algorithms. The emerging field of quantum
adders enhances the paradigm of quantum autoencoders,
since the former have already been implemented in current quantum technologies [26–28, 30].
The authors acknowledge support from Spanish
MINECO FIS2015-69983-P, Ramón y Cajal Grant RYC2012-11391, UPV/EHU Postdoctoral Grant, and Basque
Government IT986-16.

[1] M. Schuld, I. Sinayskiy, and F. Petruccione, An introduction to quantum machine learning, Contemp. Phys.
56, 172 (2015).
[2] J. Biamonte, P. Wittek, N. Pancotti, P. Rebentrost, N.
Wiebe, and S. Lloyd, Quantum machine learning, Nature
549, 195 (2017).

5
[3] V. Dunjko and H. J. Briegel, Machine learning & artificial
intelligence in the quantum domain, arXiv:1709.02779.
[4] S. Arunachalam and R. de Wolf, A Survey of Quantum
Learning Theory, arXiv:1701.06806.
[5] U. Las Heras, U. Alvarez-Rodriguez, E. Solano, and M.
Sanz, Genetic Algorithms for Digital Quantum Simulations, Phys. Rev. Lett. 116, 230504 (2016).
[6] N. Spagnolo, et al., Learning an unknown transformation
via a genetic approach, arXiv:1610.03291.
[7] I. Goodfellow, Y. Bengio and A. Courville, Deep learning
(MIT Press, Cambridge, MA, USA, 2016), Chapter 14.
[8] K. H. Wan, O. Dahlsten, H. Kristjánsson, R. Gardner,
and M. S. Kim, Quantum generalisation of feedforward
neural networks, npj Quantum Information 3, 36 (2017).
[9] J. Romero, J. P. Olson, and A. Aspuru-Guzik, Quantum
autoencoders for efficient compression of quantum data,
Quantum Sci. Technol. 2, 045001 (2017).
[10] U. Alvarez-Rodriguez, M. Sanz, L. Lamata, and E.
Solano, Biomimetic Cloning of Quantum Observables,
Sci. Rep. 4, 4910 (2014).
[11] U. Alvarez-Rodriguez, M. Sanz, L. Lamata, and E.
Solano, E. Artificial Life in Quantum Technologies, Sci.
Rep. 6, 20956 (2016).
[12] L. Lamata, Basic protocols in quantum reinforcement
learning with superconducting circuits, Sci. Rep. 7, 1609
(2017).
[13] P. Pfeiffer, I. L. Egusquiza, M. Di Ventra, M. Sanz, and E.
Solano, Quantum Memristors, Sci. Rep. 6, 29507 (2016).
[14] J. Salmilehto, F. Deppe, M. Di Ventra, M. Sanz, and
E. Solano, Quantum Memristors with Superconducting
Circuits. Sci. Rep. 7, 42044 (2017).
[15] M. Sanz, L. Lamata, and E. Solano, Quantum Memristors in Optical Systems with Feedback, in preparation.
[16] S. N. Shevchenko, Y. V. Pershin, and F. Nori, QubitBased Memcapacitors and Meminductors, Phys. Rev.
Applied 6, 014006 (2016).
[17] M. Benedetti, J. Realpe-Gómez, and A. Perdomo-Ortiz,
Quantum-assisted Helmholtz machines: A quantumclassical deep learning framework for industrial datasets
in near-term devices, arXiv:1708.09784.
[18] M. Benedetti, J. Realpe-Gómez, R. Biswas, and A.
Perdomo-Ortiz, Estimation of effective temperatures in
quantum annealers for sampling applications: A case
study with possible applications in deep learning, Phys.
Rev. A 94, 022308 (2016).
[19] A. Perdomo-Ortiz, M. Benedetti, J. Realpe-Gómez, and
R. Biswas, Opportunities and challenges for quantumassisted machine learning in near-term quantum computers, arXiv:1708.09757.
[20] U. Alvarez-Rodriguez, L. Lamata, P. Escandell-Montero,
J. D. Martı́n-Guerrero, and E. Solano, Quantum Machine

Learning without Measurements. arXiv:1612.05535.
[21] U. Alvarez-Rodriguez, et al. Advanced-Retarded Differential Equations in Quantum Photonic Systems. Sci.
Rep. 7, 42933 (2017).
[22] B. Schumacher, Quantum coding, Phys. Rev. A 51, 2738
(1995).
[23] M. A. Nielsen and I. L. Chuang, Quantum Computation
and Quantum Information (Cambridge University Press,
Cambridge, UK, 2000).
[24] U. Alvarez-Rodriguez, M. Sanz, L. Lamata, and E.
Solano, The Forbidden Quantum Adder, Sci. Rep. 5,
11983 (2015).
[25] M. Oszmaniec, A. Grudka, M. Horodecki, and A. Wójcik,
Creating a Superposition of Unknown Quantum States,
Phys. Rev. Lett. 116, 110403 (2016).
[26] X.-M. Hu, et al. Experimental creation of superposition
of unknown photonic quantum states, Phys. Rev. A 94,
033844 (2016).
[27] K. Li, et al. Experimentally superposing two pure states
with partial prior knowledge, Phys. Rev. A 95, 022334
(2017).
[28] S. Dogra, G. Thomas, S. Ghosh, and D. Suter, Superposing pure quantum states with partial prior information,
arXiv:1702.02418.
[29] S. Sami and I. Chakrabarty, A note on superposition of
two unknown states using Deutsch CTC model, Mod.
Phys. Lett. A 31, 1650170 (2016).
[30] R. Li, U. Alvarez-Rodriguez, L. Lamata, and E. Solano,
Approximate Quantum Adders with Genetic Algorithms:
An IBM Quantum Experience, Quantum Meas. Quantum Metrol. 4, 1 (2017).
[31] G. Gatti, D. Barberena, M. Sanz, and E. Solano, Protected State Transfer via an Approximate Quantum
Adder, Sci. Rep. 7, 6964 (2017).
[32] M.-X. Luo, H.-R. Li, H. Lai, and X. Wang, Unified quantum no-go theorems and transforming of quantum states
in a restricted set, arXiv:1701.04166.
[33] L. D. Chambers, Practical Handbook of Genetic Algorithms (CRC Press, Boca Raton, FL, 1998).
[34] D. Leibfried, R. Blatt, C. Monroe, and D. Wineland,
Quantum dynamics of single trapped ions, Rev. Mod.
Phys. 75, 281 (2003).
[35] K. Mølmer and A. Sørensen, Multiparticle Entanglement
of Hot Trapped Ions, Phys. Rev. Lett. 82, 1835 (1999).
[36] M. H. Devoret and R. J. Schoelkopf, Superconducting
Circuits for Quantum Information: An Outlook, Science
339, 1169 (2013).
[37] E. Knill, R. Laflamme, and G. J. Milburn, A scheme for
efficient quantum computation with linear optics. Nature
409, 46 (2001).

