VQE

VQE

In Divi, we offer two different VQE modes. The first one is a standard single-instance ground-state energy estimation, and the latter is the hyperparameter sweep mode. We will provide examples to demonstrate modes in this section.

Vanilla VQE

For our VQE implementation, we integrate tightly with PennyLane’s qchem module. As such, the VQE constructor accepts a list of symbols as well as their unit coordinates to generate a Molecule object, which is then used to generate the molecular Hamiltonian. The constructor also accepts a bond_length argument, which is multiplied by each coordinate item to generate the final coordinates of the molecule.

Apart from the molecular information, the constructor also takes as input an ansatz, which can be selected from the available ansatze in the VQEAnsatz class, as well as the number of ansatz layers, the optimizer and the maximum number of optimization iterations. An example of how to initialize a VQE object is shown below:

import time

from divi.parallel_simulator import ParallelSimulator
from divi.qprog import VQE, VQEAnsatz
from divi.qprog.optimizers import Optimizers

vqe_problem = VQE(
    symbols=["H", "H"],
    bond_length=0.5,
    coordinate_structure=[(0, 0, 0), (0, 0, 1)],
    ansatz=VQEAnsatz.HARTREE_FOCK,
    n_layers=1,
    optimizer=Optimizer.L_BFGS_B,
    max_iterations=3,
    backend=ParallelSimulator(),
)

vqe_problem.run()
energies = vqe_problem.losses[-1]

print(f"Minimum Energy Achieved: {min(energies.values()):.4f}")
print(f"Total circuits: {vqe_problem.total_circuit_count}")

In the example above, we attempt to compute the ground state energy of a hydrogen molecule (H₂). To extract the energy at the end of the optimization step, we simply access the last item of the losses class variable, which stores the losses of each iteration in the form of a dictionary mapping a parameter’s ID to its actual values. For L-BFGS-B, an iteration uses one set of parameters, and so the min(energies.values()) bit you see in the example is a bit redundant. If we were to use Monte-Carlo sampling, we would have as many losses as the sample points, and so the use of the min function becomes more salient.

VQE Hyperparameter Sweep

By sweeping over physical parameters like bond length and varying the ansatz, this mode enables large-scale quantum chemistry simulations — efficiently distributing the workload across cloud or hybrid backends.

This mode is particularly useful for the study molecular behavior and reaction dynamics. It also allows one to compare ansatz performance and optimizer robustness. All through a single class!

The example below demonstrates how to use Divi’s VQEHyperparameterSweep class to run a parallelized VQE simulation across multiple bond lengths and ansatz types for a hydrogen molecule (H₂).

from divi.qprog import VQEAnsatz, VQEHyperparameterSweep
from divi.qprog.optimizers import Optimizers
from divi import QoroService

q_service = QoroService(QORO_API_KEY, shots=5000)

vqe_problem = VQEHyperparameterSweep(
    symbols=["H", "H"],
    coordinate_structure=[(0, 0, 0), (0, 0, 1)],
    bond_lengths=list(np.linspace(0.1, 2.7, 15)),
    ansatze=[VQEAnsatz.HARTREE_FOCK, VQEAnsatz.UCCSD],
    max_iterations=1,
    optimizer=Optimizer.MONTE_CARLO,
    backend=q_service,
)

vqe_problem.create_programs()
vqe_problem.run()
vqe_problem.aggregate_results()

print(f"Total circuits: {vqe_problem.total_circuit_count}")
print(f"Simulation time: {vqe_problem.total_run_time}")

vqe_problem.visualize_results()

What’s Happening?

Step Description
VQEHyperparameterSweep(...) Initializes a batch of VQE programs over a range of bond lengths and ansatz strategies.
symbols=["H", "H"] Defines a hydrogen molecule with two atoms, as shown before.
bond_lengths=... Sweeps bond distances from 0.1 to 2.7 Å in 15 steps.
ansatze=[HARTREE_FOCK, UCCSD] Runs two different quantum circuit models for comparison.
create_programs() Constructs all circuits for each (bond length, ansatz) pair.
run() Executes all VQE circuits — possibly in parallel.
aggregate_results() Collects and merges the final energy values for plotting.
visualize_results() Displays a graph of energy vs. bond length for each ansatz.

Visualization

Divi comes built with visualization tools that allows the user to compare the approaches. The above example produces this plot for example. This is an ongoing effort, the goal is to provide dashboards for better visualization and a more in-depth comparison.

Parallelized VQE energy levels

The result of running parallelized VQE

Why Parallelize VQE?

  • VQE is an iterative algorithm requiring multiple circuit evaluations per step.
  • Sweeping over bond lengths and ansatze creates hundreds of circuits.
  • Parallelizing execution reduces total compute time and helps saturate available QPU/GPU/CPU resources.