-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
schedule() considers instruction map #10988
Conversation
…easure function of macros.py in qiskit/qiskit/pulse
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
sir, please see if my efforts a good enough :), please let me know if any additional changes are required :) |
@to24toro Could you please review the PR first? I'll merge if this looks good. |
Thank you @MozammilQ . I have two additional requests for improvement.
|
Since, get_measure_schedule is an innner function , so backend from lower_gates will be available to the inner function, so backend argument in the inner function is redundant :) Co-authored-by: Kento Ueda <38037695+to24toro@users.noreply.github.com>
…ument from the function call of get_measure_schedule
DONE
DONE
I do not understand what I am supposed to do here, anyways I have added relevant docstring in the changed methods which I forgot to add, am I supposed to do anything else? adding explanations for added arguments in which file? and I have run all tests with tox and all tests have passed. |
Thank you @MozammilQ . I will confirm it. |
@to24toro , :) |
Thank you @MozammilQ . Especially, it's better to add the backendV2 version of
However, this requires some knowledges and it might be tough. |
Co-authored-by: Kento Ueda <38037695+to24toro@users.noreply.github.com>
Co-authored-by: Kento Ueda <38037695+to24toro@users.noreply.github.com>
Co-authored-by: Kento Ueda <38037695+to24toro@users.noreply.github.com>
Co-authored-by: Kento Ueda <38037695+to24toro@users.noreply.github.com>
@to24toro , please see if this is ok :) |
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.
Thank you @MozammilQ for adding tests. Your comments about the pulse durations is very clear and helps me understand it. I suggested the minor changes.
I would like you to add the release note about the bugfix (see: https://github.com/Qiskit/qiskit/blob/main/CONTRIBUTING.md#release-notes)
def test_unavailable_defaults(self): | ||
"""Test backend with unavailable defaults.""" | ||
qr = QuantumRegister(1) | ||
qc = QuantumCircuit(qr) | ||
backend = FakeBackend(None) | ||
backend.defaults = backend.configuration | ||
self.assertRaises(QiskitError, lambda: schedule(qc, backend)) | ||
|
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.
def test_unavailable_defaults(self): | |
"""Test backend with unavailable defaults.""" | |
qr = QuantumRegister(1) | |
qc = QuantumCircuit(qr) | |
backend = FakeBackend(None) | |
backend.defaults = backend.configuration | |
self.assertRaises(QiskitError, lambda: schedule(qc, backend)) |
This test is not related with the backend version and you can remove it.
"""Test ALAP scheduling.""" | ||
# ┌────┐ ░ ┌────┐ ┌─┐ | ||
# q0_0: ┤ √X ├─░─┤ √X ├────────■──┤M├─── | ||
# ├────┤ ░ ├────┤┌────┐┌─┴─┐└╥┘┌─┐ | ||
# q0_1: ┤ √X ├─░─┤ √X ├┤ √X ├┤ X ├─╫─┤M├ | ||
# └────┘ ░ └────┘└────┘└───┘ ║ └╥┘ | ||
# c0: 2/═══════════════════════════╩══╩═ | ||
# 0 1 | ||
|
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.
I don't understand that you change the number of gates from backendV1?
Isn't it enough to replace U2 gates with sx gates?
prelude: > | ||
Added support for BackendV2 in schedule of qiskit.compiler.scheduler. | ||
Test methods in test/python/scheduler/test_basic_scheduler.py have been replicated with backend | ||
being BackenV2. | ||
features: | ||
- | | ||
Adds support for BackendV2 in schedule of qiskit.compiler.scheduler. | ||
Example usage:: | ||
#import a fake backend which is a sub-class of BackendV2. | ||
from qiskit.providers.fake_provider import FakePerth | ||
from qiskit.compiler.scheduler import schedule | ||
|
||
from qiskit.circuit import QuantumCircuit | ||
qc=QuantumCircuit(1, 1) | ||
qc.x(0) | ||
qc.measure(0,0) | ||
sched=schedule(circuits=qc, backend=FakePerth()) | ||
|
||
|
||
- | | ||
Adds tests with backend being a sub-class of BackendV2. | ||
In test file:: test/python/scheduler/test_basic_scheduler.py | ||
All the test methods that used BackendV1 has been replicated to use BackendV2. | ||
|
||
|
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.
prelude: > | |
Added support for BackendV2 in schedule of qiskit.compiler.scheduler. | |
Test methods in test/python/scheduler/test_basic_scheduler.py have been replicated with backend | |
being BackenV2. | |
features: | |
- | | |
Adds support for BackendV2 in schedule of qiskit.compiler.scheduler. | |
Example usage:: | |
#import a fake backend which is a sub-class of BackendV2. | |
from qiskit.providers.fake_provider import FakePerth | |
from qiskit.compiler.scheduler import schedule | |
from qiskit.circuit import QuantumCircuit | |
qc=QuantumCircuit(1, 1) | |
qc.x(0) | |
qc.measure(0,0) | |
sched=schedule(circuits=qc, backend=FakePerth()) | |
- | | |
Adds tests with backend being a sub-class of BackendV2. | |
In test file:: test/python/scheduler/test_basic_scheduler.py | |
All the test methods that used BackendV1 has been replicated to use BackendV2. |
Thank you for adding the release notes and sorry for my poor explanation. It would be sufficient to just add an item for "fixes". Also, please describe what was fixed in the fixes section. It would be good to briefly mention what was fixed, such as enabling scheduling using backendV2.
@to24toro , is everything good now? :) |
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.
Thank you @MozammilQ . This Bugfix definitely helps users.
def lower_gates( | ||
circuit: QuantumCircuit, | ||
schedule_config: ScheduleConfig, | ||
backend: Optional[Union[BackendV1, BackendV2]] = None, |
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.
It's a little nitpicky, but all these unions could be replaced with Backend
.
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.
Thanks @MozammilQ for contribution and @to24toro for review. I just added suggestion of the release note cleanup. You can push commit button if you like it. I'll approve the PR as is so that we can safely add this PR to merge queue before the release date.
...otes/Adding-BackendV2-support-to-schedule-of-qiskit.compiler.scheduler-a0366d3397c73af0.yaml
Outdated
Show resolved
Hide resolved
…kit.compiler.scheduler-a0366d3397c73af0.yaml Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
@nkanazawa1989 , does this look good now? :) |
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.
Thanks @MozammilQ this looks good to me. I'll add this to merge queue.
Pull Request Test Coverage Report for Build 6568856424
💛 - Coveralls |
Summary
In issue #10837 , I discovered that the schedule of qiskit.compiler works fine for BackendV1 but doesn't work for BackendV2. See this comment for details.
Details and comments
Details:
On inspection I discovered that measure function in macros.py requires backend, It uses backend to decide which of the two private methods _measure_v1 or _measure_v2 to call.
So, I decided to pass in this backend from the user to measure of macros.py
I did this as follows:
1>> I changed the definition of schedule_circuit in qiskit/qiskit/scheduler/schedule_circuit.py and added backend as Optional here.
2>> I used this backend and passed it to as_soon_as_possible and as_late_as_possible of qiskit/qiskit/scheduler/methods/basic.py, I also changed the definition of these two methods as_soon_as_possible and as_late_as_possible.
3>> I passed this backend to lower_gates by changing the definition of lower_gates in qiskit/qiskit/scheduler/lowering.py
4>> I also changed the definition of the nested function get_measure_schedule of lowering.py.
5>> Finally I passed in the backend to measure of macros.py
I have made backend in the definition of these changed methods Optional because I do not want the tests to fail, complaining the methods require backend as an additional argument.
I have reformatted the files that I changed and made sure that all the tests have passed! :)
Comments:
qiskit/qiskit/compile/scheduler.py in the definition of schedule one cannot omit the backend because, how the inst_map is processed depends on it.Furthermore, there is no need to ask for inst_map and meas_map separately if you already have the backend with you!So, backend should not be Optional here! I think inst_map, meas_map and dt are redundant here, please correct me if I am wrong :)
Final result after issue fixed: