Exploring Quantum Computing for Machine Learning
Transcript of Exploring Quantum Computing for Machine Learning
1
Exploring Quantum Computing
for Machine Learning
Istvan Barabasi, Charles C. Tappert, Daniel Evans, and Avery M. Leider
Seidenberg School of CSIS, Pace University, Pleasantville, New York 10570
{ibarabasi, ctappert, devans, aleider}@pace.edu
Abstract—(This paper explores the use of quantum computing
for solving machine learning problems more efficiently. Today’s
quantum computers are rather primitive, so only relatively small
machine learning problems can be solved at this time.
Nevertheless, the machine learning problems described here that
have been solved on quantum simulators or actual quantum
computers indicates the potential power of quantum computers
for solving computationally intensive machine learning problems
such as the deep learning multi-layer neural networks.
Keywords—machine learning, quantum computing, deep
learning, quantum machine intelligence
I. INTRODUCTION
There is currently considerable interest in quantum computing.
In the U.S. in January 2019, the National Quantum Initiative
Act authorized $1.2 billion investment over the next 5-10 years
(Rep Smith, 2019). A quantum computing race is ongoing
among the tech giants Google, IBM, and Microsoft, Amazon,
and China’s Alibaba. IBM emphasizes heavy usage on their Q
Experience quantum simulator with more than 90,000 users
who have run 5,000 experiments and published 110 papers. Governments, particularly America and China, are funding
work in the area with the concern that quantum-computers may
soon become large enough to crack current encryption
methods, giving the country that gets there first a major
advantage (Economist, 2018). At the 2019 Consumer
Electronics Show, IBM announced for sale – or, more
accurately, calculation time on it – the IBM Q System One, the
world's first commercial quantum computer (IBM, 2019b).
In MIT News, a recent article interviewed William Oliver, the
principal investigator in both the Engineering Quantum
Systems Group at MIT and the Quantum Information and
Integrated Nanosystems Group at MIT Lincoln Laboratory. He
noted that MIT’s quantum computing effort was being
inhibited by a shortage of quantum knowledge workers
(Leddy, 2019). To fill this gap Pace University in teaching
quantum computing at the PhD and advanced Master’s level,
in particular teaching the students how to become software
developers for these quantum computers, and has even started
experimenting with a high school level orientation course.
In the following sections, this paper provides a background for
readers not familiar with quantum computing, describes early
work on using quantum computers for machine learning,
discusses the new area of quantum machine intelligence,
describes additional quantum machine learning algorithms,
presents the methodology our students used to implement
quantum programs, describes in detail programs coded and run
by our faculty and students on quantum simulators or actual
quantum computers, and finally draws conclusions and
indicates future work.
II. QUANTUM COMPUTING BACKGROUND
For the reader unfamiliar with quantum computing, we provide
some background material as an introduction to the concepts
discussed in this paper (Evans, 2019). Others may wish to skip
this section.
Although quantum programs can be written in a quantum
programming language, they are often shown in a circuit
diagram (Fig. 1). The circuit diagram is close to universal in
the field, and concisely represents quantum computing
concepts.
Fig. 1: A Quantum Circuit: A Hadamard Gate followed by a
Conditional NOT Gate and Measurements.
Circuit diagrams are stacked horizontal lines (wires) with
various connections between them (Fig. 1). Each single wire
line represents a single qubit, a quantum state. Double wire
lines represent classical bits. Circuits are read from left to right
corresponding to the sequential execution of the gates in the
circuit, and to the movement of time. Gates are rectangles,
labeled for the type of gate, although some common gates, like
Conditional NOT, have special representations. Measurement
sets a classical bit from a qubit. Measurement is indicated in a
quantum circuit by a meter symbol, and usually appears at the
end of the circuit. Elements that are vertically aligned are
considered to happen simultaneously. Qubits operands are read
from top to bottom in the circuit. Individual qubit lines are
named on the left, with optional initial values. The final results
Funded, in part, by an IBM faculty award.
2
are shown in labels on the right. See the tensor product
description below for how qubits are combined in a circuit.
The data of quantum computing is the qubit, representing a
quantum state. A single qubit is a probabilistic combination of
its basis states, |0⟩ and |1⟩. The bracket notation derives from
quantum mechanics, and is an abstraction of subatomic
characteristics related by uncertainty. Mathematically, a qubit
𝜓 is a vector 𝜓 = 𝛼|0⟩ + 𝛽|1⟩ . The values of 𝛼 and 𝛽 are
limited by the probability relation |𝛼|2 + |𝛽|2 = 1 . When
measured, a qubit's state will be 0 with a probability of |𝛼|2 or
1 with a probability of |𝛽|2 . The coefficients 𝛼 and 𝛽 are
complex numbers, 𝛼 = 𝑎0 + 𝑎1i and 𝛽 = 𝑏0 + 𝑏1i . The
magnitude of a complex number is real, so the probabilities
represented by 𝛼 and 𝛽 are real numbers. If either 𝛼 or 𝛽 is 1,
the other must be 0. A qubit with only a single non-zero basis
coefficient is a pure qubit – for example, 0 ⋅ |0⟩ + 1 ⋅ |1⟩ = |1⟩. A qubit with neither coefficient equal to 1 is said to be in
superposition and will be probabilistically 1 or 0 when
measured. Measurement collapses the probabilistic quantum
state into one of its pure states: the probabilistic information is
lost, and subsequently, the qubit always measures in that
collapsed state.
Qubits are manipulated by quantum gates, representing
quantum state transformations. Mathematically, gates are
modeled by square matrices that satisfy the conditions of
unitarity. The application of a gate to a qubit is equivalent to
matrix multiplication of the qubit by the gate matrix.
Multiplication by a unitary matrix preserves the magnitude of
the vector, and thus the probability relation.
Although there are an infinite number of quantum gates,
arbitrary gates can be composed using only a small set of gates
as building blocks. This is analogous to classical computing
where, for example, AND, OR, and NOT gates form a universal
basis for building any classical circuit.
One of the postulates of quantum mechanics states that "The
state space of a composite physical system is the tensor product
of the state spaces of the component physical systems" (Nielsen
& Chuang, 2010). Among other things, this means that the
tensor product is used to match smaller qubit gates to larger
qubit operands, and vice versa. Specifically, the tensor product
|0⟩ ⊗ |0⟩ = |00⟩ creates a two qubit operand from two one-
qubit operands. In general, a two qubit quantum state is
represented by a vector 𝜓2 = 𝑎00|00⟩ + 𝑎01|01⟩ + 𝑎10|10⟩ +𝑎11|11⟩. The probability relation must hold, |𝑎00|
2 + |𝑎01|2 +
|𝑎10|2 + |𝑎11|
2 = 1. When a gate is applied to a qubit operand,
the qubit is represented as a column vector, with the basis vector
order implied by the binary numerical order. The dimension of
the general single qubit vector 𝜓 is 2 × 1. The dimension of
the two-qubit vector 𝜓2 is 4 × 1. As the number of qubits in an
operand increases, the dimension increases by a power of 2.
The tensor product reflects this because it multiplies
corresponding dimensions. The tensor product of a two qubit
quantum state (4 × 1) and a one-qubit quantum state (2 × 1) is
a three-qubit (8 × 1) quantum state. Similarly, a quantum gate
can be extended by a tensor product of the gate and the identity
matrix. A single-qubit 2 × 2 gate matrix tensor product with
the 2 × 2 identity gate matrix will create a 4 × 4 two-qubit
gate. In a quantum circuit diagram, tensor products are implied
when it is necessary to match gate and qubit dimensions.
With the foregoing information and a knowledge of the relevant
quantum gate matrices, the operation of the quantum circuit
(quantum program) in Fig. 1 can be modeled by the equation:
𝐶(|0⟩ ⊗ 𝐻(|0⟩)).
1. Apply the H-gate to the |0⟩ qubit on the first wire
1
2 1 11 −1
10 =
1
21
2
2. Expand the single qubit result to a 2-qubit operand using
the tensor product with the value on the second wire
1
21
2
⊗ 10 =
1
2
01
2
0
3. Apply the Conditional NOT gate to the result
1 0 0 00 1 0 00 0 0 10 0 1 0
1
2
01
2
0
=
1
2
001
2
4. The 2-qubit output is the vector, 1
2|00⟩ +
1
2|11⟩ .
When measured, it will yield 00 50% of the time and 11
50% of the time. Note that |1
2|2 + |
1
2|2 = 1.
The result is known as a Bell state, after the physicist John Bell,
and represents entangled qubits. With entangled qubits, the
measurements are correlated, even if the qubits are separated.
Entanglement is the basis for "quantum teleportation", what
Einstein famously called "spooky action at a distance." It
underlies such algorithms as quantum key distribution. One
may wonder at the usefulness of the probabilistic behavior of a
quantum program such as Fig. 1. The following sections show
a number of quantum computing applications that intersect
machine learning.
III. EARLY THEORETICAL ADVANCES AND EXPERIMENTS USING
QUANTUM COMPUTERS FOR MACHINE LEARNING
During 2018, Google published early articles about machine
learning algorithms using Quantum Neural Networks:
Classification with Quantum Neural Networks on Near
Term Processors by Edward Farhi1,2 and Hartmut Neven1
Barren plateaus in quantum neural network training
landscapes by Jarrod R. McClean1, Sergio Boixo 1, Vadim
N. Smelyanskiy1, Ryan Babbush1 & Hartmut Neven1
3
Fig. 2. Google’s approach to QNNs, where in contrast to hidden
layers in classical deep neural networks, the boxes represent
entangling actions, or “quantum gates”, on qubits
In March 2019, IBM and Intel reported breakthrough
experiments using quantum algorithms for deep learning.
IBM announced the development of QC4ML algorithms
which “demonstrate how noisy quantum computers can
solve machine learning classification problems that
classical computers cannot”
Intel reported about “mathematically proven that artificial
intelligence can help us understand currently unreachable
quantum physics phenomena”, publishing Quantum
Entanglement in Deep Learning Architectures. Within this
article, Intel confirms that “highly entangled many-body
wave functions can be efficiently represented by deep
learning architectures, such as convolutional neural
networks (CNNs) and recurrent neural networks (RNNs).
IV. QUANTUM MACHINE INTELLIGENCE
Quantum machine intelligence is a new approach to artificial
intelligence and machine learning. Machine learning and
quantum computing are two technologies that have substantial
impact on how we use computer science to solve artificial
intelligence problems. Based on a new study by IBM and MIT
researchers, quantum computing can extend how to apply
computation to solve complex machine learning problems
more efficiently at a fraction of time. Classical computers use
kernel methods for common pattern recognition algorithms,
such as for example implementing support vector machines
(SVMs) to solve classification problems. When SVM
considered feature space becomes large, kernel methods will
become computationally expensive. Such algorithms can be
efficiently speeded up by mapping out the combinations of
these features into a “feature space” represented via
exponentially large number of quantum states of a multi-qubit
quantum computer.
Using quantum-enhanced feature space, efficiently
implemented on quantum computers enables quantum
advantage for efficiently solving considerable number of
machine learning problems. Here are two examples for
quantum enabled machine learning.
A. Variational Quantum Classifiers (VQC)
VQC implemented using variational quantum circuits can
classify data with complex features set in a similar wat as
conventional SVM methods. It optimizes a parameterized
quantum circuit to provide a solution that cleanly separates the
data.
Fig. 3. MIT and IBM researches implemented a sample VQC
algorithm on IBM’s 5-Qubit machine (Supervised learning with
quantum-enhanced feature spaces)
Our students performed multiple tutorials for VQC classifier,
using platforms from IBM and Xanadu.AI:
IBM Quantum Computer with Qiskit SDK: students
reviewed the VQC tutorial for breast -cancer images
classification and evaluated its applicability for a 2018
Chest Xray Images Classification Project previously
implemented classically using neural networks and
Tensorflow.
Xanadu.AI PennyLane Platform: students reviewed the
VQC tutorial for IRIS dataset classification and
implemented it via GPU simulator on Google Colab.
B. Quantum kernel estimator or Quantum Support Vector
Machine (QSVM)
QSVMs estimate kernel functions on quantum computers and
optimizes a classical SVM. Solves classification problems that
require a feature map for which computing the kernel is not
efficient classically. QSVM solves the problem by performing
direct estimation of the kernel within the quantum feature
space.
Students reviewed the IBM Qiskit QSVM tutorial for
breast-cancer images classification and compared
results with earlier tutorial results that used VQC.
Giovanni Acampora from University of Naples Federico II,
Italy, launched the first journal dedicated to Quantum Artificial
Intelligence. The section named Quantum Machine Learning,
edited by Seth Lloyd from MIT, publishes papers about
quantum implementation of ML algorithms such as quantum
perceptrons, quantum neural networks, and quantum clustering.
According to Giovanni, within the last 8 year there was a 4x
growth within the number of papers published in the area of
quantum machine intelligence, with the biggest jump of
approximate 2x in 2018.
4
Fig. 4. Number of published quantum machine intelligence papers.
This journal published a number of interesting articles in the
area of applying Quantum Computing for Machine Learning
(QC4ML), such as for example:
Bayesian deep learning on a quantum computer by
Zhikuan Zhao, Alejandro Pozas-Kerstjens, Patrick
Rebentrost, with sample code for IBM and Rigetti
Quantum Computers, that can be implemented and
tested with students during class (see tutorial).
A hybrid machine learning algorithm for designing
quantum experiments by L. O’Driscoll, R. Nichols, P.
A. Knott, with an implemented example of a neural
network for classifying quantum states, with sample
code for classifying quantum states of lights via
QuTIP framework.
Fig. 5. Neural network for classifying quantum states
V. ADDITIONAL QUANTUM MACHINE LEARNING ALGORYTHMS
A. Quantum KNN (QKNN) Algorithm
Classic K Nearest-Neighbor algorithm has high complexity,
because similarity computing and searching are time-
consuming. This becomes challenging when the number of
images to be classified is high. Within “Image Classification
Based on Quantum KNN Algorithm” article, Dang at.al.
proposed a QKNN where complexity is only quantum
algorithm is only .
Fig. 6. High-level architecture of the proposed QKNN solution.
B. Quantum K-Means (QKM) Algorithm
Quantum Computing can be used for distance estimation
within k-means clustering. Shan Jin, Xi He, Xiaokai Hou, Li
Sun, Dingding Wen, Shaojun Wu and Xiaoting Wang from
University of Electronic Science and Technology of China,
designed a quantum circuit below or Euclidian distance
calculation and implemented it using IBM Qiskit:
Fig. 7. Quantum K-Means circuit to find the Euclidian distance.
C. Quantum Generative Adversarial Networks (qGANs)
GANs represent a class of algorithms that employ two neural
networks - a generator and a discriminator - to solve a
generative task, namely the creation of random samples of a
distribution that is implicitly given by the training data. As
shown in Fig. 8:
The generator creates data samples which appear to be
indistinguishable from the training data.
The discriminator tries to differentiate between the
generated samples and the training samples.
The generator and discriminator are trained alternately.
Fig. 8. Generative Adversarial Network.
5
qGAN use a quantum generator and a classical discriminator to
capture the probability distribution of classical training
samples. A quantum channel, i.e., the quantum generator, is
trained to transform a given n-qubit input state |ψin> to
an n-qubit output state, where describe the resulting
occurrence probabilities of the basis states |j>.
IBM Qiskit SDK provides a tutorial for applying qGANs in
Financial Industry for Options Pricing.
VI. IMPLEMENTING ALGORITHMS ON QUANTUM COMPUTERS
Our quantum computing graduate course has student projects
that utilize hands-on labs with simplified quantum program
development, live code executions and student projects
performed using IBM’s Quantum Experience Platform with
access to real Quantum Computers (Tappert, et al., 2019). We
use the IBM Cloud to connect to the IBM Q Network with live
quantum computers in the USA as well as in Japan, Australia,
and Spain.
We used multiple Quantum Computing Science Kits to teach
students quantum computing technology. The objective was to
help the students to gain practical experience via lab exercises
and to develop projects to solve relevant and practical
problems using quantum computing algorithm and programs.
While initially we used Watson Studio within IBM Cloud, we
later deployed a simplified shared development platform based
on an integrated JupyterHub/JupyterLab virtual machine
running within a public cloud service.
A. QC Science Kits
These QC Science Kits include:
• IBM contributed and moderated community project
Quantum Information Science Kit (Qiskit) available at
https://github.com/Qiskit
• Quantum Toolbox in Python (QuTIP) moderated by
QuSTaR (www.qustar.org)
• Investigated Rigetti’s SDK package, with focus on its
Python pyQuil package and Quantum Virtual
Machine (QVM), which is an open-source implementation
of simulator as a quantum abstract machine (QAM) using
classical computer hardware.
In addition to Quantum Computers, we used multiple Quantum
Computing simulators provided by IBM: • The 32-qubit IBMQ-QASM-Simulator via IBM Cloud
• Custom deployed HPC-Quantum-Simulator and made it
available for students with the goal to help them avoid job-
queue wait times for having their code be processed by
IBMQ devices. We have custom implemented this
simulator using a large-size virtual machine, available
24/7 for students use. Local simulators available within Qiskit, such as simplified
traditional simulator and the experimental release of the Qiskit Aer high-performance circuit simulator framework
B. JupyterHub
The benefits of using the JupyterHub type deployment of the
teaching environment were the following: • Leveraged enhanced IDE using JupyterLAB and a number
of extensions, such as Google Drive, Github and other
plugins.
• We have pre-installed multiple Quantum Computing
Science Kits, such as Qiskit, QuTIP and others.
• We have pre-installed additional required python libraries,
such as matplotlib draw, LaTex draw, IBMQ provider,
PDF exporters and other circuit visualization add-ons.
• Simplified faculty’s work to assist and help students with
their Jupyter notebooks, python programs and code
artifacts. This platform empowered students become self-
sufficient with QC science kits, creating quantum circuits
and developing programs for implementing specialized
algorithms in context of the studied class topics.
C. IBM Composer
The benefits of IBM Composer used with the high school
teaching environment were the following: • IBM Composer is all on the web, so it took only the one
step of having the high school technical support security
policy decision maker to make the URL available. The
students could get hands-on with the tool right away after
IBM registration, which took only minutes.
• IBM Composer includes descriptions of the gates,
includes QASM, and includes a diagram of the
arrangement of the qubits in the quantum computer being
programmed. The User Interface is intuitive, at least, to a
high school student. Well-placed error messages, such as
a reminder to save the program before running it, pop-up
to assist. Quantum programs written in IBM Composer can be run on either real quantum computers or on the simulator. Sometimes at periods of high traffic, the real quantum computers delayed giving their results by a few hours or even a day. Also, on common programs (such as those following the online IBM Composer tutorials), an option to accept the results of previous identical code that was run on the quantum computer, that is still in cache, will be offered. Simulator results are instantly delivered. For the classes given to the high school students, running the programs on the real machine were limited to where it made a significant difference in the results, such as Grover’s Algorithm. The simulator also offers a range of configuration options and that can be designed by the student to try different ideas.
The layout of the Composer is shown in Fig. 9 and the user can
select whether to run the program on the simulator or on one
of the real quantum computers that IBM has made available.
6
Fig 9. User interface of the IBM Composer.
The quantum registers with the qubits in them are listed on the
left side, initialized with zero kets, 0 , which is the ground
state of a qubit. The qubits are also depicted in relationship to
each other on the actual quantum circuit chip in the diagram in
the upper left side of Fig. 9. The gate selection menu on the
lower right hand side is where the programmer chooses the gate
they need and drags it onto the appropriate wire in ‘the score’.
The selection buttons, for running the program on either the
simulator or the actual quantum computing machine are on the
right hand side above the gate selection area. The system on
which to run the program is selected after the program has been
built, named, and saved.
After this orientation, the students went hands-on. The students
ran programs demonstrating the X gate which is the quantum
equivalent to the classical NOT gate. If the qubit is in a ground
state with value 0, then putting it through an X gate flips it into
the 1 state, the activation state, and vice versa. Students
reviewed the results – the zeros and ones – which were read
from right to left, as if they were Chinese characters. Also
important was the understanding that the results in a quantum
program are delivered in probabilities. Quantum programming
does not deliver exact results, so each quantum program is run
many times in order to give a probability distribution. On a
simulator, a program might be run 100 times to give a good
result, whereas on the real machine, it may take 1,024 or more
executions to give a reasonable distribution.
The hands-on portion of the class was to make 6 CNOT
connections in the IBM Composer, use X gates (X gates flip
values from zero to one and one to zero), to predict their
answers, and run the program. To do this, the students had to
study the diagram that accompanies the programming interface
of the Composer, to identify legitimate paths for entanglement
of qubits, see Fig. 10. A legitimate path of qubit entanglement
goes from qubit 1 to qubit 0 or 2 or from qubit 3 to qubit 4 or
2. An attempt to put a CNOT gate between other combinations
of qubits, such as between 1 and 3, will not be allowed and in
the Composer, the disappearance of the incorrect CNOT from
the program.
Fig. 10. Five Qubit IBM Quantum Computer.
VII. SUMMARY OF MACHINE LEARNING ALGORITHM
IMPLEMENTATIONS ON QUANTUM COMPUTERS
The following subsections contain descriptions of the quantum
computer programs implemented and run by our students and
faculty on the IBM quantum simulator.
A. Quantum War (Barabasi, et al., 2019)
The first programming example is the quantum version of the
children’s card game “War.” This program demonstrates a
practical application for the quantum principle of superposition,
and it shows how a small number of qubits can do the work of
many classical bits. It also illustrates how to create and measure
two quantum circuits.
To play the game, a deck of playing cards is divided evenly
among two players, then each player simultaneously draws a
card and the player with the card of the highest order wins the
battle and claims the losing player’s card. The first player to
run out of cards loses. After drawing, the cards are removed
from the deck. Traditionally, the rules of War state that the
losing player’s cards are added to the winning player’s deck.
This study has opted to forego this portion of the rules to keep
the example simple for those first learning about quantum
programming. For simplicity, this program also omits the three
card WAR draw for a tie.
A traditional deck of cards contains fifty-two unique cards. A
classical computer requires 312 bits (six bits per card times 52
cards) to represent all fifty-two card options simultaneously. In
contrast, a quantum computer requires only 6 qubits to
represent the 52 cards by using the principle of superposition, a
linear combination of both |0⟩ and |1⟩. This means that the qubit
represents all possible values simultaneously. Thus, six qubits,
all in a state of superposition, represent all fifty-two
possibilities when drawing from a deck of playing cards.
This study slightly modifies the rules of War to illustrate more
fully the quantum principles at play. Each player plays with a
full deck of fifty-two cards. Each deck is represented by six
qubits, twelve qubits in total.
The program begins with two classes that are used to keep track
of the cards in each player’s deck. The Card class holds
information about each playing card including, the suit, name,
and value of the card. The Deck class contains logic for creating
a deck of cards containing 52 cards with values 2-10, Jack,
Queen, King and Ace with suits Clubs, Diamonds, Hearts, and
7
Spades. It also contains the logic for drawing a card and
removing it from the deck.
Following the class definitions, the user chooses to run the
program on a local quantum simulator or IBM’s IBMQX5, a 16
qubit chip. The simulator runs faster than making a connection
to the IBMQX5 and is guaranteed to produce a result. Due to
high volume of usage, a request to use the IBMQX5 can
sometimes timeout.
Next, the program creates two quantum circuits to represent
each deck. Each circuit contains six qubits. All six qubits have
an H gate applied to them to induce a state of superposition.
This allows the six qubits to represent any of the 52 cards in the
deck. The program now contains two quantum circuits, each of
which represents a deck of 52 playing cards.
Next, the battle between players begins. Player One's quantum
circuit is measured. This represents drawing a card from the top
of the deck. Then, player Two's quantum circuit is measured.
The measurement returns the probability of drawing any one of
the 52 cards from the top of the deck. The card drawn is
determined by the measurement taken of the state of the qubits.
The six qubits representing each deck are measured 1024 times.
Each measurement is referred to as a “shot”. In a single shot,
the probability that a qubit is equal to |0⟩ or |1⟩ is measured and
recorded. After all 1024 shots, a dictionary is returned that
contains the number of times all sixty-four combinations of the
six qubits were measured. The value between 000000 and
110011 that is measured with the highest frequency
corresponds to the card that the player drew. The drawn card is
then removed from the deck and cannot be drawn again.
Finally, python logic compares the two cards and determines a
winner for the battle.
The program then presents the players with the cards that they
drew and the likelihood that the qubits represented that card at
the time of measurement. The likelihood is calculated by
dividing the number of times the value was measured by the
total number of shots and represented as a percentage in the
output. Sample output is presented in Fig. 11.
Fig. 11. Player 1 drew the 3 of Clubs, measured in 2.73% of the
shots. Player 2 drew the 6 of Spades, measured in 2.34% of the shots.
The program is successfully able to simulate a truly random
event. In classical computing, random functions are usually
pseudorandom. The functions must be seeded with the date and
time or other information to produce a result that seems random
but is not actually random. In contrast, the behavior of the
qubits is truly unpredictable. Thus, when measuring qubits to
represent a real world activity, such as drawing a card from a
shuffled deck, the result is truly random. The card game
simulation employs qubits in a practical situation that requires
truly random results.
B. Random Password Generator (Barabasi, et al., 2019)
The second programming example is the quantum version of a
random password generator. This program demonstrates how
to use superposition to generate ASCII characters. It also shows
how a small number of qubits can do the work of many classical
bits and uses a practical example to increase user engagement.
It also shows how to use a single measurement to get multiple
results and illustrates how to account for noise when measuring
a quantum circuit.
This program uses a quantum circuit to create a truly random
password using English ASCII characters. The program uses an
8 qubit quantum circuit to generate a variable length random
password. A single ASCII character, represented on a classical
computer, uses 8 bits. In the classical implementation, 8 bits
represents a single character, and only that character. In order
for the classical machine to represent a different character, the
value of one or more bits must be changed or more bits must be
used. The quantum implementation can utilize superposition to
create multiple characters using only 8 qubits by measuring
each qubit multiple times. Thus, the quantum circuit represents
all ASCII characters simultaneously when in a state of
superposition.
The quantum computer has two advantages over the classical
computer when it comes to password generation. The first
advantage is that because quantum computers use qubits with
superposition, they can generate longer passwords in less time
than a classical computer. The second advantage is that the
quantum computer is capable of generating a truly random
password while the classical computer is not. While the
classical computer utilizes pseudorandom functions to produce
results that seem random, only qubits can produce truly random
results. As with the Quantum War program, the motion of
quantum particles is unpredictable. Thus, using qubits can
produce a password that is truly random and thus stronger than
a random password generated on a classical computer.
The program begins by creating an 8 qubit quantum circuit.
Next, the program uses gates to set the qubits to the proper
states for execution. All English ASCII characters begin with
the leading bits 01. The following six bits are variable and can
be set to either 0 or 1 depending on the character being
represented. Thus, to represent an ASCII character with qubits,
the leading two qubits, qubits 7 and 6, must be set to 0 and 1
respectively. These values must not change during the
execution of the program or non-English characters will appear
in the results. The program achieves this by leaving qubit 7 in
its initialized state of 0 and using an X gate to set qubit 6 to 1.
Next, qubits 0 through 5 are put into a state of superposition
using H gates.
When all eight qubits are set to the correct values, the program
measures the quantum circuit. This determines the characters
that are used to generate the password. By measuring the qubits,
the program can determine the probability that they represent a
particular character at the time of measurement. The eight
8
qubits representing a single character are measured in 1024
shots. Each shot is a single measurement that represents a single
character. After all 1024 shots occur, Qiskit returns a dictionary
that contains the frequency that each character was measured.
Fig. 12 shows the dictionary representation of the measurement
results.
Fig. 12. Dictionary excerpt of character frequencies measured in
1024 shots: binary representation of the character (left), number of
shots (right). The first dictionary character ‘01101110’ is ‘n’.
Because Quantum measurements can be noisy, the program
must also account for noise in the measurement. Noise is
unintended environmental interference that may distort the
results of a measurement. To account for this, the program
eliminates all results that were measured in less than 2% of
shots. The 2% noise threshold is recommended in several Qiskit
examples. The program assumes that any character which
appears in greater than 2% of shots is a legitimate qubit value
and not noise. The results of 1024 shots are displayed in Fig.
12. The character ‘01101110’, the character ‘n’, was measured
in 13 shots. To determine if the character ‘n’ was actually
measured or is the result of noise, the program divides 13 by
1024 which equals 0.0127. Since the character ‘n’ only
appeared in 1.2% of shots, it is indistinguishable from noise and
thus is not included in the password. This noise threshold check
is performed for each measured character. All characters that
the program measures in more than 2% of shots are added to
the password.
Because the program accounts for noise, the final length of the
password is variable. Generally the password is between six to
eight characters but may be longer or shorter. This is due to the
random nature of qubits and the fact that noise can distort
measurements. Sometimes the measurement frequency of a few
characters rises above the noise threshold. Other times, ten or
more characters may be measured over 2% of the time. Fig. 13
shows three sample passwords generated by the quantum
program. Each column represents a single password. On the
left, is the character and on the right the percentage of shots that
it was measured in. Running the program multiple times will
predictably produce varied results.
Fig. 13. Three output examples: each password character is displayed
vertically with the probability that the character was measured. The
passwords are variable length depending on how many characters
were measured more than 2% of the time to account for noise.
This program can create randomized passwords that meet
acceptable password guidelines. The passwords are truly
random, use upper and lowercase English characters and most
commonly used special characters. Similar to the last program,
it illustrates the concepts of superposition and uses qubits to
represent multiple outcomes simultaneously. In addition to
having real world application, the combination program can
also help students understand intermediate quantum concepts
like noise, H gates and X gates.
C. Traffic Optimization Problem (Barabasi, 2018)
The Traffic Optimization Problem (TOP) we try to resolve can
be defined as a modified TSP problem, where the driver of the
car must traverse the shortest set of segments (streets or blocks
in a city), which have the lightest traffic to get to the destination.
It can be considered as a modified MaxCut problem as well.
We are looking for an algorithm is to converges fast and require
minimum set of operations, in order to be able to perform the
optimization in real-time many times for each driver. Such an
algorithm could be implemented as part of Navigator Apps and
launched from devices available within cars. To implement a
MaxCut problem of this type, we need to use the Ising Model,
created by physicist Erns Ising and optimize a Hamiltonian
function describing the function we need to minimize, which is
the number of segments and the difficulty of these segments
(difficulty represents volume of traffic on a segment).
Practically, we would be implementing the Quantum
Approximate Optimization Algorithm for the Hamiltonian
function (Farhi, Goldstone & Gutmann, 2014).
Goswami, et al. (2004) proposed an approach for extending and
using Grover’s algorithm to solve the TSP. According to them,
any search algorithm to solve Approximate TSP will fail, unless
it uses additional contextual information about the search space,
which actually is the city map and traffic volume (segment
difficulty). They proposes a new encoding scheme for TSP
permutations which can be recursively generated. According
to their proposal, the new oracle function for Grover’s search is
where r represents the segments, r-length is their length
(proportional with difficulty), t is number of iterations and is
the number of possible segments (city streets or blocks).
9
We have implemented a Quantum Approximation Algorithm
based on the weighted MaxCut model using iPythondata
science notebook, implemented and tested on
JupyterHub/JupyterLab type environment running in a cloud
environment. We have tested our algorithm at a small scale
using a 16 qubit real computer ibmqx5. In addition, we have
implemented IBM provided quantum simulator within the
cloud, where we could potentially scale it up to 32-34 qubits
(Fig. 14).
Fig. 14. Quantum Simulator scaling matrix.
We used IBM Qiskit (github.com/Qiskit), Quantum
Information Software Kit, based on which we have
implemented both our simulator and our modified TSP/TOP
algorithm for Quantum Approximation using weighted
MaxCut:
Quantum Computer Simulator:github.com/Qiskit/Qiskit-
sdk-py/tree/master/src/qasm-simulator-cpp
Approximate Quantum Optimization for four segments,
using four qubits.https://github.com/Qiskit/Qiskit-
tutorial/blob/old_tutorial_format/4_applications/classical_
optimization.ipynb
We obtained the result shown in Fig. 15, with best order from
quantum optimization is = [0, 2, 3, 1] with total distance =
13.18.
Fig. 15. Plotted Quantum Optimization Results.
D. Traveling Salesman (Koller, Bender, & Barabasi, 2019)
Suppose there is an Uber driver in Manhattan, NY who needs to pick
up 3 passengers and return them to his original position at the city
center (Fig. 16). They wish to travel along an optimal route defined by
the smallest distance from the start of their journey to the end.
Fig. 16. Simple travelling salesman problem with four nodes.
We created a 4x4 distance matrix that is computed by the Manhattan
distance of each of the nodes (Fig. 17). This matrix forms our
cost function that we sought to minimize.
Fig. 17. Manhattan distance matrix of all nodes from Fig. 16.
For a small distance matrix like this one, we can find the
shortest distance by brute force. This section, however, focuses
on generating the correct Ising Hamiltonian to be solved by
finding the lowest eigenvalue and eigenvector. Developers at
IBM have been able to abstract away much of the tedium in
finding the right operators to encode the problem. This allows
us to use their TSP Python module in Qiskit to solve this
problem most efficiently. The flow of solving this problem
involves solving using an Exact Eigensolver to verify that the
right Hamiltonian was generated and to finally solve using the
Variational Quantum Eigensolver (VQE) on the IBM
simulator. First, we generated a TSP object, instantiated it with
the dimensions of the distance matrix, the distance matrix itself,
the name of the TSP object, and the nodes of the Uber driver
and people to be picked up. The following code snippet
illustrates this instantiation.
We can immediately access methods to: calculate distances
between nodes, generate the Hamiltonian for the TSP of the
graph and compute the total distance given a list of prospective
solution. We map the problem to the Ising model to generate
the overall operator. We also generate the initial energy of the
systems using the generated Hamiltonian.
The next code snippet solved the problem using an Exact
Eigensolver to ensure that the HC provided the proper cost and
associated solution path. Output were the contents of Fig. 18.
10
Fig. 18. Resulting energy, feasibility of solution, solution, and total
distance travelled from running the Exact Eigensolver.
From solving the Uber problem using the exact eigensolver, we
found that the Hamiltonian generated by the TSP class in Qiskit
is accurate. This was verified using an iterative, brute force
method.
The Variational Quantum Eigensolver (VQE) is sometimes
called the “unsung hero of quantum computing” (Variational
Quantum Eigensolver, 2019). Unlike other quantum
algorithms that work in theory or at a small scale, the VQE
algorithm was designed to work on Near Intermediate Scale
Quantum Computers. The Quantum Computers that are
available today have a limited number of qubits that are not
fault-tolerant.
The VQE is a quantum/classical hybrid algorithm that, like the
Exact Eigensolver, finds the eigenvalues of an Ising-based
Hamiltonian. The hybridization involves preparing and
measuring a quantum state for the expectation value on the
quantum computer. Then, classically varying the parameters of
the quantum state to minimize the objective function (Peruzzo,
et al., 2013). We used the VQE provided by IBM.
The classical optimizer used was the simultaneous perturbation
stochastic approximation (SPSA). This optimizer is ideal for
several reasons. First, it only requires expectation values from
the objective function. This negates the need to make multiple
direct measurements of the quantum state’s gradient which is
not possible because of the collapsing nature of the qubits wave
function. Second, SPSA requires relatively fewer
measurements to find a proper solution to the objective
function. Finally, it has been reported that SPSA is noise
accommodating. These last two points are especially useful in
today’s quantum computers because qubits are noisy and a
significant number of measurements are already needed to
obtain a distinct probabilistic distribution. The variational form
(RY) used in the VQE was the standard layering by Y rotations
with entangling gates. The variational form is also known as
the trial wave function where different parameters (in this case
Y rotations with CNOT gates) are “plugged in” to approximate
the minimum of the Hamiltonian state. It is interesting to note
in the Qiskit Aqua documentation that number of individual Y
rotations and corresponding circuit depth can be reduced. This
occurs by applying one larger RY gate that is the collective sum
of multiple individual RY manipulations (Variational forms,
2019).
After specifying the classical optimizer and variational form for
VQE, we create a Quantum Instance Object. This stores the
specified backend that we execute on, the number of times that
the experiment is run (shots), and the amount of noise present
in the simulation (seed). The implementation can be seen in the
following code snippet:
The above section covered the code used in creating and
running an instance of the Variational Quantum Eigensolver to
find a close approximation of the lowest energy state. As with
any nascent technology, there are limitations to the Quantum
computer and the QASM simulator. In the case of the Uber
problem, we were unable to run any simulations that converged
on a solution within a generous time frame. The only simulation
that yielded a possible solution was determined to be infeasible
by the TSP module. This possible solution was also only
achieved by modifying the distance matrix to represent
Euclidean distances instead of the Manhattan distance between
two nodes. This modification was the result of the TSP Python
class being designed to only work on Euclidean node-to-node
weights. In Qiskit’s TSP example notebook, we were only able
to simulate using the qasm_statevector simulator. Using this
simulator took roughly 6 minutes to execute on a mybinder
server jupyter notebook. A 2015 Macbook Pro was unable to
run the same simulation in a 2 hour time frame on a local jupyter
notebook. The qasm_simulator backend on a mybinder server
was unable to run the the same simulation during a 4 hour time
frame. The result of the simulations can be found in Table. 1.
Table. 1. Comparison of results and hardware requirements.
What was really interesting was how much faster the Exact
Eigen solver was than the VQE. This could be due to many
more parameters that the user could change in the VQE
11
algorithm, such as using different classical optimizers or
changing the variational form. This could also back up the
claim that Quantum computers are only faster than classical
computers at larger combinatorial problems. In other words, the
speedup that Quantum computers present may only be apparent
once the size of the problem passes a threshold. Additionally,
this may only be due to a fault in our code or that we were only
using a simulator. The huge computational power required to
find a solution on a trivial problem is eye opening as well as
inspiring. Finally, the importance of the simulator to understand
the probabilities of the qubits after runtime is underscored.
E. Quantum Annealing (Gandhi & More, 2019)
Simulated annealing is a common machine learning technique,
a probabilistic technique for approximating the global optimum
of a given function. To experiment with D-Wave system, we
tried to use the LEAP system and run Integer Factoring and
Structural Imbalance problem. Besides LEAP we implemented
demo examples from Ocean SDK, both of which can be found
on github and in documents (D-Wave, 2019).
Quantum annealing proves to be useful in general to solve
problems and find solution in terms of time required as
compared to a quantum computer. D-Wave’s Ocean SDK and
LEAP is useful tool to learn quantum annealing and how to
practically use it and implement to solve problems. .It provides
an insight to how just using adiabatic quantum computing
approach, number of qubits can be increased in a quantum
computer as compared to a universal gate based quantum
computer and the advantages and disadvantages of adiabatic
quantum computing.
Setting up Ocean SDK gives the connection to D-Wave’s QPU
(Quantum Processing Unit), Fig. 19.
Fig. 19: Ocean SDK ping status.
a) Map Coloring Problem
This example is implemented using D-Wave’s Ocean SDK.
Map coloring problem is a constraint satisfaction problem. The
primary requirement of a constraint satisfaction problem is to
find a result from finite set of domain, values are assigned to a
problem, satisfying all constraint. In map coloring example, all
regions are to be colored and the constraint is that for any
neighboring regions, the color should not be same. In this case,
the regions are states of Canada. To implement this using
Ocean SDK, we followed and used the example given on D-
Wave’s documentation (D-Wave, 2019). The steps briefly to
solve the problem are:•Formulate problem as graphic•Create
binary constraint satisfaction problem•Convert to binary
quadratic model (BQM)•Sample using D-Wave SAPI
solver•Plot a valid solution. The graph plot of Fig. 20 was
obtained.
Fig. 20. Map Coloring Solution.
b) Integer Factoring
Integer factoring is a P and NP-hard problem for classical
computers. For quantum computing it runs in polynomial time
when universal gate model approach is used, currently for
which, technology does not allow the possibility for large
numbers.
Using annealing, we can represent integer factoring as a
constraint satisfaction problem. For integer factoring, the
constraints are to positive integer factors a and b and their
multiplication be equal to their product integer P.
On D-Wave: D-Wave systems solve binary quadratic models
(BQM), the Ising model traditionally used in statistical
mechanics and its computer science equivalent, the quadratic
unconstrained binary optimization (QUBO) problem.
There are different ways to formulate the factoring problem as
a BQM. We program D-Wave system using following steps:
Express P=ab as a CSP with a binary multiplication
circuit.
Convert to a BQM.
Program the quantum computer with the BQM’s
coefficients.
12
For integer factoring, there is an interactive demo on LEAP.
We implemented the available demo on LEAP using the
Jupyter notebook provided with the resources. For factoring
the integer 21, 7 and 3 were obtained. The energy sample for
the solution is shown in Fig. 21.
Fig. 21. Energy Sample Graph for the integer 21.
c) Structural Imbalance
Structural imbalance can be defined as a measure for a network
which cannot be cleanly divided, is the minimum number of
edges which violates the triadic relation theory. To solve
structural imbalance, finding a division that minimizes this
violation is a NP hard problem. It is an example of optimization,
other include traffic flow, protein-folding etc. The problem is
similar to an Ising problem. The problem is formulated using
Ocean’s penalty model. The micro-embedding feature is used
to embed 200nodes in the machine. The basis for solving the
given Militants mapping project is done using penalty model
where undesirable outcomes are given a higher potential to be
eliminated from the solution.
Both interactive demo and the Jupyter notebook were
implemented. For structural imbalance, the experiment had to
be run multiple times as the mapping of graph to the problem is
done using heuristic minor-embedding which does not behave
as expected and fails (Fig. 22).
Fig. 22. Solution time: QPU vs CPU.
F. KNN Algorithm (Yang, 2019)
KNN is a popular non-parameter classification algorithm. The
idea of the KNN algorithm is to choose the class label for the
new input that appears most often amongst its k nearest
neighbors. This is based on the assumption that the class label
of ne input vector is the same as its nearest neighbors.
In order to translate this algorithm into a quantum version, we
focus on the efficient evaluation of classical distance through a
quantum algorithm. One idea is to use similarity of two
quantum states |ψ〉and |φ〉as the similarity measure, which is
known as fidelity.
The fidelity is similar to cosine similarity used in classical
information. The value of fidelity ranges from 0 if the two
quantum states are orthogonal to 1 if the states are identical.
The fidelity can be obtained through a simple quantum routine
sometimes referred to as a control swap test. The circuit design
is shown in Fig. 23.
Fig. 23. The quantum circuit.
The C-Swap gate is a 3-bit quantum register that performs a
controlled swap (Fig. 24).
Fig. 24. The C-Swap unitary matrix.
Given a quantum register |φ,ψ〉, as well as an ancillary register
initially set to |0〉, the input quantum states is |0,φ,ψ〉. A
Hadamard gate transform the ancillary register into a
superposition: 1/√2(|0〉+|1〉). Followed SWAP gate on|ψ〉
and|φ〉which swaps the two states under the condition that the
ancillary register is in state |1〉. Therefore, the quantum state
evolves to:
The second Hadamard gate transforms this to:
13
Finally, measurement after the second Hadamard gate yields
the probability:
Hence, if |φ〉and |ψ〉are identical, the probability is 1. If they
are orthogonal the probability is 1/2. Therefore, the C-Swap
test is an estimator for the fidelity between |φ〉and |ψ〉.
The quantum circuit of Fig. 25 implements the process. The
first qubit p0’s signal pass the first Hadamard gate to transfer to
the superposition state. The q1and q2 registers store the states
which need to be compared. The signal in one qubit is |0〉and
|1〉. The gate between the three registers is called a Fredkin
gate that functions the same as the CSWAP gate. The final
signal will pass the second Hadamard gate and be measured. If
the two states are orthogonal, the measure is 0.5 while if they
are identical, the probability is 1.
Fig. 25. The Quantum Circuit.
We use two backends to simulate the circuit. First we use the
unitary simulator that works provided all the elements in the
circuit are unitary operations. The unitary result is a 23x23
matrix representing the gates in this circuit (Fig. 26). Most of
the results show probability 0.5 until the qubit q1 and q2 is the
same.
Fig. 26. The Result for Unitary Backend.
We also use the State-vector backend to analyze the result. The
State vector simulator is the most common back-end in Qiskit.
It will return the quantum states which is a complex vector of
dimensions 23. The process and results are shown in Fig. 27.
Fig. 27. The Result for State vector Backend.
In this simulation, we only used one state as the input state. In
order to check whether the state can be extended, we designed
a new quantum circle for a 2 qubit state (Fig. 28).
Fig. 28. The Extended Quantum Circuit
We extended the state in this circuit, the state is changed from
|00〉to |11〉. The measured result will be 1 if the same state
and 0.5 if different. The Unitary backend result is shown in Fig.
29.
Fig. 29. The Extended Quantum Circuit Unitary Result.
Another classifier is the SVM, and IBM and MIT, working
together, have recently published a paper where they found
14
promise using quantum enhancements in building a classifier
for the support vector machine, and their findings show their
method is tolerant of noise [18].
VIII. CONCLUSIONS
This paper explored the use of quantum computing for solving
a number of machine learning and other problems more
efficiently. Most of the quantum computing problems
described here are optimization problems – traffic optimization,
traveling salesman problem, and problems solved with
simulated annealing (map coloring, integer factoring, and
structural imbalance). Other problems involved game playing,
random password generation, and the popular KNN machine
learning algorithm. A recent MIT & IBM paper shows promise
for quantum computers to be used in the construction of a
classifier for SVM. Also, quantum implementations of deep
learning neural network problems were explored. The
problems described here that have been solved on quantum
simulators or actual quantum computers indicates the potential
power of quantum computers for solving computationally
intensive problems such as those encountered in machine
learning, including the deep learning neural networks.
REFERENCES
[1] Barabasi, S. (2018). How to compensate for traffic congestions in big cities by optimizing the path vehicles take. Proc. CSIS Research Day Conf., Pace University. http://csis.pace.edu/ ctappert/srd2018/2018PDF/ a6.pdf.
[2] Barabasi, S., Barrera, J., Bhalani, P., Dalvi, P., Dimiecik, R., Leider, A., Mondrosch, J., Peterson, K., Sawant, N. & Tappert, C. (2019). Student user experience with the IBM Qiskit quantum computing interface. Future of Information & Communication Conf., pages 547–563, Springer.
[3] D-Wave documentation (2019). https://docs.ocean.dwavesys. com/en/ latest/index.html.
[4] Economist (2018). The race is on to dominate quantum computing. Retrieved https://www.economist.com/business/ 2018/08/18/therace-is-on-to-dominate-quantum-computing.
[5] Evans, D. (2019). Quantum programming: Adventures with a quantum computer. Book in preparation.
[6] Farhi, E., Goldstone, J. & Gutmann, S. (2014). A Quantum Approximate Optimization Algorithm. https://arxiv.org/pdf/ 1411.4028.pda.
[7] Gandhi, D. & More A. (2019). Quantum Annealing and Experience with D-Wave Systems. Proc. Research Day Conf., Pace University.
[8] Goswami, D., Karnick, H., Jain, P. & Maji, H.K. (2004). Towards Efficiently Solving Quantum Traveling Salesman Problem. https://arxiv.org/pdf/quant-ph/0411013.pdf.
[9] IBM (2019a). Open Source Quantum Information Science Kit. Retrieve https://Qiskit.org.
[10] IBM (2019b). IBM Q System One, https://newsroom.ibm.com/ 2019-01-08-IBM-Unveils-Worlds-FirstIntegrated-Quantum-Computing-System-for-Commercial-Use.
[11] Koller, J., Bender, W. & Barabasi, I. (2019). Exploring Quantum Approximations of Traveling Salesman. Proc. Research Day Conf., Pace University.
[12] Leddy, C. (2019). The talent shortage in quantum computing. MIT News. Retrieved http://news.mit.edu/2019/mitwilliam-oliver-qanda-talent-shortage-quantumcomputing-0123.
[13] Nielsen, M. A. & Chuang, I. L. (2010). Quantum Computation and Quantum Information. Cambridge University Press.
[14] Peruzzo, A., McClean, J., Shadbolt, P., Yung, M.H., Zhou, X.Q., Love, P.J., Aspuru-Guzik, A. & O’Brien, J.L. (2013). A Variational eigenvalue solver on a quantum processor. arXiv:1304.3061[quant-ph.
[15] Smith, L. (2018). H.R.6227 - National Quantum Initiative Act. https://www.congress.gov/bill/115thcongress/house-bill/6227/text.
[16] Tappert, C.C., Frank, R.I., Barabasi, I., Leider, A.L., Evans, D. and Westfall, L. Experience Teaching Quantum Computing. Proc. Assoc. Supporting Computer Users in Educ. (ASCUE) Conf., June 2019.
[17] Variational Quantum Eigensolver: An unsung hero of approximate quantum computing (2019). [Blog] The developer Works Blog. Available at: https://ibm.co/2LkSi4n.
[18] Variational forms (2019). Qiskit API Documentation. Available: https://bit.ly/2DzqBhS.
[19] Yang, N. (2019). KNN Algorithm Simulation Based on Quantum Information. Proc. Research Day Conf., Pace University.