-
Notifications
You must be signed in to change notification settings - Fork 127
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
Base calibrations #1200
Open
eggerdj
wants to merge
31
commits into
qiskit-community:main
Choose a base branch
from
eggerdj:base_calibrations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Base calibrations #1200
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e2992f0
* Added the restless mix-in to the init for documentation.
eggerdj 1716aee
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj f406c30
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj cba70ea
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj c944772
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 2fa0251
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj f94be94
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 9fdb84f
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 187bb33
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 5593342
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj c6106db
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 4b39095
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 93f1180
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj ca0f59e
Merge branch 'Qiskit:main' into main
eggerdj 5afc28f
Merge branch 'main' of github.com:eggerdj/qiskit-experiments
eggerdj 7716463
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj b2e9db2
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 7d44612
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 9000df0
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj 9262f96
Merge branch 'main' of github.com:Qiskit/qiskit-experiments
eggerdj d385010
Merge branch 'Qiskit:main' into main
eggerdj f450b6f
* Added BaseCalibrations and made Calibrations inherite form it.
eggerdj c1aa9a4
Merge branch 'main' of github.com:Qiskit-Extensions/qiskit-experiment…
eggerdj b3e666f
* Align test import
eggerdj b363c82
* Add new line at EOF
eggerdj 908fe6c
* Fix lint
eggerdj 8a72fba
Update releasenotes/notes/base_calibrations-220741e03e5c7279.yaml
eggerdj 4fb24bb
* Docs.
eggerdj 72dec29
Merge branch 'main' of github.com:Qiskit-Extensions/qiskit-experiment…
eggerdj 6f21049
* Removed reserved vars and simplified base class methods.
eggerdj d8382d6
* Lint
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 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
114 changes: 114 additions & 0 deletions
114
qiskit_experiments/calibration_management/base_calibrations.py
This file contains 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,114 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2023. | ||
# | ||
# 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 calibrations class.""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Dict, Tuple, Union | ||
|
||
from qiskit.circuit import Parameter | ||
from qiskit.pulse import ScheduleBlock | ||
|
||
from qiskit_experiments.calibration_management.parameter_value import ParameterValue | ||
from qiskit_experiments.calibration_management.calibration_key_types import ( | ||
ParameterKey, | ||
ParameterValueType, | ||
) | ||
|
||
|
||
class BaseCalibrations(ABC): | ||
"""An abstract base calibration class that defines the methods needed by cal. experiments. | ||
|
||
A calibration experiment uses an instance of `BaseCalibrations` that defines where | ||
to get parameter values from and where to save them. This class also defines a method from | ||
which to retrieve pulse-schedules. | ||
""" | ||
|
||
@abstractmethod | ||
def add_parameter_value( | ||
self, | ||
value: Union[int, float, complex, ParameterValue], | ||
param: Union[Parameter, str], | ||
qubits: Union[int, Tuple[int, ...]] = None, | ||
schedule: Union[ScheduleBlock, str] = None, | ||
): | ||
"""Add a parameter value to the stored parameters. | ||
|
||
This parameter value may be applied to several channels, for instance, all | ||
DRAG pulses may have the same standard deviation. | ||
|
||
Args: | ||
value: The value of the parameter to add. If an int, float, or complex is given | ||
then the timestamp of the parameter value will automatically be generated | ||
and set to the current local time of the user. | ||
param: The parameter or its name for which to add the measured value. | ||
qubits: The qubits to which this parameter applies. | ||
schedule: The schedule or its name for which to add the measured parameter value. | ||
""" | ||
|
||
@abstractmethod | ||
def get_parameter_value( | ||
self, | ||
param: Union[Parameter, str], | ||
qubits: Union[int, Tuple[int, ...]], | ||
schedule: Union[ScheduleBlock, str, None] = None, | ||
) -> Union[int, float, complex]: | ||
"""Retrieves the value of a parameter. | ||
|
||
Parameters may be linked. :meth:`get_parameter_value` does the following steps: | ||
|
||
Args: | ||
param: The parameter or the name of the parameter for which to get the parameter value. | ||
qubits: The qubits for which to get the value of the parameter. | ||
schedule: The schedule or its name for which to get the parameter value. | ||
|
||
Returns: | ||
value: The value of the parameter. | ||
""" | ||
|
||
@abstractmethod | ||
def get_schedule( | ||
self, | ||
name: str, | ||
qubits: Union[int, Tuple[int, ...]], | ||
assign_params: Dict[Union[str, ParameterKey], ParameterValueType] = None, | ||
) -> ScheduleBlock: | ||
"""Get the template schedule with parameters assigned to values. | ||
|
||
All the parameters in the template schedule block will be assigned to the values managed | ||
by the calibrations unless they are specified in assign_params. In this case the value in | ||
assign_params will override the value stored by the calibrations. A parameter value in | ||
assign_params may also be a :class:`ParameterExpression`. | ||
|
||
.. code-block:: python | ||
|
||
# Get an xp schedule with a parametric amplitude | ||
sched = cals.get_schedule("xp", 3, assign_params={"amp": Parameter("amp")}) | ||
|
||
# Get an echoed-cross-resonance schedule between qubits (0, 2) where the xp echo gates | ||
# are referenced schedules but leave their amplitudes as parameters. | ||
assign_dict = {("amp", (0,), "xp"): Parameter("my_amp")} | ||
sched = cals.get_schedule("cr", (0, 2), assign_params=assign_dict) | ||
|
||
Args: | ||
name: The name of the schedule to get. | ||
qubits: The qubits for which to get the schedule. | ||
assign_params: The parameters to assign manually. Each parameter is specified by a | ||
ParameterKey which is a named tuple of the form (parameter name, qubits, | ||
schedule name). Each entry in assign_params can also be a string corresponding | ||
to the name of the parameter. In this case, the schedule name and qubits of the | ||
corresponding ParameterKey will be the name and qubits given as arguments to | ||
get_schedule. | ||
|
||
Returns: | ||
schedule: A copy of the template schedule with all parameters assigned. | ||
""" |
This file contains 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 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 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 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 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 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 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 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.
Note that this sentence is not finished. Also, what do you mean with "Parameters may be linked"? There's only one parameter here,
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.
This indicates parameter update can affect other schedules since it's linked.