-
Notifications
You must be signed in to change notification settings - Fork 131
Drag cal refactor #473
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
Drag cal refactor #473
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c5f7e7b
* Moved calibration.DragCal -> characterization.RoughDrag.
eggerdj 8ac651c
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into drag…
eggerdj a115062
* Default options.
eggerdj 886b73a
* Black.
eggerdj 19cc4ea
* Removed Drag update library test as this is now redundent with Roug…
eggerdj 34ec722
* Removed Drag updater.
eggerdj 1f5a7f7
* Removed unused import.
eggerdj 6fcb63d
* updated NB.
eggerdj ebae4ca
Merge branch 'main' into drag_refactor
eggerdj fc7cf2c
Merge branch 'main' of github.com:Qiskit/qiskit-experiments into drag…
eggerdj d862239
* Aligned tests to the gate naming.
eggerdj 6c95c2e
* Tutorial NB.
eggerdj 639addb
* Config test.
eggerdj 168ab3d
Merge branch 'drag_refactor' of github.com:eggerdj/qiskit-experiments…
eggerdj d69e23e
* Args order and set options.
eggerdj 9e6cd6e
Merge branch 'main' into drag_refactor
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
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
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
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
116 changes: 116 additions & 0 deletions
116
qiskit_experiments/library/calibration/rough_drag_cal.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,116 @@ | ||
| # 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 drag calibration experiment.""" | ||
|
|
||
| from typing import Iterable, List, Optional | ||
|
|
||
| from qiskit import QuantumCircuit | ||
| from qiskit.circuit import Parameter | ||
| from qiskit.providers.backend import Backend | ||
|
|
||
| from qiskit_experiments.framework import ExperimentData, fix_class_docs | ||
| from qiskit_experiments.calibration_management import ( | ||
| BaseCalibrationExperiment, | ||
| BackendCalibrations, | ||
| ) | ||
| from qiskit_experiments.calibration_management.update_library import BaseUpdater | ||
| from qiskit_experiments.library.characterization.drag import RoughDrag | ||
|
|
||
|
|
||
| @fix_class_docs | ||
| class RoughDragCal(BaseCalibrationExperiment, RoughDrag): | ||
| """A calibration version of the Drag experiment. | ||
|
|
||
| # section: see_also | ||
| qiskit_experiments.library.characterization.rough_drag.RoughDrag | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| qubit: int, | ||
| calibrations: BackendCalibrations, | ||
| backend: Optional[Backend] = None, | ||
| schedule_name: str = "x", | ||
| betas: Iterable[float] = None, | ||
| cal_parameter_name: Optional[str] = "β", | ||
| auto_update: bool = True, | ||
| group: str = "default", | ||
| ): | ||
| r"""see class :class:`RoughDrag` for details. | ||
|
|
||
| Args: | ||
| qubit: The qubit for which to run the rough drag calibration. | ||
| calibrations: The calibrations instance with the schedules. | ||
| backend: Optional, the backend to run the experiment on. | ||
| schedule_name: The name of the schedule to calibrate. Defaults to "x". | ||
| betas: A list of drag parameter values to scan. If None is given 51 betas ranging | ||
| from -5 to 5 will be scanned. | ||
| cal_parameter_name: The name of the parameter in the schedule to update. | ||
| Defaults to "β". | ||
| auto_update: Whether or not to automatically update the calibrations. By | ||
| default this variable is set to True. | ||
| group: The group of calibration parameters to use. The default value is "default". | ||
| """ | ||
| schedule = calibrations.get_schedule( | ||
| schedule_name, qubit, assign_params={cal_parameter_name: Parameter("β")}, group=group | ||
| ) | ||
|
|
||
| super().__init__( | ||
| calibrations, | ||
| qubit, | ||
| schedule=schedule, | ||
| betas=betas, | ||
| backend=backend, | ||
| schedule_name=schedule_name, | ||
| cal_parameter_name=cal_parameter_name, | ||
| auto_update=auto_update, | ||
| ) | ||
|
|
||
| def _add_cal_metadata(self, circuits: List[QuantumCircuit]): | ||
| """Add metadata to the circuit to make the experiment data more self contained. | ||
|
|
||
| The following keys are added to each circuit's metadata: | ||
| cal_param_value: The value of the previous calibrated beta. | ||
| cal_param_name: The name of the parameter in the calibrations. | ||
| cal_schedule: The name of the schedule in the calibrations. | ||
| cal_group: The calibration group to which the parameter belongs. | ||
| """ | ||
|
|
||
| prev_beta = self._cals.get_parameter_value( | ||
| self._param_name, self.physical_qubits, self._sched_name, self.experiment_options.group | ||
| ) | ||
|
|
||
| for circuit in circuits: | ||
| circuit.metadata["cal_param_value"] = prev_beta | ||
| circuit.metadata["cal_param_name"] = self._param_name | ||
| circuit.metadata["cal_schedule"] = self._sched_name | ||
| circuit.metadata["cal_group"] = self.experiment_options.group | ||
|
|
||
| def update_calibrations(self, experiment_data: ExperimentData): | ||
| """Update the beta using the value directly reported from the fit. | ||
|
|
||
| See :class:`DragCalAnalysis` for details on the fit. | ||
| """ | ||
|
|
||
| new_beta = BaseUpdater.get_value( | ||
| experiment_data, "beta", self.experiment_options.result_index | ||
| ) | ||
|
|
||
| BaseUpdater.add_parameter_value( | ||
| self._cals, | ||
| experiment_data, | ||
| new_beta, | ||
| self._param_name, | ||
| self._sched_name, | ||
| self.experiment_options.group, | ||
| ) | ||
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
Oops, something went wrong.
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.
Is this
RoughDragXSXCalas per convention of rough amp?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.
No, Drag only ever updates one pulse. To update both X and SX you should run two separate experiments with the corresponding pulses.
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.
Probably we can integrate them in future since rough drag doesn't have enough resolution of beta.