-
Notifications
You must be signed in to change notification settings - Fork 131
Setup single-qubit calibrations #114
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
31 commits
Select commit
Hold shift + click to select a range
9bb60ae
* Implemented method to setup single-qubit calibrations.
eggerdj 6b83656
Merge branch 'main' into calibrations_setup
eggerdj 9b16df9
Merge branch 'main' into calibrations_setup
eggerdj f973582
* Refactored cals setup to library style.
eggerdj 262f2a4
* Fix sigma in test.
eggerdj 319de19
Merge branch 'main' into calibrations_setup
eggerdj 894794a
Update qiskit_experiments/calibration_management/basis_gate_library.py
eggerdj 97524de
Merge branch 'main' into calibrations_setup
eggerdj d10d155
* Made library options kwargs.
eggerdj 59bde3e
* Added error raising.
eggerdj b33f73b
* Added basis gates property.
eggerdj 58acc43
* Renamed transmon library.
eggerdj c5962fe
* Docs.
eggerdj 4ae1763
* Added better Drag optionality.
eggerdj 654d017
* Added y and sy gates to library.
eggerdj 1dadebe
* Add check to make sure we do not add default values for gates that …
eggerdj 577394b
Update qiskit_experiments/calibration_management/basis_gate_library.py
eggerdj 84ee237
Merge branch 'main' into calibrations_setup
eggerdj 529d3b1
* Docs.
eggerdj 977122c
Merge branch 'calibrations_setup' of github.com:eggerdj/qiskit-experi…
eggerdj 824bb44
* Update the way the library is passed to BackendCalibrations.
eggerdj 332f8a4
* Lint.
eggerdj fd4b286
Merge branch 'main' into calibrations_setup
eggerdj 8282ee0
* Added option to link parameters.
eggerdj 86c3e9a
Merge branch 'calibrations_setup' of github.com:eggerdj/qiskit-experi…
eggerdj d3c0b69
* Partial generation of basis gates.
eggerdj 4ca85e4
* Added test.
eggerdj 58fad06
Merge branch 'main' into calibrations_setup
eggerdj a457f1a
* Fixed test issue and added in operator.
eggerdj 3ac1e08
Merge branch 'calibrations_setup' of github.com:eggerdj/qiskit-experi…
eggerdj 9e478b2
Merge branch 'main' into calibrations_setup
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
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
207 changes: 207 additions & 0 deletions
207
qiskit_experiments/calibration_management/basis_gate_library.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,207 @@ | ||
| # 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. | ||
|
|
||
| """ | ||
| A collections of libraries to setup Calibrations. | ||
|
|
||
| Note that the set of available libraries will be extended in future releases. | ||
| """ | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import Dict, List, Optional, Tuple | ||
|
|
||
| from qiskit.circuit import Parameter | ||
| import qiskit.pulse as pulse | ||
| from qiskit.pulse import ScheduleBlock | ||
|
|
||
| from qiskit_experiments.calibration_management.calibration_key_types import ParameterValueType | ||
| from qiskit_experiments.exceptions import CalibrationError | ||
|
|
||
|
|
||
| class BasisGateLibrary(ABC): | ||
| """A base class for libraries of basis gates to make it easier to setup Calibrations.""" | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Location where default parameter values are stored. These may be updated at construction. | ||
| __default_values__ = dict() | ||
|
|
||
| # The basis gates that this library generates. | ||
| __supported_gates__ = None | ||
|
|
||
| def __init__( | ||
| self, basis_gates: Optional[List[str]] = None, default_values: Optional[Dict] = None | ||
| ): | ||
| """Setup the library. | ||
|
|
||
| Args: | ||
| basis_gates: The basis gates to generate. | ||
| default_values: A dictionary to override library default parameter values. | ||
|
|
||
| Raises: | ||
| CalibrationError: If on of the given basis gates is not supported by the library. | ||
| """ | ||
| self._schedules = dict() | ||
|
|
||
| # Update the default values. | ||
| self._default_values = dict(self.__default_values__) | ||
| if default_values is not None: | ||
| self._default_values.update(default_values) | ||
|
|
||
| if basis_gates is not None: | ||
| for gate in basis_gates: | ||
| if gate not in self.__supported_gates__: | ||
| raise CalibrationError( | ||
| f"Gate {gate} is not supported by {self.__class__.__name__}. " | ||
| f"Supported gates are: {self.__supported_gates__}." | ||
| ) | ||
|
|
||
| self._basis_gates = basis_gates or self.__supported_gates__ | ||
|
|
||
| def __getitem__(self, name: str) -> ScheduleBlock: | ||
| """Return the schedule.""" | ||
| if name not in self._schedules: | ||
| raise CalibrationError(f"Gate {name} is not contained in {self.__class__.__name__}.") | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return self._schedules[name] | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def __contains__(self, name: str) -> bool: | ||
| """Check if the basis gate is in the library.""" | ||
| return name in self._schedules | ||
|
|
||
| @property | ||
| def basis_gates(self) -> List[str]: | ||
| """Return the basis gates supported by the library.""" | ||
| return list(name for name in self._schedules) | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @abstractmethod | ||
| def default_values(self) -> List[Tuple[ParameterValueType, Parameter, Tuple, ScheduleBlock]]: | ||
| """Return the default values for the parameters. | ||
|
|
||
| Returns | ||
| A list of tuples is returned. These tuples are structured so that instances of | ||
| :class:`Calibrations` can call :meth:`add_parameter_value` on the tuples. | ||
| """ | ||
|
|
||
|
|
||
| class FixedFrequencyTransmon(BasisGateLibrary): | ||
| """A library of gates for fixed-frequency superconducting qubit architectures. | ||
|
|
||
| Note that for now this library supports single-qubit gates and will be extended | ||
| in the future. | ||
| """ | ||
|
|
||
| __default_values__ = {"duration": 160, "amp": 0.5, "β": 0.0} | ||
|
|
||
| __supported_gates__ = ["x", "y", "sx", "sy"] | ||
|
|
||
| def __init__( | ||
| self, | ||
| basis_gates: Optional[List[str]] = None, | ||
| default_values: Optional[Dict] = None, | ||
| use_drag: bool = True, | ||
| link_parameters: bool = True, | ||
| ): | ||
| """Setup the schedules. | ||
|
|
||
| Args: | ||
| basis_gates: The basis gates to generate. | ||
| default_values: Default values for the parameters this dictionary can contain | ||
| the following keys: "duration", "amp", "β", and "σ". If "σ" is not provided | ||
| this library will take one fourth of the pulse duration as default value. | ||
| use_drag: If set to False then Gaussian pulses will be used instead of DRAG | ||
| pulses. | ||
| link_parameters: if set to True then the amplitude and DRAG parameters of the | ||
| X and Y gates will be linked as well as those of the SX and SY gates. | ||
| """ | ||
| super().__init__(basis_gates, default_values) | ||
| self._link_parameters = link_parameters | ||
|
|
||
| dur = Parameter("duration") | ||
| sigma = Parameter("σ") | ||
|
|
||
| # Generate the pulse parameters | ||
| def _beta(use_drag): | ||
| return Parameter("β") if use_drag else None | ||
|
|
||
| x_amp, x_beta = Parameter("amp"), _beta(use_drag) | ||
|
|
||
| if self._link_parameters: | ||
| y_amp, y_beta = 1.0j * x_amp, x_beta | ||
| else: | ||
| y_amp, y_beta = Parameter("amp"), _beta(use_drag) | ||
|
|
||
| sx_amp, sx_beta = Parameter("amp"), _beta(use_drag) | ||
|
|
||
| if self._link_parameters: | ||
| sy_amp, sy_beta = 1.0j * sx_amp, sx_beta | ||
| else: | ||
| sy_amp, sy_beta = Parameter("amp"), _beta(use_drag) | ||
|
|
||
| # Create the schedules for the gates | ||
| sched_x = self._single_qubit_schedule("x", dur, x_amp, sigma, x_beta) | ||
| sched_y = self._single_qubit_schedule("y", dur, y_amp, sigma, y_beta) | ||
| sched_sx = self._single_qubit_schedule("sx", dur, sx_amp, sigma, sx_beta) | ||
| sched_sy = self._single_qubit_schedule("sy", dur, sy_amp, sigma, sy_beta) | ||
|
|
||
| for sched in [sched_x, sched_y, sched_sx, sched_sy]: | ||
| if sched.name in self._basis_gates: | ||
| self._schedules[sched.name] = sched | ||
|
|
||
| @staticmethod | ||
| def _single_qubit_schedule( | ||
| name: str, | ||
| dur: Parameter, | ||
| amp: Parameter, | ||
| sigma: Parameter, | ||
| beta: Optional[Parameter] = None, | ||
| ) -> ScheduleBlock: | ||
| """Build a single qubit pulse.""" | ||
|
|
||
| chan = pulse.DriveChannel(Parameter("ch0")) | ||
|
|
||
| if beta is not None: | ||
eggerdj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with pulse.build(name=name) as sched: | ||
| pulse.play(pulse.Drag(duration=dur, amp=amp, sigma=sigma, beta=beta), chan) | ||
| else: | ||
| with pulse.build(name=name) as sched: | ||
| pulse.play(pulse.Gaussian(duration=dur, amp=amp, sigma=sigma), chan) | ||
|
|
||
| return sched | ||
|
|
||
| def default_values(self) -> List[Tuple[ParameterValueType, Parameter, Tuple, ScheduleBlock]]: | ||
| """Return the default values for the parameters. | ||
|
|
||
| Returns | ||
| A list of tuples is returned. These tuples are structured so that instances of | ||
| :class:`Calibrations` can call :meth:`add_parameter_value` on the tuples. | ||
| """ | ||
| defaults = [] | ||
| for name in self.basis_gates: | ||
| schedule = self._schedules[name] | ||
| for param in schedule.parameters: | ||
| if "ch" not in param.name: | ||
| if "y" in name and self._link_parameters: | ||
| continue | ||
|
|
||
| if param.name == "σ" and "σ" not in self._default_values: | ||
| value = self._default_values["duration"] / 4 | ||
| else: | ||
| value = self._default_values[param.name] | ||
|
|
||
| if name in {"sx", "sy"} and param.name == "amp": | ||
| value /= 2.0 | ||
|
|
||
| if "y" in name and param.name == "amp": | ||
| value *= 1.0j | ||
|
|
||
| defaults.append((value, param.name, tuple(), name)) | ||
|
|
||
| return defaults | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.