-
Notifications
You must be signed in to change notification settings - Fork 136
Improve calibration experiments #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
2e995f7
f28d7a5
63b22f7
2bdc95b
4005884
ad5b120
7fdac59
7074d78
f11129b
8d88b01
3e24236
4164860
16b847a
6a4c454
5c45d54
afe05e5
861a3e3
1e538be
4f262d8
417346b
c12dbe2
2514aa2
6671ce9
580f70b
53337b7
9074e2c
cc5ebc4
7ffae87
36baa4f
3111b82
bb8fc79
df29ba0
112d5b7
bbd9293
fad77aa
6da58d0
9ed1449
0ddc1e4
073ead5
60b27af
65d78f0
bdd141b
d354708
cbf74ac
7e2ea6c
94ad1c6
5c2d9c1
9a70f1b
75d2f11
906c5ab
a5cc975
c41428c
8762448
84a37a2
5438738
53dd7e1
a9d7994
f6d21ff
75d4fd8
ab45007
ea21af7
c70179a
4ea0d09
1703448
29a3582
555cf55
395a89c
5090893
6cf1d0b
4c06960
c5894b1
9f19a6e
fe9b244
8c7dd74
ae20f7a
e2c3c39
34518e2
8232baa
1f71b96
88652ab
aa6c973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
| """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 | ||
|
eggerdj marked this conversation as resolved.
Outdated
|
||
| __updater__ = None | ||
|
eggerdj marked this conversation as resolved.
Outdated
eggerdj marked this conversation as resolved.
Outdated
|
||
|
|
||
| @abstractmethod | ||
| def update_calibrations(self, experiment_data: ExperimentData): | ||
|
eggerdj marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if this method should be part of the If this was changed we should probably add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 | ||
|
eggerdj marked this conversation as resolved.
Outdated
eggerdj marked this conversation as resolved.
Outdated
|
||
| options.auto_update = True | ||
|
|
||
| return options | ||
|
|
||
| def run( | ||
|
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() | ||
|
eggerdj marked this conversation as resolved.
Outdated
|
||
| self.update_calibrations(experiment_data) | ||
|
|
||
| return experiment_data | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,7 @@ def update( | |
| calibrations: BackendCalibrations, | ||
| exp_data: ExperimentData, | ||
| result_index: Optional[int] = None, | ||
| parameter: str = None, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| ): | ||
|
|
@@ -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, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.