Use VQE to calculate the ground energy of hydrogen molecules on IBM Quantum
Abstract
Quantum computing has emerged as a promising technology for solving problems that are intractable for classical computers. In this study, we introduce quantum computing and implement the Variational Quantum Eigensolver (VQE) algorithm using Qiskit on the IBM Quantum platform to calculate the ground state energy of a hydrogen molecule. We provide a theoretical framework of quantum mechanics, qubits, quantum gates, and the VQE algorithm. Our implementation process is described, and we simulate the results. Additionally, experiments are conducted on the IBM Quantum platform, and the results are analyzed. Our findings demonstrate that VQE can efficiently calculate molecular properties with high accuracy. However, limitations and challenges in scaling the algorithm for larger molecules are also identified. This work contributes to the growing body of research on quantum computing and highlights the potential applications of VQE for real-world problem-solving.
I Introduction
Quantum computing is a rapidly growing field that explores the potential of quantum mechanics to develop new technologies[1]. Unlike classical computers which use binary digits (bits) to represent information, quantum computers use quantum bits (qubits) that can exist in superpositions of states, allowing for massive parallelism and the ability to solve problems faster than classical computers.
In this study, we focus on the implementation of the Variational Quantum Eigensolver (VQE) algorithm[2] using Qiskit[3] on the IBM Quantum platform[4] to calculate the ground state energy of a hydrogen molecule. The calculation of molecular properties is of great significance in chemistry, as it can aid in the design of new drugs, catalysts, and materials. However, the computational complexity of solving the Schrödinger equation for large molecules using classical methods limits the accuracy and efficiency of these calculations. VQE has emerged as a promising algorithm for calculating molecular energies on quantum computers, offering significant speed-ups over classical methods.
Quantum computing is an emerging field of computer science that utilizes the principles of quantum mechanics to perform calculations on data. In traditional computing, bits are used to represent information in binary form (0 or 1), whereas in quantum computing, qubits are used to store and manipulate information. Qubits are quantum systems that can exist in a superposition of states, which means they can represent both 0 and 1 at the same time. This property makes quantum computers capable of performing certain calculations exponentially faster than classical computers.
One of the most famous algorithms in quantum computing is Shor’s algorithm[5], which efficiently factors large numbers into their prime factors. This algorithm has important implications for cryptography, as it would allow for the efficient breaking of many commonly used encryption schemes. Another important algorithm in quantum computing is Grover’s algorithm[6], which provides a quadratic speedup for searching unstructured databases. Grover’s algorithm has numerous applications in fields such as optimization and machine learning.
The basic building block of a quantum computer is a quantum gate, which is a unitary transformation that acts on one or more qubits. Some common examples of quantum gates include the Hadamard gate, which creates a superposition state, and the Pauli gates, which perform rotations around the x, y, and z axes. The state of a quantum system is represented by a ket vector, which is an element of a complex Hilbert space. In order to perform quantum computations, it is necessary to perform operations on qubits while maintaining their coherence. This is a significant challenge due to the susceptibility of quantum systems to decoherence from environmental interactions. Despite these challenges, there has been significant progress in the development of quantum hardware and algorithms in recent years. Many companies and research institutions are actively working on developing practical quantum computers that can be used to solve real-world problems.
The VQE algorithm is a hybrid quantum-classical approach for finding the ground state energy of a given molecule on a quantum computer. The goal of the VQE algorithm is to find the lowest eigenvalue of the molecular Hamiltonian, which represents the ground energy of the molecule. In essence, the VQE algorithm involves preparing a trial wavefunction called Ansatz on the quantum computer, measuring its energy, and then optimizing the parameters of the wavefunction using a classical optimization algorithm. This process is repeated iteratively until an optimal set of parameters is found that minimizes the energy of the trial wavefunction.
Given a molecular Hamiltonian , we can express the ground state energy as the minimum of the expectation value of with respect to some trial wavefunction parametrized by a set of parameters :
(1) |
We can use a quantum computer to measure , and a classical optimizer to vary the parameters in order to minimize this expectation value. This process is repeated until convergence is achieved and an approximation of the ground state energy is obtained.
This work will begin with an introduction to quantum computing and explain the principle behind the VQE algorithm. In addition, we utilized IBM’s Quantum platform and Qiskit library to calculate the ground-state energy of a hydrogen molecule using the VQE algorithm for our research. Finally, we will summarize the current development direction of quantum algorithms and provide future outlooks.
II Quantum Computing
II.1 Represent of Qubits
In quantum computing, wave functions and qubits are usually represented using Dirac notation, which is written in the form of a Ket vector. Typically, the state of a qubit can be represented by a ket vector as follow:
(2) |
The and are called probability amplitude, satisfy the normalization of probability, means . The and are called standard basis vectors, correspond to 0 and 1 respectively.
Qubits can also be represented in three-dimensional space by Bloch spheres, as shown in FIG. 1.

