Skip to content

Commit

Permalink
Add minimal working code examples in Experiment API docs (#1494)
Browse files Browse the repository at this point in the history
### Summary

This change adds minimal working code examples to the API pages for
Experiments,
    EFSpectroscopy,
    EFRabi,
    StarkRamseyXYAmpScan,
    FineAmplitudeCal,
    FineXAmplitudeCal,
    FineSXAmplitudeCal,
    FineDragCal,
    FineXDragCal,
    FineSXDragCal,
    FineFrequencyCal,
    FrequencyCal,
    HalfAngleCal,
    RoughAmplitudeCal,
    RoughXSXAmplitudeCal,
    EFRoughXSXAmplitudeCal,
    RoughDragCal,
    RoughFrequencyCal,
    QuantumVolume,
    InterleavedRB,
    LayerFidelity,
    StandardRB,
    MitigatedProcessTomography,
    MitigatedStateTomography,
    ProcessTomography,
    StateTomography and
    TomographyExperiment.

### Details and comments

- This PR covers many remaining experiments in `issue#1238` and
`issue#1221`.
- In the API pages, the documentation for each experiment has been
updated with its code example. Users are required to specify a backend
in the code example. By default, backends used in the code examples, are
simulators such as, SingleTransmonTestBackend() and
AerSimulator(FakePerth()).

---------

Co-authored-by: 中澤 直仁 <[email protected]>
  • Loading branch information
Naohnakazawa and 中澤 直仁 authored Dec 18, 2024
1 parent 840a231 commit cc258d7
Show file tree
Hide file tree
Showing 23 changed files with 867 additions and 25 deletions.
1 change: 1 addition & 0 deletions qiskit_experiments/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
~randomized_benchmarking.StandardRB
~randomized_benchmarking.InterleavedRB
~randomized_benchmarking.LayerFidelity
~tomography.TomographyExperiment
~tomography.StateTomography
~tomography.ProcessTomography
Expand Down
111 changes: 109 additions & 2 deletions qiskit_experiments/library/calibration/fine_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@ class FineAmplitudeCal(BaseCalibrationExperiment, FineAmplitude):
experiment the circuits that are run have a custom gate with the pulse schedule attached
to it through the calibrations.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
# backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=True, seed=101)
.. jupyter-execute::
import numpy as np
from qiskit.circuit.library import SXGate
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineAmplitudeCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.030})
cals = Calibrations.from_backend(backend=backend, libraries=[library])
exp_cal = FineAmplitudeCal(physical_qubits=(0,),
calibrations=cals,
schedule_name="sx",
backend=backend,
cal_parameter_name="amp",
auto_update=True,
gate=SXGate(),
measurement_qubits=(0,))
# This option is necessary!
exp_cal.analysis.set_options(fixed_parameters={"angle_per_gate" : np.pi / 2,
"phase_offset" : np.pi})
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
Expand Down Expand Up @@ -156,7 +193,42 @@ def update_calibrations(self, experiment_data: ExperimentData):


class FineXAmplitudeCal(FineAmplitudeCal):
"""A calibration experiment to calibrate the amplitude of the X schedule."""
"""A calibration experiment to calibrate the amplitude of the X schedule.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
# backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=True, seed=111)
.. jupyter-execute::
import numpy as np
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineXAmplitudeCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.030})
cals = Calibrations.from_backend(backend, libraries=[library])
exp_cal = FineXAmplitudeCal((0,),
cals,
schedule_name="x",
backend=backend,
cal_parameter_name="amp",
auto_update=True,
)
exp_data = exp_cal.run().block_for_results()
display(exp_data.figure(0))
exp_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down Expand Up @@ -204,7 +276,42 @@ def _pre_circuit(self, num_clbits: int) -> QuantumCircuit:


class FineSXAmplitudeCal(FineAmplitudeCal):
"""A calibration experiment to calibrate the amplitude of the SX schedule."""
"""A calibration experiment to calibrate the amplitude of the SX schedule.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
# backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=True, seed=105)
.. jupyter-execute::
import numpy as np
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineSXAmplitudeCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.015})
cals = Calibrations.from_backend(backend, libraries=[library])
exp_cal = FineSXAmplitudeCal((0,),
cals,
schedule_name="sx",
backend=backend,
cal_parameter_name="amp",
auto_update=True,
)
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down
106 changes: 103 additions & 3 deletions qiskit_experiments/library/calibration/fine_drag_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,41 @@


