Skip to main content
Create your own
Lesson illustration

VQE for H2 Ground State

Hello! Welcome back to our deep dive into quantum computing.

In our last two lessons, we assembled the key quantum components of the Variational Quantum Eigensolver (VQE). We learned how to represent a molecular Hamiltonian as a sum of Pauli strings and, crucially, how to devise a measurement strategy to estimate its expectation value on a quantum computer.

Today, we will put all the pieces together. This lesson addresses the learning outcome: Implement the VQE algorithm to find the ground state of a simple molecular Hamiltonian like H2. We will construct the full hybrid quantum-classical workflow, where a classical optimizer guides a quantum computer toward the lowest energy state of a molecule.

1. The VQE Algorithm: A Hybrid Approach

At its heart, VQE is an application of the variational principle of quantum mechanics, which states that the expectation value of a Hamiltonian for any trial wavefunction is always greater than or equal to the true ground state energy :

VQE uses a quantum computer to prepare a parameterized trial state and estimate its energy . A classical computer then runs an optimization algorithm to find the parameters that minimize this energy, thereby approximating .

The overall workflow is an iterative loop:

  1. Classical Start: Choose an initial set of parameters .
  2. Quantum Task:
    a. Prepare the parameterized quantum state on the quantum computer.
    b. Measure the expectation value of the Hamiltonian, , to get the energy .
  3. Classical Optimization: Pass the energy to a classical optimizer.
  4. Update: The optimizer uses (and possibly its gradient) to propose a new set of parameters, .
  5. Iterate: Repeat the loop with until the energy value converges.

The Variational Quantum Eigensolver — Programming on Quantum Computers — Coding with Qiskit S2E4

To start, let's watch a brief segment from a Qiskit video that provides a high-level overview of this hybrid process and its application in chemistry.

Please watch from 00:39 to 03:45. This will introduce the motivation for using VQE in quantum chemistry and outline the main steps of the algorithm.

2. The Physics of the Problem: The H₂ Molecule

To implement VQE, we need a concrete problem. The dihydrogen molecule, H₂, is the canonical "hello, world!" for quantum chemistry simulations. While simple, its exact solution requires accounting for electron-electron correlation, making it a meaningful testbed.

Your background in physics will make the process of formulating the Hamiltonian familiar. We start with the full description of all kinetic and potential energies of the nuclei and electrons. We then make a critical simplification.

VQE Zero to Hero

The video 'VQE Zero to Hero' provides an excellent walkthrough of the physics, from the full molecular Hamiltonian to a form usable by a quantum computer. It covers the Born-Oppenheimer approximation, the transition to second quantization, and the mapping to qubit operators.

Please watch from 02:03 to 20:35. This covers four key conceptual steps: Simplifying the molecular Hamiltonian with the Born-Oppenheimer approximation. Moving from first quantization (wavefunctions) to second quantization (occupation numbers and fermionic operators). Expressing the electronic Hamiltonian in this new formalism. Mapping the fermionic operators to Pauli operators using the Jordan-Wigner transformation.

As the video explains, this chain of approximations and transformations takes us from a complex physical system to an abstract qubit Hamiltonian, , whose ground state energy we can find with VQE.

3. Implementing VQE for H₂

Now, let's translate this theory into a practical implementation. We will use the PennyLane library, but the concepts are directly transferable to other frameworks like Qiskit.

The following thesis provides a detailed account of simulating H₂ with VQE, connecting the theory directly to the 4-qubit problem we will solve.

Simulation of H2 molecule through Variational Quantum ...

This Master's thesis, 'Simulation of H2 molecule through Variational Quantum Eigensolver', gives a clear, step-by-step derivation for the H₂ molecule.

Please read Chapters 2.1, 2.2, and 2.3 (pages 13-20). These sections detail: The H₂ Hamiltonian and the Born-Oppenheimer approximation. The second quantization representation, mapping the four relevant spin-orbitals to a 4-qubit system. The Jordan-Wigner transformation applied to H₂, resulting in an explicit Pauli string Hamiltonian (Equation 2.17).

With the Hamiltonian defined, we can proceed with the VQE implementation. The PennyLane demo below provides a concise, complete code example.

A brief overview of VQE | PennyLane Demos

The PennyLane demo 'A brief overview of VQE' walks through the entire process of finding the ground state energy of H₂.

