Introduction
The Variational Quantum Eigensolver (VQE) algorithm is a hybrid quantum-classical method developed to estimate the ground-state energy of a quantum system, described by a Hamiltonian \( H \). It leverages the variational principle and quantum computing to prepare trial wavefunctions and evaluate their energy expectation values efficiently, making it a key algorithm for near-term quantum devices.
Variational Principle
The variational principle is a fundamental concept in quantum mechanics that provides a method for approximating the ground-state energy of a system. It states that for any trial wavefunction \( |\psi(\vec{\theta})\rangle \), the expectation value of the Hamiltonian \( H \), denoted by \( E(\vec{\theta}) \), is an upper bound to the ground-state energy \( E_0 \):
\[
E_0 \leq E(\vec{\theta}) = \langle \psi(\vec{\theta}) | H | \psi(\vec{\theta}) \rangle
\]
Equality holds only if the trial wavefunction \( |\psi(\vec{\theta})\rangle \) is exactly the ground state of \( H \). This principle allows us to approximate the ground-state energy by optimizing the parameters \( \vec{\theta} \) of the trial wavefunction to minimize \( E(\vec{\theta}) \).
A key advantage of the variational principle is that it guarantees the calculated energy \( E(\vec{\theta}) \) will not be lower than the true ground-state energy, making it a reliable method for quantum systems.
VQE Algorithm Workflow
- Hamiltonian Representation: Decompose the Hamiltonian \( H \) into a sum of weighted tensor products of Pauli operators:
\[
H = \sum_i c_i P_i
\]
where \( c_i \) are real coefficients, and \( P_i \) are tensor products of Pauli matrices and identity operators. This decomposition enables efficient computation of \( H \) on quantum hardware. - Parameterized Quantum Circuit: Construct a parameterized quantum circuit to prepare the trial wavefunction \( |\psi(\vec{\theta})\rangle \), where \( \vec{\theta} \) are adjustable parameters. The circuit design should balance expressivity (to explore the Hilbert space) and efficiency (to minimize hardware requirements).
- Energy Expectation Measurement: Compute the energy expectation value \( E(\vec{\theta}) \):
\[
E(\vec{\theta}) = \langle \psi(\vec{\theta}) | H | \psi(\vec{\theta}) \rangle = \sum_i c_i \langle \psi(\vec{\theta}) | P_i | \psi(\vec{\theta}) \rangle
\]
For each term \( \langle \psi(\vec{\theta}) | P_i | \psi(\vec{\theta}) \rangle \), \( P_i \) can have multiple eigenvalues (e.g., \( +1, -1 \), or others in a higher-dimensional space, depending on its dimension). The expectation value is computed as:
\[
\langle P_i \rangle = \sum_j \lambda_j p_j
\]
where \( \lambda_j \) are the eigenvalues of \( P_i \) and \( p_j \) are the corresponding probabilities of observing those eigenvalues during measurement. - Classical Optimization: Use a classical optimization algorithm to iteratively adjust \( \vec{\theta} \) to minimize \( E(\vec{\theta}) \). Common optimizers include gradient-based methods (e.g., Adam) or gradient-free techniques (e.g., COBYLA, Nelder-Mead).
- Ground-State Approximation: The optimized parameters \( \vec{\theta} \) produce a trial wavefunction \( |\psi(\vec{\theta})\rangle \), which approximates the ground state of \( H \). The corresponding energy \( E(\vec{\theta}) \) is the estimated ground-state energy.
Practical Implementation of VQE for Ground-State Computation
from logicqubit.logic import * from scipy.optimize import * gates = Gates() ID = gates.ID() X = gates.X() Y = gates.Y() Z = gates.Z() II = ID.kron(ID) YY = Y.kron(Y) IZ = ID.kron(Z) ZI = Z.kron(ID) ZZ = Z.kron(Z) # eignvalues of X,Y,Z: [1, -1] and I: [1, 1] # signs to be used in calculating the expected value sig_ss = np.kron([1, -1], [1, -1]) sig_is = np.kron([1, 1], [1, -1]) sig_si = np.kron([1, -1], [1, 1])
Classical Solution
import scipy # Define the Hamiltonian as a linear combination of tensor products of Pauli matrices and the identity operator # H = 2*II + YY + 3*IZ - ZI + 2*ZZ H = 2*II.get() + YY.get() + 3*IZ.get() - ZI.get() + 2*ZZ.get() # The ground-state energy is the minimum eigenvalue value = min(scipy.linalg.eig(H)[0]) # Output the minimum eigenvalue (ground-state energy) print("Minimum eigenvalue:", value) Minimum eigenvalue: (-4.123105625617661+0j)
Variational Quantum Eignsolver Solution
# Define the parameterized quantum circuit (ansatz) with six adjustable parameters def ansatz_2q(q1, q2, params): # q1, q2 are qubits; params is the list of parameters q2.CNOT(q1) q1.RY(params[0]) # Apply rotation gates parameterized by params q2.RY(params[1]) q1.CNOT(q2) q1.RY(params[2]) q2.RY(params[3]) q2.CNOT(q1) q1.RY(params[4]) q2.RY(params[5]) # Compute the expectation value for a set of measurement results def expectation_value(measurements, base=np.array([1, -1, -1, 1])): probabilities = np.array(measurements) # Convert measurements to probabilities expectation = np.sum(base * probabilities) return expectation # Compute the expectation value for the YY term of the Hamiltonian def sigma_yy(params): logicQuBit = LogicQuBit(2, first_left=False) # Initialize a 2-qubit system q1 = Qubit() q2 = Qubit() ansatz_2q(q1, q2, params) # Apply the ansatz circuit # Apply the measurement basis change for YY (rotation gates) q1.RX(pi / 2) q2.RX(pi / 2) # Measure the qubits and calculate the expectation value result = logicQuBit.Measure([q1, q2]) result = expectation_value(result) return result # Compute the expectation values for the ZZ, IZ, and ZI terms of the Hamiltonian def sigma_zz(params): logicQuBit = LogicQuBit(2, first_left=False) # Initialize a 2-qubit system q1 = Qubit() q2 = Qubit() ansatz_2q(q1, q2, params) # Apply the ansatz circuit # Measure the qubits and calculate the expectation values result = logicQuBit.Measure([q1, q2]) # ZZ, IZ, and ZI commute ([ZZ, IZ] = [ZZ, ZI] = 0), allowing their simultaneous measurement. zz = expectation_value(result) # Expectation value for ZZ iz = expectation_value(result, sig_is) # Expectation value for IZ zi = expectation_value(result, sig_si) # Expectation value for ZI return zz, iz, zi # Define the energy expectation value as a function of the circuit parameters def expectation_energy(params): # Calculate individual term contributions yy = sigma_yy(params) zz, iz, zi = sigma_zz(params) # Combine the contributions to compute the total energy result = 2 + yy + 3 * iz - zi + 2 * zz return result # Minimize the energy expectation value using a classical optimization algorithm minimum = minimize(expectation_energy, [0, 0, 0, 0, 0, 0], method='Nelder-Mead', options={'xtol': 1e-10, 'ftol': 1e-10}) ground_state = minimum['fun'] print("Ground State:", ground_state) Ground State: -4.123105623206764
The error between the classical method and the VQE algorithm is quantified as
error = abs(min_eigenvalue - ground_state) print("Error:", error) Error: 2.4108963714297715e-09
Check out the Colab Notebook.
Conclusion
The Variational Quantum Eigensolver (VQE) algorithm combines quantum computation to explore the Hilbert space with classical optimization for refining solutions. By applying the variational principle, it provides an efficient method to approximate the ground-state energy of complex quantum systems.
The example demonstrates how VQE successfully approximates the ground-state energy of a Hamiltonian using parameterized circuits and iterative optimization, producing results consistent with classical methods. Its efficiency is enhanced by techniques like Hamiltonian decomposition and simultaneous measurement of commuting operators. VQE is particularly valuable for applications in quantum chemistry, material science, and optimization problems, offering a practical approach for noisy intermediate-scale quantum (NISQ) devices.