At this time, since the length of the vector is specified as a unit length, the quantum state can be determined by the angle between the projection of the vector on the - plane and the axis and the angle between the vector and the axis. At this time, the state vector can be expressed as:
(3) |
One of the benefits of this representation is the ability to distinguish global phase. The so-called global phase is a factor whose norm is 1.
The state of a system composed of qubits is represented by the tensor product composite of the states of these qubits, that is, it can be represented by a -dimensional complex vector, where each element corresponds to a ground state composed of a qubit. For example, in a system of two qubits, if the first qubit is in state and the second qubit is in state , the state of the entire system can be expressed as:
(4) |
Similar to the single-qubit case, we can also use the Dirac notation to represent the state of a multi-qubit system, namely:
(5) |
where is a complex coefficient, and denotes the th ground state in a system of qubits. In quantum computing, we usually only focus on the states associated with a certain measurement, i.e. if we measure the system, it will only be in one of the ground states.
II.2 Operations on Qubits
In quantum computing, all operations can be equivalently performed by applying a unitary matrix to a qubit.
For example, if you want to flip the state vectors of qubits around their respective axes, that is, rotate around the corresponding axis, this operation corresponds to the Pauli matrix. In quantum computing, Pauli matrices are also known as Pauli gates.
(6) |
Generally, the identity matrix is regarded as a kind of Pauli gate. Compared with the Pauli gate, there is also a special gate that rotates around a certain axis, called the rotation gates, denoted as , where represents the corresponding axis, and represents the rotation angle.
(7) | ||||
According to Euler’s formula , the gate can be squared to obtain the gate, and the gate can also be squared to obtain the gate. Correspondingly, the gate rotates around the -axis, while the gate rotates .
(8) | ||||
In quantum computing, there is another common operation, which is to prepare a uniformly distributed superposition state. The so-called uniform distribution superposition state is a quantum superposition state, where and have the same probability, that is, and . These two states can usually be represented by and .
A uniform superposition state is usually achieved using a Hadamard gate, denoted as . It introduces transitions between uniformly distributed superposition states and non-uniformly distributed states. The so-called non-uniformly distributed states are and for a qubit.
(9) |
For multi-qubit systems, the more common quantum gate is the controlled NOT gate (CNOT). CNOT is divided into two parts, the control qubit and the target qubit. If the state of the control qubit is , it is equivalent to applying an gate to the target qubit, otherwise it will do nothing to the target qubit.
(10) |
A set of quantum gates is said to be universal if there is a set of quantum gates such that all quantum operations, or quantum programs, can be approximated by sequences of gates in this set. Any quantum program can be represented by a sequence of quantum circuits and classical near-time computation.
II.3 Quantum Circuits
In quantum computing, quantum circuits are graphical representations used to describe the evolution and manipulation of quantum states. It consists of a series of quantum gates, each of which represents an operation on one or more qubits. By constructing different quantum circuits, we can realize tasks such as various quantum algorithms and quantum communication protocols[7].
For example, the FIG. 2 shows the process of preparing entangled states using gate and CNOT gate.

