-
Notifications
You must be signed in to change notification settings - Fork 131
Calibrations fixes #740
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
Calibrations fixes #740
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0a7de31
* Added the following consistency fixes for Calibrations:
eggerdj 558c5ea
* Extra timezone fix and black
eggerdj d0695d6
* Removed unneeded check.
eggerdj eace06e
* Added more robust test.
eggerdj f3b76b9
* Added utility functions for Calibrations.
eggerdj 3a5953c
* Lint and docs.
eggerdj 484a54c
Merge branch 'main' into issue-558
eggerdj 56a9b70
* Require coupling map.
eggerdj fc39a1b
* Test fix.
eggerdj d804a1b
* Lint.
eggerdj e788f9d
Merge branch 'main' into issue-558
eggerdj 84be06d
* Type hint.
eggerdj 54c0a68
Update qiskit_experiments/calibration_management/calibrations.py
eggerdj 66df2fa
Update qiskit_experiments/calibration_management/calibrations.py
eggerdj 7b835d8
Update qiskit_experiments/calibration_management/calibrations.py
eggerdj aacba9a
* Reverted commit 66df2fa
eggerdj 29bd57f
* Return value for CalibrationUtils.
eggerdj a26b5b7
* Refactor of internals of _used_in_calls
eggerdj d48dd49
Apply suggestions from code review
eggerdj 6035069
* Moved to stand-alone functions in the cal utils.
eggerdj 648c878
Merge branch 'issue-558' of github.com:eggerdj/qiskit-experiments int…
eggerdj 46b9b23
Merge branch 'main' into issue-558
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
62 changes: 62 additions & 0 deletions
62
qiskit_experiments/calibration_management/calibration_utils.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,62 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2019-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 helper functions""" | ||
|
|
||
| from typing import List, Set | ||
| from qiskit.pulse import ScheduleBlock, Call | ||
|
|
||
|
|
||
| def used_in_calls(schedule_name: str, schedules: List[ScheduleBlock]) -> Set[str]: | ||
| """Find the schedules in the given list that call a given schedule by name. | ||
|
|
||
| Args: | ||
| schedule_name: The name of the callee to identify. | ||
| schedules: A list of potential caller schedules to search. | ||
|
|
||
| Returns: | ||
| A set of schedule names that call the given schedule. | ||
| """ | ||
| caller_names = set() | ||
|
|
||
| for schedule in schedules: | ||
| if _used_in_calls(schedule_name, schedule): | ||
| caller_names.add(schedule.name) | ||
|
|
||
| return caller_names | ||
|
|
||
|
|
||
| def _used_in_calls(schedule_name: str, schedule: ScheduleBlock) -> bool: | ||
| """Recursively find if the schedule calls a schedule with name ``schedule_name``. | ||
|
|
||
| Args: | ||
| schedule_name: The name of the callee to identify. | ||
| schedule: The schedule to parse. | ||
|
|
||
| Returns: | ||
| True if ``schedule``calls a ``ScheduleBlock`` with name ``schedule_name``. | ||
| """ | ||
| blocks_have_schedule = False | ||
|
|
||
| for block in schedule.blocks: | ||
| if isinstance(block, Call): | ||
| if block.subroutine.name == schedule_name: | ||
| return True | ||
| else: | ||
| blocks_have_schedule = blocks_have_schedule or _used_in_calls( | ||
| schedule_name, block.subroutine | ||
| ) | ||
|
|
||
| if isinstance(block, ScheduleBlock): | ||
| blocks_have_schedule = blocks_have_schedule or _used_in_calls(schedule_name, block) | ||
|
|
||
| return blocks_have_schedule |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # 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. | ||
|
|
||
| """Class to test utility functions for calibrations.""" | ||
|
|
||
| from test.base import QiskitExperimentsTestCase | ||
| import qiskit.pulse as pulse | ||
| from qiskit_experiments.calibration_management.calibration_utils import used_in_calls | ||
|
|
||
|
|
||
| class TestCalibrationUtils(QiskitExperimentsTestCase): | ||
| """Test the function in CalUtils.""" | ||
|
|
||
| def test_used_in_calls(self): | ||
| """Test that we can identify schedules by name when calls are present.""" | ||
|
|
||
| with pulse.build(name="xp") as xp: | ||
| pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1)) | ||
|
|
||
| with pulse.build(name="xp2") as xp2: | ||
| pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(1)) | ||
|
|
||
| with pulse.build(name="call_xp") as xp_call: | ||
| pulse.call(xp) | ||
|
|
||
| with pulse.build(name="call_call_xp") as xp_call_call: | ||
| pulse.play(pulse.Drag(160, 0.5, 40, 0.2), pulse.DriveChannel(1)) | ||
| pulse.call(xp_call) | ||
|
|
||
| self.assertSetEqual(used_in_calls("xp", [xp_call]), {"call_xp"}) | ||
| self.assertSetEqual(used_in_calls("xp", [xp2]), set()) | ||
| self.assertSetEqual( | ||
| used_in_calls("xp", [xp_call, xp_call_call]), {"call_xp", "call_call_xp"} | ||
| ) | ||
|
|
||
| with pulse.build(name="xp") as xp: | ||
| pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2)) | ||
|
|
||
| cr_tone_p = pulse.GaussianSquare(640, 0.2, 64, 500) | ||
| rotary_p = pulse.GaussianSquare(640, 0.1, 64, 500) | ||
|
|
||
| cr_tone_m = pulse.GaussianSquare(640, -0.2, 64, 500) | ||
| rotary_m = pulse.GaussianSquare(640, -0.1, 64, 500) | ||
|
|
||
| with pulse.build(name="cr") as cr: | ||
| with pulse.align_sequential(): | ||
| with pulse.align_left(): | ||
| pulse.play(rotary_p, pulse.DriveChannel(3)) # Rotary tone | ||
| pulse.play(cr_tone_p, pulse.ControlChannel(2)) # CR tone. | ||
| pulse.call(xp) | ||
| with pulse.align_left(): | ||
| pulse.play(rotary_m, pulse.DriveChannel(3)) | ||
| pulse.play(cr_tone_m, pulse.ControlChannel(2)) | ||
| pulse.call(xp) | ||
|
|
||
| self.assertSetEqual(used_in_calls("xp", [cr]), {"cr"}) |
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.