Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2e995f7
* Added demo of wrappers.
eggerdj Jul 28, 2021
f28d7a5
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into cal_…
eggerdj Aug 13, 2021
63b22f7
* Added more flexibility to FineAmplitude.
eggerdj Aug 13, 2021
2bdc95b
* Added calibration base class and amended experiments accordingly.
eggerdj Aug 15, 2021
4005884
* Added tests for Drag and Rabi cals updating.
eggerdj Aug 16, 2021
ad5b120
Merge branch 'main' into cal_wrappers
eggerdj Aug 16, 2021
7fdac59
* Rabi test.
eggerdj Aug 16, 2021
7074d78
* Changed name of init arg: calibrations -> cals.
eggerdj Aug 17, 2021
f11129b
Merge branch 'main' into cal_wrappers
eggerdj Aug 17, 2021
8d88b01
* Fix some merge issues.
eggerdj Aug 17, 2021
3e24236
* Removed wrappers tutorial.
eggerdj Aug 17, 2021
4164860
* Small fixes to experiments.
eggerdj Aug 18, 2021
16b847a
* Updated the demo NB.
eggerdj Aug 18, 2021
6a4c454
* Added ABC
eggerdj Aug 18, 2021
5c45d54
* Added calibration options.
eggerdj Aug 18, 2021
afe05e5
* Override run_analysis(...) instead of run(...)
eggerdj Aug 20, 2021
861a3e3
* Reverted to overriding run_experiment.
eggerdj Aug 25, 2021
1e538be
* Improved docstrings.
eggerdj Aug 26, 2021
4f262d8
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Aug 31, 2021
417346b
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Aug 31, 2021
c12dbe2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Aug 31, 2021
2514aa2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Aug 31, 2021
6671ce9
* Developper docstring.
eggerdj Aug 31, 2021
580f70b
* get_schedules_from_defaults docstring.
eggerdj Aug 31, 2021
53337b7
* Refactored the arguments of get_schedule.
eggerdj Sep 1, 2021
9074e2c
* Added a default implementation of the update_calibrations method.
eggerdj Sep 1, 2021
cc5ebc4
* RaiseNotImplementedError on default schedules.
eggerdj Sep 1, 2021
7ffae87
* Protect against missing schedule name in FineAmplitude.
eggerdj Sep 1, 2021
36baa4f
Merge branch 'main' into cal_wrappers
eggerdj Sep 1, 2021
3111b82
* Black and lint.
eggerdj Sep 1, 2021
bb8fc79
* Lint black and RoughFrequency mixin.
eggerdj Sep 1, 2021
df29ba0
* Black
eggerdj Sep 1, 2021
112d5b7
* RoughEFFrequency
eggerdj Sep 1, 2021
bbd9293
* Small change to DragCal anti schedule.
eggerdj Sep 3, 2021
fad77aa
Merge branch 'main' into cal_wrappers
eggerdj Sep 21, 2021
6da58d0
Merge branch 'main' into cal_wrappers
eggerdj Sep 21, 2021
9ed1449
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
0ddc1e4
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
073ead5
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
60b27af
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
65d78f0
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
bdd141b
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 28, 2021
d354708
* Changed Drag.
eggerdj Sep 28, 2021
cbf74ac
Merge branch 'main' into cal_wrappers
eggerdj Sep 28, 2021
7e2ea6c
* Small changes to align test_drag
eggerdj Sep 28, 2021
94ad1c6
* Fixed drag and its tests.
eggerdj Sep 28, 2021
5c2d9c1
* Removed calibration options.
eggerdj Sep 28, 2021
9a70f1b
* Docstrings.
eggerdj Sep 28, 2021
75d2f11
* Docstring.
eggerdj Sep 28, 2021
906c5ab
* Fixed needed variables in RoughFrequency
eggerdj Sep 28, 2021
a5cc975
* Fix to test_update for drag
eggerdj Sep 28, 2021
c41428c
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into cal_…
eggerdj Sep 30, 2021
8762448
* Made cals non-optional in RoughFrequency.
eggerdj Sep 30, 2021
84a37a2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 30, 2021
5438738
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Sep 30, 2021
53dd7e1
* Reset Rabi, Drag, and FineAmp
eggerdj Sep 30, 2021
a9d7994
* Reset test_update_library
eggerdj Sep 30, 2021
f6d21ff
* Black
eggerdj Sep 30, 2021
75d4fd8
* Added auto_update to the cals.
eggerdj Sep 30, 2021
ab45007
* inits and mixin
eggerdj Oct 1, 2021
ea21af7
* Moved RoughFrequency.
eggerdj Oct 1, 2021
c70179a
* Black, docs, NB
eggerdj Oct 1, 2021
4ea0d09
Merge branch 'main' into cal_wrappers
eggerdj Oct 1, 2021
1703448
* Lint
eggerdj Oct 1, 2021
29a3582
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Oct 4, 2021
555cf55
Update qiskit_experiments/library/calibration/rough_frequency.py
eggerdj Oct 4, 2021
395a89c
Merge branch 'main' into cal_wrappers
eggerdj Oct 4, 2021
5090893
* Type hints.
eggerdj Oct 4, 2021
6cf1d0b
* Init args.
eggerdj Oct 4, 2021
4c06960
* Docstring on convention.
eggerdj Oct 4, 2021
c5894b1
* Lint on tests.
eggerdj Oct 4, 2021
9f19a6e
* MRO warning.
eggerdj Oct 5, 2021
fe9b244
Merge branch 'main' into cal_wrappers
eggerdj Oct 5, 2021
8c7dd74
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj Oct 14, 2021
ae20f7a
* Added calibrations property
eggerdj Oct 14, 2021
e2c3c39
Merge branch 'cal_wrappers' of github.com:eggerdj/qiskit-experiments …
eggerdj Oct 14, 2021
34518e2
* changed __updater__ -> _updater
eggerdj Oct 14, 2021
8232baa
Merge branch 'main' into cal_wrappers
eggerdj Oct 14, 2021
1f71b96
* black
eggerdj Oct 14, 2021
88652ab
* add_analysis_callback
eggerdj Oct 14, 2021
aa6c973
* Added block for results in the test.
eggerdj Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
962 changes: 459 additions & 503 deletions docs/tutorials/calibrating_armonk.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Base class for calibration-type experiments."""

from abc import abstractmethod
from typing import Optional

from qiskit.providers.options import Options
from qiskit.providers.backend import Backend

from qiskit_experiments.framework.base_experiment import BaseExperiment
from qiskit_experiments.framework.experiment_data import ExperimentData


class BaseCalibrationExperiment(BaseExperiment):
Comment thread
eggerdj marked this conversation as resolved.
Outdated
"""An abstract base class for calibration experiments.