III Use VQE to get hydrogen molecule
The VQE algorithm is a quantum algorithm for solving the smallest eigenvalue, and is usually used to solve the molecular ground state energy. The core idea of the VQE algorithm is to construct a parameterized quantum circuit, and then use a classical computer to optimize the quantum circuit so that the output state of the circuit is close to the target state, and calculate the expected value of the target Hamiltonian on this state. By minimizing this expected value, the minimum eigenvalue of the target Hamiltonian can be obtained, and then the solution to the molecular ground state energy can be completed.
Before starting to solve the problem, we first organize the Hamiltonian and wave function of the hydrogen atom into the form required in quantum computing, that is, the form represented by the combination of quantum gates.
In quantum mechanics, for a quantum state , we can use the Hamiltonian operator to replace its energy. In other words, the system energy is the eigenvalue of its Hamiltonian, and the ground state energy is its minimum eigenvalue.
(11) |
In this way, our goal becomes to find the minimum value of , that is, to find .
III.1 The Hamiltonian
The Hamiltonian of a system can generally be split into two parts: momentum and potential energy . where can usually be expressed as , which is a function of distance. In an electronic system, the potential energy can be roughly divided into three parts, electrons and electrons, nucleus and nuclei, and electrons and nuclei, which can be expressed as follows:
(12) | ||||
where is the number of protons in the -th nucleus, is the electronic charge.
Kinetic energy can be divided into two parts: electron kinetic energy and atomic nuclear kinetic energy.
(13) |
where is the mass of a nucleus, is the electron mass, is the Laplace operator of the -th particle.
For these two complex formulas, we can simplify them. First, we can assume that the nucleus is stationary, but this is relative to the electrons. Secondly, we use atomic units[9] and set some constants such as to 1, so that our formula can be simplified to the following form.
(14) | ||||
Further, we can divide the Hamiltonian into two parts, the one-particle part and the two-particle part . Assuming that represents the spin-orbit that constitutes the system, we will use the generation operator and annihilation operator to represent the single-particle part.
(15) |
The two-particle part can also be similarly expressed by the production operator and annihilation operator.
(16) |
As mentioned above, we can get the final representation of our quadratic quantized Hamiltonian.
(17) |
where is a correction constant used to correct errors due to simplification.
Next, we also need to map the twice-quantized Hamiltonian into the quantum computer. Here, we have many options, such as using Jordan-Wigner transformation[10], or Bravyi-Kitaev transformation[11]. For simplicity, we use the Jordan-Wigner transform.
(18) |
where , and are Pauli matrices in quantum computing, respectively.
After doing this, the Hamiltonian of our hydrogen molecule can be expressed as:
(19) | ||||
III.2 The Wave Function
In computational physics, usually, the wave function of our system can be expressed in the form of Slater determinant[12].
(20) |
where is the normalization parameter and represents the molecular orbital wavefunction of the th orbital of the th atom. Because it basically satisfies the format of quantum computing, sometimes we can express it as .
But in order to make our calculation more convenient, we can quantize this wave function twice and express it in the form of occupation number representation.
(21) |
Among them, is a constant coefficient, while represents the number of possession, and indicates whether the electron is in a certain state.
For the wave function represented by the representation of the occupation number, we use the generation operator and the annihilation operator to operate, that is, flip the corresponding occupancy number state, the generation operator can change the number of possession from to , and the annihilation operator can change the number of possession from to .
IV Use Qiskit to Solve
Theoretically, we need to prepare the objective function and quantum circuit by ourselves, that is, use the formula (17) and the formula (18) to perform quadratic Quantize and express it in the form of a quantum circuit. For example, for hydrogen molecule, its Hamiltonian can be represented by the formula (19).
However, in the process of actually calculating the molecular ground state energy, we do not need to manually solve and simplify the molecular Hamiltonian. In chemistry, scientists already store some common molecular properties in some databases. When we calculate, in most cases, we only need to query the information of the corresponding molecule to get what we need.
In Python, there is a library named PySCF[13], which stores the information of many elements and molecules. We can use the drivers or APIs provided by PySCF to query molecular information or build molecules relatively easily. For example, if we want to build a hydrogen molecule here, we can use the code showing in TABLE. 1 to complete it.
molecule = Molecule( geometry=[ ["H", [0.0, 0.0, -dist / 2]], ["H", [0.0, 0.0, dist / 2]]], multiplicity=1, charge=0) driver = ElectronicStructureMoleculeDriver( molecule=molecule, basis="sto3g", driver_type=ElectronicStructureDriverType.PYSCF) problem = ElectronicStructureProblem(driver, [electronic.FreezeCoreTransformer( freeze_core=True)])
After building the model, we also need to perform secondary quantization and mapping.
These operations have been defined in Qiskit.
We can use the second_q_ops
method to obtain the operator after the second quantization.
Among the returned operators, the first one is the Hamiltonian we need, that is, hamiltonian = problem.second_q_ops()[0]
.
Secondary quantization is not enough, we also need to map it to a form that can be represented in quantum computing, here we can directly use Jordan Wigner mapping to complete this step:
mapper = JordanWignerMapper() converter = QubitConverter(mapper, two_qubit_reduction=False) qubit_op = converter.convert(hamiltonian)
After processing, the Hamiltonian can be represented using a Pauli matrix:
(22) | ||||
In order to use the VQE algorithm, we also need to parameterize our quantum circuit and need a suitable initial state. The VQE algorithm itself has a certain degree of randomness, which does not guarantee that a convergence result can be obtained, and a reasonable selection of the initial state can also accelerate the convergence of the algorithm. So here, we use UCCSD[14] as an assumption (Ansatz), and the initial state of the circuit is initialized to using the Hartree-Fock method.
init_state = HartreeFock(num_spin_orbitals, num_particles, converter) var_form = UCCSD( converter, num_particles, num_spin_orbitals, initial_state=init_state)

