VQE with MATLAB - MATLAB
Video Player is loading.
Current Time 0:00
Duration 5:14
Loaded: 3.13%
Stream Type LIVE
Remaining Time 5:14
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 5:14

    VQE with MATLAB

    Dive deep into the variational quantum eigensolver (VQE), a hybrid quantum-classical algorithm designed to find the lowest eigenvalue of a matrix. VQE is particularly useful in solving optimization problems and is widely applied in quantum chemistry and quantum simulations. Learn how to implement this algorithm using MATLAB® and MATLAB Support Package for Quantum Computing to determine the minimum ground state energy of a chemistry Hamiltonian. The VQE leverages the variational principle of physics to solve eigenvalues of matrices using classical computing methods, which can be challenging—especially for large matrices with complex numbers. By utilizing quantum computing, VQE offers a more efficient approach. In quantum mechanics, any measurable variable is called an observable, represented mathematically as a matrix. When measured, these observables yield discrete or quantized values known as eigenvalues, with corresponding eigenvectors. A Hamiltonian, representing the total energy of a system, is a key observable in quantum mechanics. The VQE algorithm estimates the lowest eigenvalue by applying the variational method. The VQE process involves two main parts: the ansatz and the classical optimizer. The ansatz is a quantum circuit with tunable parameters, mimicking a system’s ground state wavefunction or eigenvectors. The classical optimizer adjusts the parameters of the ansatz to minimize energy, iteratively finding the actual ground state. For this demo, explore a chemistry problem Hamiltonian in the second quantized form, using Pauli matrices X, Y, and Z and identity gates. Begin by defining the Hamiltonian and solving it classically to establish a benchmark for the VQE algorithm. Next, construct the ansatz and plot the quantum circuit. Then, define an optimizer using Global Optimization Toolbox to minimize the eigenvalues of the Hamiltonian. The optimizer simulates the circuit iteratively, converging to a minimum eigenvalue close to the classically calculated value. Finally, extract the optimal rotational gate values and run the circuit on both the MATLAB simulator and a hardware device hosted on AWS®. By comparing the results, verify the successful implementation of the VQE.

    Published: 10 Jul 2024

    The Variational Quantum Eigensolver, or VQE, is a hybrid quantum classical algorithm designed to find the lowest eigenvalue of a matrix. This video will show you how the VQE algorithm is implemented in MATLAB and how you can use the MATLAB Support Package for Quantum Computing to determine the minimum ground state energy of a chemistry Hamiltonian.

    As the name suggests, VQE uses the variational principles of physics to solve the eigenvalues of a matrix. Using classical computing methods to find the smallest eigenvalue is difficult, especially when the matrix is big and consists of complex numbers. This is where the variational quantum eigensolver comes into play.

    Any variable in quantum mechanics which can be measured is called an observable. Observables can be mathematically represented as a matrix in quantum mechanics. When you measure an observable of a quantum system that is bounded, you get some discrete or quantized values. These are the eigenvalues of the observable matrix. These eigenvalues will have corresponding eigenvectors.

    A Hamiltonian is an observable in quantum mechanics. And it represents the total energy of a system. The VQE algorithm estimates the lowest eigenvalue by applying the variational method with carefully selected trial eigenvectors.

    The first part of a VQE is selecting the ansatz. An ansatz is a quantum circuit where rotation gate angles are typically used as tunable parameters. The selection of an ansatz is dependent on the problem Hamiltonian. Ansatz represents a tunable quantum state and is an educated guess of the system's ground state wave function. These quantum states act as the eigenvector when acted upon by the Hamiltonian, returning eigenvalues representing the energy.

    The second part is the classical optimization. The tunable parameters of the ansatz and energy eigenvalues of the Hamiltonian are fed into the classical optimizer. The optimizer adjusts the parameters of the quantum circuit to minimize the energy. This process is repeated iteratively, gradually finding the state with the lowest possible energy, the ground state.

    Now that you understand how it works, let's see how MATLAB and the MATLAB Support Package for Quantum Computing makes it easy to implement the VQE. For this demo, let's look at a chemistry problem Hamiltonian in the second quantized form. This form means that the Hamiltonian is expressed using the Pauli matrices X, Y, Z, and identity gates only.

    These are standard quantum gates and are predefined in the MATLAB Support Package for Quantum Computing. The Observable class and estimate function used in the example are available on our File Exchange. First, we define the Hamiltonian. Since it's a simple Hamiltonian, let's solve it classically for the lowest eigenvalue, using some standard MATLAB operations. We calculate all the eigenvalues and then take the minimum to get the lowest eigenvalue of the Hamiltonian. Now we know what to expect from an VQE algorithm once it is optimized.

    Let's build the function to determine the ansatz, which will create the trial wave function and plot the circuit. Notice the parameterized rotational gates in the circuit. We want to find the minimum energy and thereby optimize these parameters.

    We've selected this ansatz for the problem because it's simple. And it's compatible with the hardware device on which we're going to run it. Now let's define an optimizer which will minimize to the lowest eigenvalue of the defined Hamiltonian from the parameters of the circuit.

    We're using the surrogate optimizer solver for MATLAB Global Optimization Toolbox for optimization of these objective functions that are expensive and time consuming. Every iteration of the optimizer is going to simulate the circuit with 1,000 shots each time.

    You can see our optimizer converges to a minimum eigenvalue of negative 0.936, which is very close to the classically calculated and expected value of negative 0.9406. Let's now extract the optimal set of values of the rotational gates of the ansatz, which results in this minimum eigenvalue. Now we have the optimal values of rotational gates of the ansatz.

    So let's run the circuit on the MATLAB Simulator. Let's also rerun the Matlab authored circuit on a hardware device, Aria 1, hosted on AWS. The results are stored in the Amazon S3 bucket. So we need to fetch it from there to our local machine.

    Comparing the simulation and hardware results, you will find that both the results show the binary state 01 with highest probability. This verifies our implementation of the VQE on both the MATLAB Simulator and the hardware. If you'd like to take a deeper look at a VQE, download the MATLAB Support Package for Quantum Computing. And check out the example linked in the description below. Thanks for watching.

    View more related videos