This abstract base class specifies an experiment and how to update an
optional instance of :class:`Calibrations` specified in the experiment options
under calibrations. Furthermore, the experiment options also specifies
an auto_update variable which, by default, is set to True. If this variable,
is True then the run method of the experiment will call :meth:`block_for_results`
and update the calibrations instance.
"""

# The updater class that updates the Calibrations instance
Comment thread
eggerdj marked this conversation as resolved.
Outdated
__updater__ = None
Comment thread
eggerdj marked this conversation as resolved.
Outdated
Comment thread
eggerdj marked this conversation as resolved.
Outdated

@abstractmethod
def update_calibrations(self, experiment_data: ExperimentData):
Comment thread
eggerdj marked this conversation as resolved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this method should be part of the Updater itself and be called like updater.update_calibrations(exp_data). Since experiments can define custom updaters they could overload the updater if needed. I'm not sure if there would be issues with this though since the examples in this PR are pretty straightforward so nothing overloads this method.

If this was changed we should probably add updater as a property to return the current updater too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to reconsider the way the updaters work in a subsequent PR focused more on the updaters.

"""Update parameter values in the :class:`Calibrations` instance.

Subclasses must implement this method which will call the :meth:`update`
method of the updater.
"""

@classmethod
def _default_experiment_options(cls) -> Options:
"""Default options for experiment

Experiment Options:
calibrations (Calibrations): An optional instance of :class:`Calibrations` if this
Comment thread
eggerdj marked this conversation as resolved.
Outdated
instance is specified then the experiment will try and update the calibrations.
auto_update (bool): A boolean which defaults to True. If this variable is set to
True then running the calibration experiment will block for the results and
update the calibrations if the calibrations is not None.
"""
options = super()._default_experiment_options()
options.calibrations = None
Comment thread
eggerdj marked this conversation as resolved.
Outdated
Comment thread
eggerdj marked this conversation as resolved.
Outdated
options.auto_update = True

return options

def run(
Comment thread
eggerdj marked this conversation as resolved.
self,
backend: Backend,
analysis: bool = True,
experiment_data: Optional[ExperimentData] = None,
**run_options,
) -> ExperimentData:
"""Run an experiment, perform analysis, and update any calibrations.

Args:
backend: The backend to run the experiment on.
analysis: If True run analysis on the experiment data.
experiment_data: Optional, add results to existing experiment data.
If None a new ExperimentData object will be returned.
run_options: backend runtime options used for circuit execution.