Here, our parameterized quantum circuit can be represented by FIG. 3. The three circuit gates connecting four qubits in the figure are circuit gates after packaging. The mark on the gate indicates which part the gate represents, and is our parameter.
In this way, the preparatory work is completed, and the next step is to use the VQE algorithm.
Here, we choose to use the IBM Quantum online computing platform provided by IBM Corporation to calculate our circuit.
We can use the IBMQ
interface to connect to the computing platform.
After selecting the computing device to be used, we can start computing.
Here I choose ibmq_jakarta.
provider = IBMQ.enable_account(token) backend = least_busy( provider.backends( filters=lambda x: x.configuration().n_qubits >= 6 and not x.configuration().simulator and x.status().operational == True)) print("least busy backend: ", backend)
Similarly, the VQE algorithm has already been implemented in Qiskit, so there is no need to implement it yourself. At the same time, the VQE algorithm needs to be used in conjunction with classic optimization algorithms, and most of these algorithms are implemented in Qiskit and can be used directly. Here, for the classical optimization algorithm, considering the situation and accuracy of the quantum computer, the L-BFGS algorithm is chosen to be used.
optimizer = optimizers.L_BFGS_B(maxiter=20) vqe = VQE(var_form, optimizer, quantum_instance=backend) vqe_calc = vqe.compute_minimum_eigenvalue( qubit_op) vqe_result = problem.interpret(vqe_calc) .total_energies[0].real
The L-BFGS algorithm, is an optimization algorithm in the family of quasi-Newton methods[15]. This algorithm approximates the Broyden Fletcher Goldfarb Shanno algorithm using limited computer memory. This algorithm is used to minimize over an unconstrained vector , where is a differentiable function.
As a comparison, we use the result obtained by the built-in ground state energy method in Qiskit as the exact solution, and compare it with the solution obtained by using the VQE algorithm.
V Summary
We make the atomic distance start from Å, take Å as the step distance, and continuously calculate the energy ground state of the hydrogen molecular system at different distances, we can get FIG. 4. It can be seen that the results of the VQE algorithm are in good agreement with the exact solution using the numerical method, where the energy units are Hartree.


