qcmet.benchmarks.BenchmarkCollection#
- class qcmet.benchmarks.BenchmarkCollection(benchmarks, save_path=None)[source]#
A collection of BaseBenchmark instances.
This class defines a wrapper for collecting different benchmarks into one. This class inherits from BaseBenchmark, providing the same API as other benchmarks.
- __init__(benchmarks, save_path=None)[source]#
Initialize a BenchmarkCollection instance.
- Parameters:
benchmarks (List[BaseBenchmark] | Dict[str, BaseBenchmark]) – Either: - List[BaseBenchmark]: List of BaseBenchmark instances. - Dict[str, BaseBenchmark]: Dictionary of {identifier: BaseBenchmark}. The label of each benchmark will be created in the format of “Benchmark{index}_{benchmark.name}” if no identifiers provided or as “identifier” if the benchmarks are passed in as a dictionary.
save_path (str | Path | FileManager, optional) – Path to save benchmark outputs. Defaults to None.
Methods
__init__(benchmarks[, save_path])Initialize a BenchmarkCollection instance.
analyze()Analyze measurements to return benchmark results.
generate_circuits()Generate benchmark circuits, user facing.
Check if _plot function is implemented for at least one of the benchmarks in the collection.
load_circuit_measurements(circuit_measurements)Load measurement counts into the experiment_data DataFrame.
measurements_to_probabilities()Convert raw measurement counts to normalized probabilities.
plot([axes])Plot benchmark results for all benchmarks in the collection that has a plot function.
run([device, num_shots])Run all benchmarks in the collection.
save()Call each benchmark in the collection to save the results.
set_save_path(save_path)Set benchmark save path if not set in class constructor.
Attributes
circuitsGets all benchmark circuits.
experiment_dataGetter for experiment_data dataframe.
Return the number of qubits for each benchmark in the collection.
- property num_qubits: Dict#
Return the number of qubits for each benchmark in the collection. Overrides BaseBenchmark.num_qubits.
- run(device=None, num_shots=1024, **kwargs)[source]#
Run all benchmarks in the collection. Overrides BaseBenchmark.run.
If num_shots is int, super().run() is called to run all circuits from all benchmarks in one go. Otherwise, each benchmark is called to run in sequence with a different specified number of shots, and self._experiment_data and self._runtime_params will be left as None, since each benchmark will have their own _experiment_data and _runtime_params generated by their respective run.
- Parameters:
device (BaseDevice, optional) – Device to run benchmark on. Defaults to None.
num_shots (int | List[int], optional) – Either - int: Number of shots, applied to all benchmarks in the collection. - List[int]: A list of number of shots for each benchmark in the collection. Defaults to 1024.
**kwargs (Dict[str, any]) – Optional keyword arguments passed to device in _runtime_params.
- has_plotting()[source]#
Check if _plot function is implemented for at least one of the benchmarks in the collection.
Overrides BaseBenchmark.has_plotting.
- Returns:
True if at least one of the benchmarks in the collection have a plot function.
- Return type:
- plot(axes=None)[source]#
Plot benchmark results for all benchmarks in the collection that has a plot function.
- Parameters:
axes (List[matplotlib.axes._axes.Axes], optional) – Plot will use axes if provided. The length of this list must be equal to the number of benchmarks in the collection with plotting implemented. Defaults to None.