See also

A Jupyter notebook version of this tutorial can be downloaded here.

image0

Single qubit randomized benchmarking#

Single-qubit randomized benchmarking measures the single-qubit gates fidelity. For this experiment a sequence of random Clifford gates is generated (one sequence per seed), and for each experiment an increasing portion of this sequence is executed (different gate string lengths m) before the qubit is returned to its initial state. A fit of the exponential decay of the overlap between initial and final states gives the average error per Clifford gate, while the variance in this \(⟨\psi_f|\psi_i⟩\) overlap between seeds for the same gate string length gives an estimate of the degree to which this error is coherent.

[1]:
import numpy as np
from dependencies.analysis_utils import RBAnalysis
from dependencies.randomized_benchmarking.utils import randomized_benchmarking_schedule
from xarray import open_dataset

from qblox_scheduler import HardwareAgent
Generating hash table for SingleQubitClifford.
Hash table generated.
Generating hash table for TwoQubitCliffordCZ.
Hash table generated.
Generating hash table for TwoQubitCliffordZX.
Hash table generated.
Testing decompositions.
Test passed.

Setup#

The hardware agent manages the connection to the instrument and ensures that pulses and acquisitions happen over the appropriate input and output channels of the Cluster. The cell below creates an instance of the HardwareAgent based on the hardware- and device-under-test configuration files in the ./dependencies/configs folder, allowing us to start doing measurements. We also define some convenient aliases to use throughout our measurements. For a more thorough discussion of the hardware- and device-under-test configuration files, check out this tutorial.

[2]:
# Set up hardware agent, this automatically connects to the instrument
hw_agent = HardwareAgent(
    hardware_configuration="./dependencies/configs/hw_config.json",
    quantum_device_configuration="./dependencies/configs/dut_config.json",
)

# convenience aliases
q0 = hw_agent.quantum_device.get_element("q0")
q2 = hw_agent.quantum_device.get_element("q2")
cluster = hw_agent.get_clusters()["cluster"]
hw_options = hw_agent.hardware_configuration.hardware_options
qubit = q0
/builds/0/.venv/lib/python3.10/site-packages/qblox_scheduler/qblox/hardware_agent.py:460: UserWarning: cluster: Trying to instantiate cluster with ip 'None'.Creating a dummy cluster.
  warnings.warn(

Experiment settings#

[3]:
# RB settings
lengths = np.arange(0, 40, 5)
seeds = np.random.randint(0, 2**31 - 1, size=10, dtype=np.int32)

repetitions = 1

Experiment schedule#

[4]:
sched = randomized_benchmarking_schedule(
    qubit.name,
    lengths=lengths,
    repetitions=repetitions,
    seeds=seeds,
)

# Execute the experiment
rb_data = hw_agent.run(sched)
if cluster.is_dummy:
    example_data = open_dataset(
        "./dependencies/datasets/single_qubit_randomized_benchmarking.hdf5", engine="h5netcdf"
    )
    rb_data.update({"S_21": example_data.S_21, "calibration": example_data.calibration})

Analyze the experiment#

[5]:
rb_analysis = RBAnalysis(rb_data).run()
rb_analysis.display_figs_mpl()
/builds/0/.venv/lib/python3.10/site-packages/numpy/lib/_function_base_impl.py:644: ComplexWarning: Casting complex values to real discards the imaginary part
  a = asarray(a, dtype=dtype, order=order)
/builds/0/.venv/lib/python3.10/site-packages/matplotlib/cbook.py:1719: ComplexWarning: Casting complex values to real discards the imaginary part
  return math.isfinite(val)
/builds/0/.venv/lib/python3.10/site-packages/matplotlib/collections.py:200: ComplexWarning: Casting complex values to real discards the imaginary part
  offsets = np.asanyarray(offsets, float)
../../../_images/applications_superconducting_fixed_frequency_transmon_300_randomized_benchmarking_10_1.png