If compared with the actual data, when the geometric distance is and , that is, dist = 0.725
, the actual data , and the data obtained by our VQE algorithm is , the error is about .
Although the data difference is greater than the chemical precision , it is still a relatively accurate solution method.
There may be three sources of error:
-
1.
The error caused by assuming that the nucleus is stationary;
-
2.
There is a certain error in the actual measurement;
-
3.
The error caused by the randomness of the VQE algorithm itself.
The second error cannot be eliminated, the first error can be reduced using a more accurate model, and the last error may be the most influential. Especially when running an algorithm on an actual quantum device, due to the limitations of the current quantum device, there is a large background noise, which will affect the coherence of the quantum, thereby affecting the result.
Acknowledgments
This work was partially supported by the National Natural Science Foundation of China under Grant Nos. 11875178 and 12005114. The work of A.W. was supported by the start-up funding from China Three Gorges University. A.W. is also grateful for the support from the Chutian Scholar Program of Hubei Province.
References
- Feynman [1986] R. P. Feynman, Quantum mechanical computers, Found. Phys. 16, 507 (1986).
- Peruzzo et al. [2014] A. Peruzzo, J. McClean, P. Shadbolt, M.-H. Yung, X.-Q. Zhou, P. J. Love, A. Aspuru-Guzik, and J. L. O’Brien, A variational eigenvalue solver on a photonic quantum processor, Nature Communications 5, 4213 (2014).
- Qiskit contributors [2023] Qiskit contributors, Qiskit: An open-source framework for quantum computing (2023).
- ibm [2023] IBM Quantum (2023), quantum-computing.ibm.com.
- Shor [1994] P. Shor, Algorithms for quantum computation: discrete logarithms and factoring, in Proceedings 35th Annual Symposium on Foundations of Computer Science (1994) pp. 124–134.
- Grover [1996] L. K. Grover, A fast quantum mechanical algorithm for database search, in Proceedings of the twenty-eighth annual ACM symposium on Theory of computing - STOC '96 (ACM Press, 1996).
- Barenco et al. [1995] A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVincenzo, N. Margolus, P. Shor, T. Sleator, J. A. Smolin, and H. Weinfurter, Elementary gates for quantum computation, Phys. Rev. A 52, 3457 (1995).
- Boykin et al. [2000] P. O. Boykin, T. Mor, M. Pulver, V. Roychowdhury, and F. Vatan, A new universal and fault-tolerant quantum basis, Inf. Process. Lett. 75, 101 (2000).
- Hartree [1928] D. R. Hartree, The wave mechanics of an atom with a non-coulomb central field. part i. theory and methods, Mathematical Proceedings of the Cambridge Philosophical Society 24, 89–110 (1928).
- Jordan and Wigner [1928] P. Jordan and E. Wigner, Über das Paulische Äquivalenzverbot, Z. Phys. 47, 631 (1928).
- Seeley et al. [2012] J. T. Seeley, M. J. Richard, and P. J. Love, The Bravyi-Kitaev transformation for quantum computation of electronic structure, J. Chem. Phys. 137, 224109 (2012).
- Slater [1929] J. C. Slater, The Theory of Complex Spectra, Phys. Rev. 34, 1293 (1929).
- Sun et al. [2018] Q. Sun, T. C. Berkelbach, N. S. Blunt, G. H. Booth, S. Guo, Z. Li, J. Liu, J. D. McClain, E. R. Sayfutyarova, S. Sharma, S. Wouters, and G. K.-L. Chan, PySCF: the Python-based simulations of chemistry framework, WIREs Comput. Mol. Sci. 8, e1340 (2018).
- McClean et al. [2016] J. R. McClean, J. Romero, R. Babbush, and A. Aspuru-Guzik, The theory of variational hybrid quantum-classical algorithms, New J. Phys. 18, 023023 (2016).
- Davidon [1959] W. Davidon, VARIABLE METRIC METHOD FOR MINIMIZATION, Tech. Rep. (Office of Scientific and Technical Information (OSTI), 1959).