Preparing the Hamiltonian matrix for quantum computing algorithms
Many of the applications of quantum computing are in computational chemistry and there are a few well understood algorithms for simulating complex molecular systems on quantum computers. As quantum computers inch closer to practicality, computation chemistry will explode and open up new worlds for drug discovery, surface simulation and battery technology. I’m excited, I think you should be too, so I decided to understand how these algorithms work and try to communicate them in an effective way for other techy non-physicists.
One barrier I came across again and again was on the first line of every explanation of every algorithm for computation chemistry. They all start with the Hamiltonian operator expressed as a matrix. Often as a sum of other simpler matrices called Pauli matrices. It was easy to find information about the Hamiltonian operator as part of the Schrödinger equation, but the form usually described in that context looks nothing like a matrix: it is a differential operator. How do you get from a differential operator to a matrix? And what do you do with it once you have got there? This little blog won’t turn you into a practical quantum scientist, but it will hopefully give you some intuition for how the magic of these techniques are applied.
Let’s quickly remind ourselves of the Schrödinger equation, which I presented in an earlier post. If you are not familiar with this equation and what it means then I recommend reading that post and then coming back here.
We define the equation in terms of the Hamiltonian operator for our system then solve it to find the wave function and corresponding eigenvalues.
The Hamiltonian operator has two parts: the kinetic energy of the system T-hat, that describes each isolated particle and is defined in terms of the momentum operator p-hat, and the potential energy of the system V-hat, which describes the possible interactions of each particle.
The momentum operator is a differential operator in that to apply it to a wave function is to differentiate that wave function. In fact the momentum operator is applied twice in the Hamiltonian making the Hamiltonian a second order differential operator.
How to you turn a differential operator into a matrix?
The differential operator and the more complex Hamiltonian are both linear operators, that is they act on a vector and preserve vector addition and scalar multiplication. Cheerfully, linear algebra tells us that any linear operator can be expressed as a matrix. To express an operator as a matrix you first need to define a basis for the linear space on which the operator will act. A basis is a set of vectors such that any vector in the space can be made from a linear combination of basis vectors. Normally you would choose an orthonormal basis, meaning that the vectors are orthogonal and of size 1.
For example, we can define the space of real quadratics by the basis {1, x, x²}. We can define any quadratic in our linear space of quadratics as a linear combination of our basis elements with coefficients a, b and c:
D(a + bx + cx²) = b + 2cx
We can write our basis as the following set of vectors. Since we are thinking about quantum systems, it is also useful to write the basis as a set of kets.
We can then define the differential operator D = d/dx by the following matrix:
I’ll show you how to derive it below, but first let us check that it works. The result of applying our differential operator to the quadratic is the same as applying the matrix above to the vector representing that quadratic.
Expressing the Hamiltonian as a matrix
The first step in constructing the matrix for a Hamiltonian is to choose the basis for the matrix. The basis set that one chooses for the Hamiltonian depend on the set of wave functions that you want the Hamiltonian to act upon, but the idea is the same as above. Once you have your basis, the matrix can be defined as follows, where Hij is the ijth element of the matrix with i denoting the row and j denoting the column. The j-kets are the vectors in the basis. When using the bra-ket notation to represent vectors, the bra is the conjugate transpose of the corresponding ket, meaning we write the vector horizontally and we flip the sign of the complex part of each element.
As an exercise we can apply this formula to the differential operator above and our chosen basis to derive the matrix. Here are expressions for some of the elements, remembering that ⟨a|a⟩ = 1 where the kets represent vectors of size 1, and ⟨a|b⟩ = 0 for a != b because our basis vectors are orthogonal.
⟨1|D|1⟩ = 0⟨1| = 0
⟨1|D|x⟩ = ⟨1|1⟩ = 1
⟨x|D|x²⟩ = 2⟨x|x⟩ = 2
⟨1|D|x²⟩ = 2⟨1|x⟩ = 0
How do we choose a basis for our Hamiltonian?
It is reasonably obvious now I hope how one chooses the basis for the space of real polynomials, but how do we choose a basis for our Hamiltonian? In quantum computing a common choice for the basis is a set of atomic orbitals. These are functions that describe the charge and probable location of an electron. The wave function can be represented as a weighted sum of atomic orbitals. It can also therefore be represented as a vector of the coefficients or weights of such a sum.
Hopefully you are starting to build up a picture of why the wave function is sometimes referred to as a function and sometimes a vector and sometimes a state. For atomic orbitals the associated function defines the state of the atom and the likelihood of finding an electron in a specific place were we to measure it. The wave function can be built from a linear sum of atomic orbitals. The vector is formed of the coefficients of that linear sum.
It is helpful to define the Hamiltonian in terms of atomic orbitals, although it is not the only way to express the operator, there are other ways to choose the basis. In general a basis should be chosen to give a reasonably wide space in which to express the wave function, but the set should be as small as possible because you need an extra qubit for every extra element in the basis set.
What do we do with our Hamiltonian matrix?
Expressing the Hamiltonian as a matrix is not quite enough to make it really useful, we usually need to work a bit harder to write it in a form that can be consumed by a quantum computer. Usually the Hamiltonian is expressed as a sum of Pauli matrices. Pauli matrices are unitary, reversible, and act on a single qubit so can be implemented on a quantum computer.
These three matrices along with the identity matrix form a basis for 2x2 Hermitian matrices. Hermitian matrices have real eigenvalues so when we construct quantum operators with respect to some observable, the matrix of those operators must be Hermitian for the value of that observable to be real. An operator with complex eigenvalues would imply that the observable such as angular momentum or energy would be complex, which is not possible. The condition of quantum operators being represented as Hermitian matrices means we can decompose the operator matrix using a linear sum of Pauli Matrices, eg: H = a X + b Y + c Z + d I
Pauli matrices can be built as gates on a quantum computer so representing the Hamiltonian in this way gets us closer to being able to represent the operator on a quantum computer. Pauli matrices are 2x2 so if our Hamiltonian is a higher-order matrix we can represent it in terms of Pauli gates, but we must build a new basis from tensor products of the Pauli matrices, the tensor product resulting in a higher dimensional matrix. For example for a 4x4 Hamiltonian you would calculate the following coefficients:
In general you can calculate the coefficients with the following formula where tr indicates taking the trace of a matrix, which is the sum of its eigenvalues. I won’t delve into the details of house this works here because this blog is already a bit long, but if you want to know more look up Pauli Decomposition and you will find a wealth of examples.
Modern programming environments usually provide libraries for decomposing Hermitian matrices in terms of tensor products of Pauli operators, often called Pauli Strings, so unless you are studying for your masters in Quantum Algorithms, this is probably not something you will need to do by hand.
Further simplification of the Hamiltonian
There are many transformations and simplification of the Hamiltonian to prepare it for use in a quantum algorithm. These are usually performed prior to Pauli decomposition. One such technique is called Second Quantization. This is a simplification of the Hamiltonian based on the idea that identical particles in identical states are interchangeable. So instead of defining the state of each particle individually, we simply say how many particles are in each state. The treatment of bosons such as photons is different from fermions such as electrons and protons so if you look up the technique you will see different formulae for each, but the idea of symmetry and simplification of identical particles is the same. The method of second quantitation introduces creation and annihilation operators to represent the creation and annihilation of particles as the state of the system evolves and energy states change. It is possible to then map the system in terms of the creation and annihilation operators to Pauli matrices.
The creation and annihilation operators are often defined in terms of adding and removing electrons from the system. If atomic orbitals are used to form the basis then the Hamiltonian is defined in terms of the state of the electrons. It is often possible to ignore effects that have less effect on the system that you are modelling to simplify the model. For example the nucleus of the atom can be modeled as a stable point. A Hamiltonian that is defined in terms of the electron states is often called a Fermionic Hamiltonian, an electron being a type of fermion.
To put these techniques into practice takes a lot more depth that is practical to cover here, but hopefully I’ve given you some intuition for the notation and concepts behind the representation of molecular systems and how one might apply them on a quantum computer. I’ll be following this with a post on computational chemistry that talks about how you take the description of the system and compute properties that we can use in areas such as drug discovery.