-
Notifications
You must be signed in to change notification settings - Fork 131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
2e995f7
* Added demo of wrappers.
eggerdj f28d7a5
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into cal_…
eggerdj 63b22f7
* Added more flexibility to FineAmplitude.
eggerdj 2bdc95b
* Added calibration base class and amended experiments accordingly.
eggerdj 4005884
* Added tests for Drag and Rabi cals updating.
eggerdj ad5b120
Merge branch 'main' into cal_wrappers
eggerdj 7fdac59
* Rabi test.
eggerdj 7074d78
* Changed name of init arg: calibrations -> cals.
eggerdj f11129b
Merge branch 'main' into cal_wrappers
eggerdj 8d88b01
* Fix some merge issues.
eggerdj 3e24236
* Removed wrappers tutorial.
eggerdj 4164860
* Small fixes to experiments.
eggerdj 16b847a
* Updated the demo NB.
eggerdj 6a4c454
* Added ABC
eggerdj 5c45d54
* Added calibration options.
eggerdj afe05e5
* Override run_analysis(...) instead of run(...)
eggerdj 861a3e3
* Reverted to overriding run_experiment.
eggerdj 1e538be
* Improved docstrings.
eggerdj 4f262d8
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 417346b
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj c12dbe2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 2514aa2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 6671ce9
* Developper docstring.
eggerdj 580f70b
* get_schedules_from_defaults docstring.
eggerdj 53337b7
* Refactored the arguments of get_schedule.
eggerdj 9074e2c
* Added a default implementation of the update_calibrations method.
eggerdj cc5ebc4
* RaiseNotImplementedError on default schedules.
eggerdj 7ffae87
* Protect against missing schedule name in FineAmplitude.
eggerdj 36baa4f
Merge branch 'main' into cal_wrappers
eggerdj 3111b82
* Black and lint.
eggerdj bb8fc79
* Lint black and RoughFrequency mixin.
eggerdj df29ba0
* Black
eggerdj 112d5b7
* RoughEFFrequency
eggerdj bbd9293
* Small change to DragCal anti schedule.
eggerdj fad77aa
Merge branch 'main' into cal_wrappers
eggerdj 6da58d0
Merge branch 'main' into cal_wrappers
eggerdj 9ed1449
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 0ddc1e4
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 073ead5
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 60b27af
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 65d78f0
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj bdd141b
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj d354708
* Changed Drag.
eggerdj cbf74ac
Merge branch 'main' into cal_wrappers
eggerdj 7e2ea6c
* Small changes to align test_drag
eggerdj 94ad1c6
* Fixed drag and its tests.
eggerdj 5c2d9c1
* Removed calibration options.
eggerdj 9a70f1b
* Docstrings.
eggerdj 75d2f11
* Docstring.
eggerdj 906c5ab
* Fixed needed variables in RoughFrequency
eggerdj a5cc975
* Fix to test_update for drag
eggerdj c41428c
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into cal_…
eggerdj 8762448
* Made cals non-optional in RoughFrequency.
eggerdj 84a37a2
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 5438738
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 53dd7e1
* Reset Rabi, Drag, and FineAmp
eggerdj a9d7994
* Reset test_update_library
eggerdj f6d21ff
* Black
eggerdj 75d4fd8
* Added auto_update to the cals.
eggerdj ab45007
* inits and mixin
eggerdj ea21af7
* Moved RoughFrequency.
eggerdj c70179a
* Black, docs, NB
eggerdj 4ea0d09
Merge branch 'main' into cal_wrappers
eggerdj 1703448
* Lint
eggerdj 29a3582
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj 555cf55
Update qiskit_experiments/library/calibration/rough_frequency.py
eggerdj 395a89c
Merge branch 'main' into cal_wrappers
eggerdj 5090893
* Type hints.
eggerdj 6cf1d0b
* Init args.
eggerdj 4c06960
* Docstring on convention.
eggerdj c5894b1
* Lint on tests.
eggerdj 9f19a6e
* MRO warning.
eggerdj fe9b244
Merge branch 'main' into cal_wrappers
eggerdj 8c7dd74
Update qiskit_experiments/calibration_management/base_calibration_exp…
eggerdj ae20f7a
* Added calibrations property
eggerdj e2c3c39
Merge branch 'cal_wrappers' of github.com:eggerdj/qiskit-experiments …
eggerdj 34518e2
* changed __updater__ -> _updater
eggerdj 8232baa
Merge branch 'main' into cal_wrappers
eggerdj 1f71b96
* black
eggerdj 88652ab
* add_analysis_callback
eggerdj aa6c973
* Added block for results in the test.
eggerdj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
366 changes: 366 additions & 0 deletions
366
qiskit_experiments/calibration_management/base_calibration_experiment.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
qiskit_experiments/library/calibration/rough_frequency.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # 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. | ||
|
|
||
| """Calibration version of spectroscopy experiments.""" | ||
|
|
||
| from typing import Iterable | ||
|
|
||
| from qiskit_experiments.library.characterization.qubit_spectroscopy import QubitSpectroscopy | ||
| from qiskit_experiments.library.characterization.ef_spectroscopy import EFSpectroscopy | ||
| from qiskit_experiments.calibration_management.update_library import Frequency | ||
| from qiskit_experiments.calibration_management.backend_calibrations import BackendCalibrations | ||
| from qiskit_experiments.calibration_management.base_calibration_experiment import ( | ||
| BaseCalibrationExperiment, | ||
| ) | ||
|
|
||
|
|
||
| class RoughFrequencyCal(BaseCalibrationExperiment, QubitSpectroscopy): | ||
| """A calibration experiment that runs QubitSpectroscopy.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| qubit: int, | ||
| calibrations: BackendCalibrations, | ||
| frequencies: Iterable[float], | ||
| unit: str = "Hz", | ||
| auto_update: bool = True, | ||
| absolute: bool = True, | ||
| ): | ||
| """See :class:`QubitSpectroscopy` for detailed documentation. | ||
|
|
||
| Args: | ||
| qubit: The qubit on which to run spectroscopy. | ||
| calibrations: If calibrations is given then running the experiment may update the values | ||
| of the frequencies stored in calibrations. | ||
| frequencies: The frequencies to scan in the experiment. | ||
| unit: The unit in which the user specifies the frequencies. Can be one of 'Hz', 'kHz', | ||
| 'MHz', 'GHz'. Internally, all frequencies will be converted to 'Hz'. | ||
| auto_update: If set to True, which is the default, then the experiment will | ||
| automatically update the frequency in the calibrations. | ||
| absolute: Boolean to specify if the frequencies are absolute or relative to the | ||
| qubit frequency in the backend. | ||
|
|
||
| Raises: | ||
| QiskitError: if there are less than three frequency shifts or if the unit is not known. | ||
|
|
||
| """ | ||
| super().__init__( | ||
| calibrations, | ||
| qubit, | ||
| frequencies, | ||
| unit, | ||
| absolute, | ||
| updater=Frequency, | ||
| auto_update=auto_update, | ||
| ) | ||
|
|
||
|
|
||
| class RoughEFFrequencyCal(BaseCalibrationExperiment, EFSpectroscopy): | ||
| """A calibration experiment that runs QubitSpectroscopy.""" | ||
|
|
||
| __updater__ = Frequency | ||
|
|
||
| # pylint: disable=super-init-not-called | ||
| def __init__( | ||
| self, | ||
| qubit: int, | ||
| calibrations: BackendCalibrations, | ||
| frequencies: Iterable[float], | ||
| unit: str = "Hz", | ||
| auto_update: bool = True, | ||
| absolute: bool = True, | ||
| ): | ||
| """See :class:`QubitSpectroscopy` for detailed documentation. | ||
|
|
||
| Args: | ||
| qubit: The qubit on which to run spectroscopy. | ||
| calibrations: If calibrations is given then running the experiment may update the values | ||
| of the frequencies stored in calibrations. | ||
| frequencies: The frequencies to scan in the experiment. | ||
| unit: The unit in which the user specifies the frequencies. Can be one of 'Hz', 'kHz', | ||
| 'MHz', 'GHz'. Internally, all frequencies will be converted to 'Hz'. | ||
| auto_update: If set to True, which is the default, then the experiment will | ||
| automatically update the frequency in the calibrations. | ||
| absolute: Boolean to specify if the frequencies are absolute or relative to the | ||
| qubit frequency in the backend. | ||
|
|
||
| Raises: | ||
| QiskitError: if there are less than three frequency shifts or if the unit is not known. | ||
|
|
||
| """ | ||
| super().__init__( | ||
| calibrations, | ||
| qubit, | ||
| frequencies, | ||
| unit, | ||
| absolute, | ||
| cal_parameter_name="f12", | ||
| updater=Frequency, | ||
| auto_update=auto_update, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # 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. | ||
|
|
||
| """Rough frequency calibration tests.""" | ||
|
|
||
| from test.test_qubit_spectroscopy import SpectroscopyBackend | ||
|
|
||
| import numpy as np | ||
|
|
||
| from qiskit.test import QiskitTestCase | ||
| from qiskit.test.mock import FakeArmonk | ||
|
|
||
| from qiskit_experiments.library import RoughFrequencyCal | ||
| from qiskit_experiments.calibration_management import BackendCalibrations | ||
| from qiskit_experiments.calibration_management.basis_gate_library import FixedFrequencyTransmon | ||
|
|
||
|
|
||
| class TestRoughFrequency(QiskitTestCase): | ||
| """Tests for the rough frequency calibration experiment.""" | ||
|
|
||
| def test_init(self): | ||
| """Test that initialization.""" | ||
|
|
||
| qubit = 1 | ||
| cals = BackendCalibrations(FakeArmonk()) | ||
| frequencies = [1, 2, 3] | ||
| unit = "kHz" | ||
| auto_update = False | ||
| absolute = False | ||
|
|
||
| freq = RoughFrequencyCal(qubit, cals, frequencies, unit, auto_update, absolute) | ||
|
|
||
| self.assertEqual(freq.physical_qubits, (qubit,)) | ||
| self.assertEqual(freq._frequencies, [1000, 2000, 3000]) | ||
| self.assertEqual(freq._absolute, False) | ||
| self.assertEqual(freq.auto_update, False) | ||
|
|
||
| def test_update_calibrations(self): | ||
| """Test that we can properly update an instance of BackendCalibrations.""" | ||
|
|
||
| freq01 = FakeArmonk().defaults().qubit_freq_est[0] | ||
|
|
||
| backend = SpectroscopyBackend(freq_offset=5e6, line_width=2e6) | ||
| backend.defaults().qubit_freq_est = [freq01, freq01] | ||
|
|
||
| library = FixedFrequencyTransmon(basis_gates=["x", "sx"]) | ||
| cals = BackendCalibrations(FakeArmonk(), library=library) | ||
|
|
||
| prev_freq = cals.get_parameter_value(cals.__qubit_freq_parameter__, (0,)) | ||
| self.assertEqual(prev_freq, freq01) | ||
|
|
||
| frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21) | ||
|
|
||
| RoughFrequencyCal(0, cals, frequencies).run(backend).block_for_results() | ||
|
|
||
| # Check the updated frequency which should be shifted by 5MHz. | ||
| post_freq = cals.get_parameter_value(cals.__qubit_freq_parameter__, (0,)) | ||
| self.assertTrue(abs(post_freq - freq01 - 5e6) < 1e6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # 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. | ||
|
|
||
| """Tests for the base class for calibration-type experiments.""" | ||
|
|
||
| from qiskit.test import QiskitTestCase | ||
|
|
||
| from qiskit_experiments.library import QubitSpectroscopy | ||
| from qiskit_experiments.calibration_management.calibrations import Calibrations | ||
| from qiskit_experiments.calibration_management.base_calibration_experiment import ( | ||
| BaseCalibrationExperiment, | ||
| ) | ||
|
|
||
|
|
||
| class TestBaseCalibrationClass(QiskitTestCase): | ||
| """Tests for base calibration experiment classes.""" | ||
|
|
||
| def test_class_order(self): | ||
| """Test warnings when the BaseCalibrationExperiment is not the first parent.""" | ||
|
|
||
| class CorrectOrder(BaseCalibrationExperiment, QubitSpectroscopy): | ||
| """A class with the correct order should not produce warnings..""" | ||
|
|
||
| def __init__(self): | ||
| """A dummy class for parent order testing.""" | ||
| super().__init__(Calibrations(), 0, [0, 1, 2]) | ||
|
|
||
| CorrectOrder() | ||
|
|
||
| with self.assertWarns(Warning): | ||
|
|
||
| # pylint: disable=unused-variable | ||
| class WrongOrder(QubitSpectroscopy, BaseCalibrationExperiment): | ||
| """Merely defining this class is enough to raise the warning.""" | ||
|
|
||
| def __init__(self): | ||
| """A dummy class for parent order testing.""" | ||
| super().__init__(Calibrations(), 0, [0, 1, 2]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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