Please read the sections 'Building the electronic Hamiltonian', 'Implementing the VQE algorithm', and the part of 'Classical Optimization' that sets up and runs the optimization loop. Focus on these three key implementation steps: Hamiltonian: How the 4-qubit Hamiltonian is loaded. Ansatz & Cost Function: How the simple, chemically-motivated ansatz is built and how the cost function is defined as a QNode that computes the Hamiltonian's expectation value. Optimization: How a classical optimizer is used to iteratively call the cost function and minimize the energy.

Let's break down the implementation steps from the demo:

  1. The Hamiltonian: Modern quantum chemistry libraries handle the complex physics calculations (the one- and two-electron integrals, and ) and the fermionic-to-qubit mapping for us. We can directly load the 4-qubit Pauli-string Hamiltonian for H₂ at a given bond length. The Hamiltonian in the PennyLane demo is the same one derived in the thesis you read (Equation 2.17), just for a different bond length.

  2. The Ansatz: The demo uses a simple but effective ansatz.

    • It starts by preparing the Hartree-Fock (HF) state, which is the classical best-guess for the ground state. For H₂ in a minimal basis, this is , representing the two electrons occupying the two lowest-energy spin-orbitals.
    • It then applies a single DoubleExcitation gate. This gate creates a superposition with the state , which represents the two electrons being excited to the two higher-energy anti-bonding orbitals.
    • The resulting trial state is , where is the single variational parameter we need to optimize. This captures the most important electron correlation effect in the H₂ molecule.
  3. The Cost Function: This is the Python function that connects the classical and quantum parts. In PennyLane, the @qml.qnode decorator turns a circuit-defining function into an executable object. This function takes the parameter , prepares the state , and returns the expectation value .

  4. The Optimization: A classical optimizer, like gradient descent, is initialized. It then calls the cost function repeatedly, adjusting at each step to find the value that minimizes the returned energy. The final converged energy is our VQE estimate of the ground state energy.

4. Finding the Equilibrium Bond Length

A key application in chemistry is to find the potential energy surface of a molecule. For H₂, this means calculating the ground state energy at various internuclear distances, . The distance that yields the minimum energy corresponds to the molecule's equilibrium bond length.

This involves wrapping our VQE algorithm in another classical loop that iterates over different values of .

The Variational Quantum Eigensolver — Programming on Quantum Computers — Coding with Qiskit S2E4

The Qiskit video we saw earlier demonstrates this 'outer loop' by calculating the ground state energy of LiH at various distances and plotting the resulting energy curve.

Please watch the implementation section from 07:30 to 21:33. While the code uses Qiskit, the structure is what's important. Notice how the VQE procedure is placed inside a for loop that iterates over different atomic distances. The final plot shows the energy curve and reveals the equilibrium bond length.

This process of scanning distances to find the minimum-energy configuration is a standard VQE application and demonstrates its power in exploring chemical properties. The thesis you reviewed also performs this analysis in its final section (3.4, "Results").

Conclusion

In this lesson, we have successfully assembled and implemented the full VQE algorithm. We have seen how it operates as a hybrid quantum-classical method to solve a meaningful problem in quantum chemistry.

Key Takeaways:

  • VQE is an iterative, hybrid algorithm that uses a classical optimizer to train a parameterized quantum circuit.
  • The objective is to find the parameters that minimize the expectation value of a Hamiltonian, , thereby approximating the system's ground state energy.
  • For molecular simulations like H₂, the process involves translating the physical system into a qubit Hamiltonian using the Born-Oppenheimer approximation, second quantization, and a mapping like Jordan-Wigner.
  • The core of the implementation consists of three parts: defining the Hamiltonian, designing an appropriate ansatz (e.g., based on the Hartree-Fock state and chemical excitations), and setting up the classical optimization loop that repeatedly calls the quantum computer (or simulator).
  • By running VQE for different molecular geometries, we can compute potential energy surfaces and find key properties like equilibrium bond lengths.

Preview of the Next Lesson

So far, our focus has been on finding static properties of a system, namely its ground state. Quantum computers also promise to excel at simulating how quantum systems evolve in time.

In our next lesson, Implement Hamiltonian simulation using a first-order Trotter-Suzuki decomposition, we will shift our focus from static to dynamic problems. We will explore how to approximate the time evolution operator by breaking it down into a sequence of simpler quantum gates, a technique known as Trotterization. This is a foundational method for simulating quantum dynamics on a digital quantum computer.

Can't find a good explanation? Sign up and we'll make it for you

Sign up