StandardRB¶
- class StandardRB(physical_qubits, lengths, backend=None, num_samples=3, seed=None, full_sampling=False)[source]¶
An experiment to characterize the error rate of a gate set on a device.
Overview
Randomized Benchmarking (RB) is an efficient and robust method for estimating the average error rate of a set of quantum gate operations. See Qiskit Textbook for an explanation on the RB method.
A standard RB experiment generates sequences of random Cliffords such that the unitary computed by the sequences is the identity. After running the sequences on a backend, it calculates the probabilities to get back to the ground state, fits an exponentially decaying curve, and estimates the Error Per Clifford (EPC), as described in Refs. [1, 2].
Note
In 0.5.0, the default value of
optimization_levelintranspile_optionschanged from0to1for RB experiments. That may result in shorter RB circuits hence slower decay curves than before.References
User manual
Analysis class reference
Experiment options
These options can be set by the
set_experiment_options()method.- Options
Defined in the class
StandardRB:lengths (List[int])
Default value:NoneA list of RB sequences lengths.num_samples (int)
Default value:NoneNumber of samples to generate for each sequence length.seed (None or int or SeedSequence or BitGenerator or Generator)
Default value:NoneA seed used to initializenumpy.random.default_rngwhen generating circuits. Thedefault_rngwill be initialized with this seed value every timecircuits()is called.full_sampling (bool)
Default value:NoneIf True all Cliffords are independently sampled for all lengths. If False for sample of lengths longer sequences are constructed by appending additional Clifford samples to shorter sequences.clifford_synthesis_method (str)
Default value:"rb_default"The name of the Clifford synthesis plugin to use for building circuits of RB sequences. See Synthesis Methods.
Defined in the class
BaseExperiment:max_circuits (Optional[int])
Default value:NoneThe maximum number of circuits per job when running an experiment on a backend.
Example
import numpy as np from qiskit_experiments.library import StandardRB, InterleavedRB from qiskit_experiments.framework import ParallelExperiment, BatchExperiment import qiskit.circuit.library as circuits lengths_2_qubit = np.arange(1, 70, 10) lengths_1_qubit = np.arange(1, 400, 80) num_samples = 3 seed = 1010 qubits = (1, 2) # Run a 1-qubit RB experiment on qubits 1, 2 to determine the error-per-gate of 1-qubit gates single_exps = BatchExperiment( [ StandardRB((qubit,), lengths_1_qubit, num_samples=num_samples, seed=seed) for qubit in qubits ] ) expdata_1q = single_exps.run(backend=backend).block_for_results() exp_2q = StandardRB(qubits, lengths_2_qubit, num_samples=num_samples, seed=seed) # Use the EPG data of the 1-qubit runs to ensure correct 2-qubit EPG computation exp_2q.analysis.set_options(epg_1_qubit=expdata_1q.analysis_results(dataframe=True)) expdata_2q = exp_2q.run(backend=backend).block_for_results() results_2q = expdata_2q.analysis_results(dataframe=True) print("Gate error ratio: %s" % expdata_2q.experiment.analysis.options.gate_error_ratio) display(expdata_2q.figure(0)) print(f"Available results: {set(results_2q.name)}")
Gate error ratio: {'cx': 1.0}
Available results: {'EPC_corrected', 'alpha', 'EPC', 'EPG_cx'}Initialization
Initialize a standard randomized benchmarking experiment.
- Parameters:
physical_qubits (Sequence[int]) – List of physical qubits for the experiment.
lengths (Iterable[int]) – A list of RB sequences lengths.
backend (Backend | None) – The backend to run the experiment on.
num_samples (int) – Number of samples to generate for each sequence length.
seed (int | SeedSequence | BitGenerator | Generator | None) – Optional, seed used to initialize
numpy.random.default_rng. when generating circuits. Thedefault_rngwill be initialized with this seed value every timecircuits()is called.full_sampling (bool | None) – If True all Cliffords are independently sampled for all lengths. If False for sample of lengths longer sequences are constructed by appending additional samples to shorter sequences. The default is False.
- Raises:
QiskitError – If any invalid argument is supplied.
Attributes
- analysis¶
Return the analysis instance for the experiment
- backend¶
Return the backend for the experiment
- experiment_options¶
Return the options for the experiment.
- experiment_type¶
Return experiment type.
- num_qubits¶
Return the number of qubits for the experiment.
- physical_qubits¶
Return the device qubits for the experiment.
Methods
- circuits()[source]¶
Return a list of RB circuits.
- Returns:
A list of
QuantumCircuit.- Return type:
list[QuantumCircuit]
- config()¶
Return the config dataclass for this experiment
- Return type:
- copy()¶
Return a copy of the experiment
- Return type:
- classmethod from_config(config)¶
Initialize an experiment from experiment config
- Return type:
- job_info(backend=None)¶
Get information about job distribution for the experiment on a specific backend.
- Parameters:
backend (Backend) – Optional, the backend for which to get job distribution information. If not specified, the experiment must already have a set backend.
- Returns:
A dictionary containing information about job distribution.
”Total number of circuits in the experiment”: Total number of circuits in the experiment.
”Maximum number of circuits per job”: Maximum number of circuits in one job based on backend and experiment settings.
”Total number of jobs”: Number of jobs needed to run this experiment on the currently set backend.
- Return type:
dict
- Raises:
QiskitError – if backend is not specified.
- run(backend=None, sampler=None, analysis='default', timeout=None, backend_run=None, **run_options)¶
Run an experiment and perform analysis.
- Parameters:
backend (Backend | None) – Optional, the backend to run on. Will override existing backend settings.
sampler (BaseSamplerV2 | None) – Optional, the sampler to run the experiment on. If None then a sampler will be invoked from previously set backend
analysis (BaseAnalysis | None) – Optional, a custom analysis instance to use for performing analysis. If None analysis will not be run. If
"default"the experimentsanalysis()instance will be used if it contains one.timeout (float | None) – Time to wait for experiment jobs to finish running before cancelling.
backend_run (bool | None) – Use backend run (temp option for testing)
run_options – backend runtime options used for circuit execution.
- Returns:
The experiment data object.
- Raises:
QiskitError – If experiment is run with an incompatible existing ExperimentData container.
- Return type:
- set_experiment_options(**fields)¶
Set the experiment options.
- Parameters:
fields – The fields to update the options
- Raises:
AttributeError – If the field passed in is not a supported options
- set_run_options(**fields)¶
Set options values for the experiment
run()method.- Parameters:
fields – The fields to update the options
See also
The Setting options for your experiment guide for code example.
- set_transpile_options(**fields)¶
Set the transpiler options for
run()method.- Parameters:
fields – The fields to update the options
- Raises:
QiskitError – If initial_layout is one of the fields.
See also
The Setting options for your experiment guide for code example.