Skip to content
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

Split scheduling pass into scheduling and padding #7709

Merged
merged 17 commits into from
Mar 10, 2022

Conversation

nkanazawa1989
Copy link
Contributor

Now functionality of scheduling pass is split into two pieces; scheduling (analysis) and padding (transform). In between these operations, one can insert non-transform operation such as alignment (i.e. reschedule).

Summary

This PR splits functionality of scheduling passes into scheduling (analysis) and padding (transform). This is beneficial since one can interleave alignment passes, i.e. rescheduling, in between these operation without regenerating DAG. In addition, scheduling operation creates time_slot dictionary in the property set of the pass manager. This allows us to easily track instruction start time without accumulating instruction duration from the begging of the DAG wire.

Details and comments

Note that this is breaking API change since now scheduling passes insert no delay. In addition, consecutive delays are now merged into a single delay, which is necessary to correctly evaluate alignment constraints (will be in follow-up PR). Because it is not easy to dynamically switch base class (analysis -> transform pass) just for backward compatibility (technically possible though), current approach is to allow this API change and to write enough information in the release note. Since scheduling pass is used only in the specific situation (e.g. noisy circuit simulation, evaluation of alignment constraints, dynamical decoupling), the impact of this change is expected to be limited.

@nkanazawa1989 nkanazawa1989 added the Changelog: API Change Include in the "Changed" section of the changelog label Feb 25, 2022
@nkanazawa1989 nkanazawa1989 requested a review from a team as a code owner February 25, 2022 16:50
Now functionality of scheduling pass is split into two pieces; scheduling (analysis) and padding (transform). In between these operations, one can insert non-transform operation such as alignment (i.e. reschedule).
@nkanazawa1989 nkanazawa1989 deleted the upgrade/alignment-pass branch February 28, 2022 05:15
@nkanazawa1989 nkanazawa1989 restored the upgrade/alignment-pass branch February 28, 2022 05:17
@nkanazawa1989 nkanazawa1989 reopened this Feb 28, 2022
@coveralls
Copy link

coveralls commented Feb 28, 2022

Pull Request Test Coverage Report for Build 1961014800

  • 81 of 87 (93.1%) changed or added relevant lines in 11 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 83.456%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/scheduling/base_scheduler.py 6 7 85.71%
qiskit/transpiler/preset_passmanagers/level0.py 2 3 66.67%
qiskit/transpiler/preset_passmanagers/level2.py 2 3 66.67%
qiskit/transpiler/preset_passmanagers/level3.py 2 3 66.67%
qiskit/transpiler/passes/scheduling/padding.py 54 56 96.43%
Totals Coverage Status
Change from base Build 1960638229: 0.003%
Covered Lines: 52381
Relevant Lines: 62765

💛 - Coveralls

Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the direction splitting out the padding part from scheduling passes so that we can remove the overhead of creating new DAG multiple times (e.g. ASAPSchedule and AlignMeasure) in the future.

For its implementation, I think we need more discussion on what should be stored in property_set by the new ASAP/ALAPSchedule analysis pass. Currently, "start times" are stored as a dict {node: t0 (start time)}. However, the t0 information seems essentially not used in the newly implemented BasePadding pass. I'm thinking the minimal data to be stored may be "idle slots", i.e. (prev_node, node(next_node), duration), and t0 of the node is supplemental information that could be ignored in rescheduling passes such as AlignMeasure. What do you think?

I've left other minor comments and suggestions inline.

qiskit/transpiler/passes/scheduling/asap.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/alap.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/alap.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/padding.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/padding.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/padding.py Outdated Show resolved Hide resolved
nkanazawa1989 and others added 2 commits March 1, 2022 20:44
Co-authored-by: Toshinari Itoko <15028342+itoko@users.noreply.github.com>
- rename timeslot
- remove redundant sort
@nkanazawa1989
Copy link
Contributor Author

Thanks @itoko! It might be hard to grasp the entire picture of the refactoring only with this PR, but align measure and align pulse are the constraints on t0. The main target of time_slot (now it's renamed to node_start_time) is indeed these alignment passes in which currently t0 are computed by integrating duration of all ancestor nodes on the wire. Thus having start time rather than idle time makes the logic much faster.

I was also thinking to store (t0, t1) tuple in the property set, but I decided to store only t0 since t1 = t0 = node.duration (having both is bit redundant).

@itoko
Copy link
Contributor

itoko commented Mar 2, 2022

Oh, I missed that. You're right. Alignment constraints are about t0 (not duration), so we need to store t0s even if it is not directly used in Padding passes. Also, not storing t1 (and prev_node as well) sounds reasonable to me.

Comment on lines 128 to 132
# Note that some transformation pass can override .op attribute of DAGOpNode
# without breaking the reference to object. However, once operation is updated,
# there is no guarantee that the duration of node is unchanged.
key = node.name, node.sort_key, getattr(node, "_node_id")
node_start_time[key] = t0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, this is a tricky problem.. I'd like to hear more opinion on how to address this issue. I personally prefer to simply using DAGOpNode instance as a key here (i.e. give up to raise an error when someone updates node.op without updating node itself) and notify that users should not update DAG before using note_start_time property in docstrings.
Also, I'm not sure if the current key can always track the update of the node. For example, what happens if only the params are replaced in node.op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point. This code is indeed not robust to the future change of node data structure. I guess the mutability of node.op is due to performance of the Unroller node, which is likely intentional and a pass manager designer must take care for the arrangement of passes. In that sense, the padding pass here can also take node as-is rather than decomposing it for the key, and let the designer carefully choose the order of passes.

- remove duration from property set
- documentation update
Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments on comments

qiskit/transpiler/passes/scheduling/alap.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/asap.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/scheduling/padding.py Outdated Show resolved Hide resolved
Co-authored-by: Toshinari Itoko <15028342+itoko@users.noreply.github.com>
- replace start time dict key with node, unittest is dropped
- handle edge case for delay at the very end

Previously, the maximum circuit duration is generated and attached at scheduler pass. However, this duration may change in the alignment pass, the duration is dropped from the property set and re-evaluated in the padding pass. However, if user intentionally insert delay at the end of circuit, this is just ignored and circuit duration cannot be estimated properly. In this commit, new logic considers the circuit duration when the last node is delay.
Co-authored-by: Toshinari Itoko <15028342+itoko@users.noreply.github.com>
itoko
itoko previously approved these changes Mar 4, 2022
Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates, @nkanazawa1989. LGTM now.
I approve without adding automerge tag so that you could ask one more final check from other reviewers as this PR includes a big design change.

@itoko itoko added this to the 0.20 milestone Mar 4, 2022
kdk
kdk previously approved these changes Mar 7, 2022
Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on @nkanazawa1989 and @itoko . The approach here LGTM.

ajavadia
ajavadia previously approved these changes Mar 9, 2022
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments mostly on docstrings

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
@nkanazawa1989 nkanazawa1989 dismissed stale reviews from ajavadia, kdk, and itoko via f5919dc March 9, 2022 13:45
nkanazawa1989 and others added 4 commits March 9, 2022 22:45
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
…is-04333b6fef524d21.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
…is-04333b6fef524d21.yaml

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kdk kdk added the automerge label Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants