Reader small image

You're reading from  A Practical Guide to Quantum Machine Learning and Quantum Optimization

Product typeBook
Published inMar 2023
PublisherPackt
ISBN-139781804613832
Edition1st Edition
Right arrow
Authors (2):
Elías F. Combarro
Elías F. Combarro
author image
Elías F. Combarro

Elías F. Combarro holds degrees from the University of Oviedo (Spain) in both Mathematics (1997, award for second highest grades in the country) and Computer Science (2002, award for highest grades in the country). After some research stays at the Novosibirsk State University (Russia), he obtained a Ph.D. in Mathematics (Oviedo, 2001) with a dissertation on the properties of some computable predicates under the supervision of Prof. Andrey Morozov and Prof. Consuelo Martínez. Since 2009, Elías F. Combarro has been an associate professor at the Computer Science Department of the University of Oviedo. He has published more than 50 research papers in international journals on topics such as Computability Theory, Machine Learning, Fuzzy Measures and Computational Algebra. His current research focuses on the application Quantum Computing to algebraic, optimisation and machine learning problems. From July 2020 to January 2021, he was a Cooperation Associate at CERN openlab. Currently, he is the Spain representative in the Advisory Board of CERN Quantum Technology Initiative, a member of the Advisory Board of SheQuantum and one of the founders of the QSpain, a quantum computing think tank based in Spain.
Read more about Elías F. Combarro

Samuel González-Castillo
Samuel González-Castillo
author image
Samuel González-Castillo

Samuel González-Castillo holds degrees from the University of Oviedo (Spain) in both Mathematics and Physics (2021). He is currently a mathematics research student at the National University of Ireland, Maynooth, where he works as a graduate teaching assistant. He completed his physics bachelor thesis under the supervision of Prof. Elías F. Combarro and Prof. Ignacio F. Rúa (University of Oviedo), and Dr. Sofia Vallecorsa (CERN). In it, he worked alongside other researchers from ETH Zürich on the application of Quantum Machine Learning to classification problems in High Energy Physis. In 2021, he was a summer student at CERN developing a benchmarking framework for quantum simulators. He has contributed to several conferences on quantum computing.
Read more about Samuel González-Castillo

View More author details
Right arrow

Chapter 7
VQE: Variational Quantum Eigensolver

From so simple a beginning endless forms most beautiful and most wonderful have been, and are being, evolved.
— Charles Darwin

In the previous chapters of this part of the book, we have studied how quantum algorithms can help us solve combinatorial optimization problems, but there are many other important types of optimization problems out there! This chapter will broaden the scope of our optimization methods to cover more general settings, including applications in fields such as chemistry and physics.

We will achieve this by studying the famous Variational Quantum Eigensolver (VQE) algorithm, which can be seen as a generalization of the Quantum Approximate Optimization Algorithm that we studied back in Chapter 5, QAOA: Quantum Approximate Optimization Algorithm. Actually, it would be more precise to say that we can see QAOA as a particular case of VQE; in fact, VQE was introduced earlier than QAOA in a now famous paper by Peruzzo...

7.1 Hamiltonians, observables, and their expectation values

So far, we’ve found in Hamiltonians a way to encode combinatorial optimization problems. As you surely remember, in these optimization problems, we start with a function that assigns real numbers to binary strings of a certain length , and we seek to find a binary string with minimum cost . In order to do that with quantum algorithms, we define a Hamiltonian such that

\left\langle x \right|H_{f}\left| x \right\rangle = f(x)

holds for every binary string of length . Then, we can solve our original problem by finding a ground state of (that is, a state such that the expectation value is minimum).

This was just a very quick summary of Chapter 3, Working with Quadratic Unconstrained Binary Optimization Problems. When you read that chapter, you may have noticed that the Hamiltonian associated to has an additional, very remarkable property. We have mentioned this a couple of times already, but it is worth remembering that, for every computational basis state , it holds...

7.2 Introducing VQE

The goal of the Variational Quantum Eigensolver (VQE) is to find a ground state of a given Hamiltonian . This Hamiltonian can describe, for instance, the energy of a certain physical or chemical process, and we will use some such examples in the following two sections, which will cover how to execute VQE with Qiskit and PennyLane. For the moment, however, we will keep everything abstract and focus on finding a state such that is minimum. Note that in this section, we will be using to refer to the Hamiltonian so that it does not get confused with the Hadamard matrix that we will also be using in our computations.

To learn more

VQE is by no means the only quantum algorithm that has been proposed to find the ground states of Hamiltonians. Some very promising options use a quantum subroutine known as Quantum Phase Estimation (QPE) (see, for instance, the excellent surveys by McArdle et al. [66] and by Cao et al. [22]). The main disadvantage of these approaches...