class FineDragCal(BaseCalibrationExperiment, FineDrag):
"""A calibration version of the fine DRAG experiment."""
"""A calibration version of the fine DRAG experiment.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
#backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=False, seed=108)
.. jupyter-execute::
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineDragCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.030, "beta": 0.0})
cals = Calibrations.from_backend(backend, libraries=[library])
exp_cal = FineDragCal((0,),
calibrations=cals,
backend=backend,
schedule_name="sx",
cal_parameter_name="β",
auto_update=True,
)
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down Expand Up @@ -146,7 +180,40 @@ def update_calibrations(self, experiment_data: ExperimentData):


class FineXDragCal(FineDragCal):
"""Fine DRAG calibration of X gate."""
"""Fine DRAG calibration of X gate.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
#backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=False, seed=118)
.. jupyter-execute::
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineXDragCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.030, "beta": 0.0})
cals = Calibrations.from_backend(backend, libraries=[library])
exp_cal = FineXDragCal((0,),
calibrations=cals,
backend=backend,
cal_parameter_name="β",
auto_update=True,
)
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down Expand Up @@ -178,7 +245,40 @@ def __init__(


class FineSXDragCal(FineDragCal):
"""Fine DRAG calibration of X gate."""
"""Fine DRAG calibration of X gate.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
#backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=False, seed=118)
.. jupyter-execute::
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library import FineSXDragCal
library = FixedFrequencyTransmon(default_values={"duration": 320, "amp": 0.030, "beta": 0.0})
cals = Calibrations.from_backend(backend=backend, libraries=[library])
exp_cal = FineSXDragCal((0,),
calibrations=cals,
backend=backend,
cal_parameter_name="β",
auto_update=True,
)
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down
30 changes: 29 additions & 1 deletion qiskit_experiments/library/calibration/fine_frequency_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,35 @@


class FineFrequencyCal(BaseCalibrationExperiment, FineFrequency):
"""A calibration version of the fine frequency experiment."""
"""A calibration version of the fine frequency experiment.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
# backend
from qiskit_ibm_runtime.fake_provider import FakePerth
from qiskit_aer import AerSimulator
backend = AerSimulator.from_backend(FakePerth())
.. jupyter-execute::
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library.calibration.fine_frequency_cal import FineFrequencyCal
cals = Calibrations.from_backend(backend=backend, libraries=[FixedFrequencyTransmon()])
exp_cal = FineFrequencyCal((0,), cals, backend=backend, auto_update=False, gate_name="sx")
cal_data=exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down
30 changes: 29 additions & 1 deletion qiskit_experiments/library/calibration/frequency_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,35 @@


class FrequencyCal(BaseCalibrationExperiment, RamseyXY):
"""A qubit frequency calibration experiment based on the Ramsey XY experiment."""
"""A qubit frequency calibration experiment based on the Ramsey XY experiment.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
# backend
from qiskit_ibm_runtime.fake_provider import FakePerth
from qiskit_aer import AerSimulator
backend = AerSimulator.from_backend(FakePerth())
.. jupyter-execute::
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library.calibration.frequency_cal import FrequencyCal
cals = Calibrations.from_backend(backend=backend, libraries=[FixedFrequencyTransmon()])
exp_cal = FrequencyCal((0,), cals, backend=backend, auto_update=False)
cal_data=exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down
44 changes: 43 additions & 1 deletion qiskit_experiments/library/calibration/half_angle_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,49 @@


class HalfAngleCal(BaseCalibrationExperiment, HalfAngle):
"""Calibration version of the :class:`.HalfAngle` experiment."""
"""Calibration version of the :class:`.HalfAngle` experiment.
# section: example
.. jupyter-execute::
:hide-code:
import warnings
warnings.filterwarnings("ignore", ".*Could not determine job completion time.*", UserWarning)
warnings.filterwarnings("ignore",
message=".*entire Qiskit Pulse package is being deprecated.*",
category=DeprecationWarning,
)
# backend
from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend
backend = SingleTransmonTestBackend(5.2e9,-.25e9, 1e9, 0.8e9, 1e4, noise=False, seed=199)
.. jupyter-execute::
from qiskit import pulse
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.basis_gate_library \
import FixedFrequencyTransmon
from qiskit_experiments.library.calibration.half_angle_cal import HalfAngleCal
library = FixedFrequencyTransmon(default_values={"duration": 640})
cals = Calibrations.from_backend(backend=backend, libraries=[library])
exp_cal = HalfAngleCal((0,), cals, backend=backend)
inst_map = backend.defaults().instruction_schedule_map
with pulse.build(backend=backend, name="y") as sched_build:
pulse.play(pulse.Drag(duration=160,
sigma=40,
beta=5,
amp=0.05821399464431249,
angle=0.0,), pulse.DriveChannel(0),)
inst_map.add("y", (0,), sched_build)
cal_data = exp_cal.run().block_for_results()
display(cal_data.figure(0))
cal_data.analysis_results(dataframe=True)
"""

def __init__(
self,
Expand Down
Loading

0 comments on commit cc258d7

Please sign in to comment.