qrisp.vqe.VQEProblem.benchmark#

VQEProblem.benchmark(qarg, depth_range, precision_range, iter_range, optimal_energy, repetitions=1, mes_kwargs={}, init_type='random')[source]#

This method enables convenient data collection regarding performance of the implementation.

Parameters:
qargQuantumVariable or QuantumArray

The quantum argument the benchmark is executed on. Compare to the .run method.

depth_rangelist[int]

A list of integers indicating, which depth parameters should be explored. Depth means the amount of VQE layers.

precision_rangelist[float]

A list of floats indicating, which precision parameters should be explored. Precision refers to how accurately the Hamiltonian is evaluated. The number of shots the backend performs per iteration scales quadratically with the inverse precision.

iter_rangelist[int]

A list of integers indicating, what iterations parameter should be explored. Iterations means the amount of backend calls, the optimizer is allowed to do.

optimal_energyfloat

The exact ground state energy of the problem Hamiltonian.

repetitionsint, optional

The amount of repetitions, each parameter constellation should go though. Can be used to get a better statistical significance. The default is 1.

mes_kwargsdict, optional

The keyword arguments, that are used for the get_measurement function. The default is {}.

init_typestring, optional

Specifies the way the initial optimization parameters are chosen. Available is random. The default is random: Parameters are initialized uniformly at random in the interval \([0,\pi/2)]\).

Returns:
VQEBenchmark

The results of the benchmark.

Examples

We create a Heisenberg problem instance and benchmark several parameters:

from qrisp import QuantumVariable
from qrisp.vqe.problems.heisenberg import *
from networkx import Graph

G = Graph()
G.add_edges_from([(0,1),(1,2),(2,3),(3,4)])

vqe = heisenberg_problem(G,1,0)
H = create_heisenberg_hamiltonian(G,1,0)

benchmark_data = vqe.benchmark(qarg = QuantumVariable(5),
                    depth_range = [1,2,3],
                    precision_range = [0.02,0.01],
                    iter_range = [25,50],
                    optimal_energy = H.ground_state_energy(),
                    repetitions = 2
                    )

We can investigate the data by calling visualize:

benchmark_data.visualize()
../../../../_images/vqe_benchmark_plot.png

The VQEBenchmark class contains a variety of methods to help you drawing conclusions from the collected data. Make sure to check them out!