7.3 Using VQE with Qiskit

In this section, we will show how we can use Qiskit to run VQE on both simulators and actual quantum hardware. To do that, we will use a problem taken from quantum chemistry: determining the energy of the or dihydrogen molecule. Our first subsection is devoted to defining this problem.

7.3.1 Defining a molecular problem in Qiskit

To illustrate how we can use VQE with Qiskit, we will consider a simple quantum chemistry problem. We will imagine that we have two atoms of hydrogen forming an molecule and that we want to compute its ground state and its energy. For that, we need to obtain the Hamiltonian of the system, which is a little bit different from the kind of Hamiltonian that we are used to. The Hamiltonians that we have considered so far are called qubit Hamiltonians, while the one that we need to describe the energy of the molecule is called a fermionic Hamiltonian — the name comes from the fact that it involves fermions, that is, particles...

7.4 Using VQE with PennyLane

In this section, we will illustrate how to run VQE with PennyLane. The problem that we will work with will be, again, finding the ground state of the dihydrogen molecule. This is a task we are already familiar with and, moreover, this will allow us to compare our results with those that we obtained with Qiskit in the previous section. So, without further ado, let’s start by showing how to define the problem in PennyLane.

7.4.1 Defining a molecular problem in PennyLane

As with Qiskit, PennyLane provides methods to work with quantum chemistry problems. To study the molecule, we can use the following instructions:

import pennylane as qml 
 
from pennylane import numpy as np 
 
 
 
seed = 1234 
 
np.random.seed(seed) 
 
 
 
symbols = ["H", "H"] 
 
coordinates = np.array([0.0, 0.0, -0.6991986158, 0.0, 0.0, 0.6991986158]) 
 
 
 
H, qubits = qml.qchem.molecular_hamiltonian(symbols, coordinates) 
 
print("Qubit Hamiltonian: "...

Summary

In this chapter, we have studied Hamiltonians and observables in detail. In particular, we have learned how to derive mathematical expressions for their expectation values and how to estimate these quantities using quantum computers.

Then, we studied the VQE algorithm and how it can be used to find ground states of general Hamiltonians. We also described a modification of VQE called VQD that can also be used to compute excited states and not just states of minimum energy.

Then, we moved to practical matters and learned how to use Qiskit to run VQE and VQD. We illustrated this with a very interesting problem: that of finding the ground state of a simple molecule. We then introduced methods to simulate the behavior of quantum algorithms when there is noise and how to reduce the adverse effect of readout errors with some mitigation techniques. We also studied how to run VQE problems on actual quantum computers with IBM runtime.

After that, we also learned how to implement and run...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
A Practical Guide to Quantum Machine Learning and Quantum Optimization
Published in: Mar 2023Publisher: PacktISBN-13: 9781804613832
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Elías F. Combarro

Elías F. Combarro holds degrees from the University of Oviedo (Spain) in both Mathematics (1997, award for second highest grades in the country) and Computer Science (2002, award for highest grades in the country). After some research stays at the Novosibirsk State University (Russia), he obtained a Ph.D. in Mathematics (Oviedo, 2001) with a dissertation on the properties of some computable predicates under the supervision of Prof. Andrey Morozov and Prof. Consuelo Martínez. Since 2009, Elías F. Combarro has been an associate professor at the Computer Science Department of the University of Oviedo. He has published more than 50 research papers in international journals on topics such as Computability Theory, Machine Learning, Fuzzy Measures and Computational Algebra. His current research focuses on the application Quantum Computing to algebraic, optimisation and machine learning problems. From July 2020 to January 2021, he was a Cooperation Associate at CERN openlab. Currently, he is the Spain representative in the Advisory Board of CERN Quantum Technology Initiative, a member of the Advisory Board of SheQuantum and one of the founders of the QSpain, a quantum computing think tank based in Spain.
Read more about Elías F. Combarro

author image
Samuel González-Castillo

Samuel González-Castillo holds degrees from the University of Oviedo (Spain) in both Mathematics and Physics (2021). He is currently a mathematics research student at the National University of Ireland, Maynooth, where he works as a graduate teaching assistant. He completed his physics bachelor thesis under the supervision of Prof. Elías F. Combarro and Prof. Ignacio F. Rúa (University of Oviedo), and Dr. Sofia Vallecorsa (CERN). In it, he worked alongside other researchers from ETH Zürich on the application of Quantum Machine Learning to classification problems in High Energy Physis. In 2021, he was a summer student at CERN developing a benchmarking framework for quantum simulators. He has contributed to several conferences on quantum computing.
Read more about Samuel González-Castillo