qrisp.vqe.VQEProblem.benchmark#
- VQEProblem.benchmark(qarg, depth_range, precision_range, iter_range, optimal_energy, repetitions=1, mes_kwargs={}, init_type='random', optimizer='COBYLA', options={})[source]#
This method enables convenient data collection regarding performance of the implementation.
- Parameters:
- qargQuantumVariable or callable
The argument to which the VQE circuit is applied, or a function returning a QuantumVariable to which the VQE circuit is applied.
- depth_rangelist[int]
A list of integers indicating, which depth parameters should be explored. Depth means the amount of VQE ansatz 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 for the
expectation_value
function. Default is an empty dictionary.- init_typestr, optional
Specifies the way the initial optimization parameters are chosen. Available is
random
. The default israndom
: Parameters are initialized uniformly at random in the interval \([0,\pi/2)]\).- optimizerstr, optional
Specifies the SciPy optimization routine. Available are, e.g.,
COBYLA
,COBYQA
,Nelder-Mead
. The Default isCOBYLA
.- optionsdict
A dictionary of solver options.
- 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(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()
The VQEBenchmark class contains a variety of methods to help you drawing conclusions from the collected data. Make sure to check them out!