Returns:
The experiment data object.
"""
experiment_data = super().run(backend, analysis, experiment_data, **run_options)

if self.experiment_options.auto_update:
if self.experiment_options.calibrations is not None:
experiment_data = experiment_data.block_for_results()
Comment thread
eggerdj marked this conversation as resolved.
Outdated
self.update_calibrations(experiment_data)

return experiment_data
8 changes: 7 additions & 1 deletion qiskit_experiments/calibration_management/update_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def update(
calibrations: BackendCalibrations,
exp_data: ExperimentData,
result_index: Optional[int] = None,
parameter: str = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that updater classes are more important it would be good to improve the API documentation of the BaseUpdater class (either in that class doc string, or the cal management module docstring) to explain to developers how to subclass a calibration updater class for their experiments. This can be done as followup PR

group: str = "default",
**options,
):
Expand All @@ -163,14 +164,19 @@ def update(
calibrations: The calibrations to update.
exp_data: The experiment data from which to update.
result_index: The result index to use. By default search entry by name.
parameter: The name of the parameter to update. If None is given this will default
to :code:`calibrations.__qubit_freq_parameter__`.
group: The calibrations group to update. Defaults to "default."
options: Trailing options.

"""
if parameter is None:
parameter = calibrations.__qubit_freq_parameter__

super().update(
calibrations=calibrations,
exp_data=exp_data,
parameter=calibrations.__qubit_freq_parameter__,
parameter=parameter,
schedule=None,
result_index=result_index,
group=group,
Expand Down
61 changes: 57 additions & 4 deletions qiskit_experiments/library/calibration/drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
from qiskit.providers import Backend
import qiskit.pulse as pulse

from qiskit_experiments.framework import BaseExperiment, Options
from qiskit_experiments.framework import Options
from qiskit_experiments.framework.experiment_data import ExperimentData
from qiskit_experiments.exceptions import CalibrationError
from qiskit_experiments.library.calibration.analysis.drag_analysis import DragCalAnalysis
from qiskit_experiments.calibration_management.update_library import Drag
from qiskit_experiments.calibration_management.calibrations import Calibrations
from qiskit_experiments.calibration_management.base_calibration_experiment import (
BaseCalibrationExperiment,
)


class DragCal(BaseExperiment):
class DragCal(BaseCalibrationExperiment):
r"""An experiment that scans the DRAG parameter to find the optimal value.

# section: overview
Expand Down Expand Up @@ -75,6 +81,8 @@ class DragCal(BaseExperiment):

__analysis_class__ = DragCalAnalysis

__updater__ = Drag

@classmethod
def _default_run_options(cls) -> Options:
"""Default option values for the experiment :meth:`run` method."""
Expand Down Expand Up @@ -107,6 +115,8 @@ def _default_experiment_options(cls) -> Options:
each series. Note that this list must always have a length of three as
otherwise the analysis class will not run.
betas (Iterable): the values of the DRAG parameter to scan.
cal_parameter_name (str): The name of the DRAG parameter in the schedule stored in
the calibrations instance. The default value is "β".
"""
options = super()._default_experiment_options()

Expand All @@ -117,6 +127,7 @@ def _default_experiment_options(cls) -> Options:
options.sigma = 40
options.reps = [1, 3, 5]
options.betas = np.linspace(-5, 5, 51)
options.cal_parameter_name = "β"
Comment thread
eggerdj marked this conversation as resolved.
Outdated

return options

Expand Down Expand Up @@ -149,13 +160,41 @@ def set_experiment_options(self, reps: Optional[List] = None, **fields):

super().set_experiment_options(reps=reps, **fields)

def __init__(self, qubit: int):
def __init__(
self,
qubit: int,
cals: Optional[Calibrations] = None,
schedule_name: Optional[str] = "x",
cal_parameter_name: Optional[str] = "β",
betas: Optional[List] = None,
reps: Optional[List] = None,
):
"""
Args:
qubit: The qubit for which to run the Drag calibration.
cals: If calibrations is given then running the experiment may update the
values of the pulse parameters stored in calibrations.
schedule_name: The name of the schedule to extract from the calibrations. This value
defaults to "x".
cal_parameter_name: The name of the parameter in calibrations to update. This name will
be stored in the experiment options and defaults to "β".
betas: The values of the DRAG parameter to scan. Specify this argument to override the
default values of the experiment.
"""

super().__init__([qubit])
self.experiment_options.calibrations = cals
self.experiment_options.cal_parameter_name = cal_parameter_name

if cals is not None and schedule_name is not None:
self.experiment_options.rp = cals.get_schedule(
schedule_name, qubit, assign_params={cal_parameter_name: Parameter("β")}
)

if betas is not None:
self.experiment_options.betas = betas

if reps is not None:
self.experiment_options.reps = reps

def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
"""Create the circuits for the Drag calibration.
Expand Down Expand Up @@ -258,3 +297,17 @@ def circuits(self, backend: Optional[Backend] = None) -> List[QuantumCircuit]:
circuits.append(assigned_circuit)

return circuits

def update_calibrations(self, experiment_data: ExperimentData):
"""Update the calibrations given the experiment data.

Args:
experiment_data: The experiment data to use for the update.
"""
calibrations = self.experiment_options.calibrations
name = self.experiment_options.rp.name
parameter_name = self.experiment_options.cal_parameter_name

self.__updater__.update(
calibrations, experiment_data, parameter=parameter_name, schedule=name
)
Loading