-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Update transpiler pipeline to (only) use target internally #12850
Conversation
b587438
to
9078df2
Compare
As of 9078df2, there are 347 failing tests that must be classified into one of these 2 use cases depending on the different input combinations:
More updates will follow.
|
Status after df78b1c:
|
…is gates in the preset pass managers.
df78b1c
to
8eea4cf
Compare
Status after 8eea4cf
|
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 13701403967Details
💛 - Coveralls |
15167a3
to
cbd0973
Compare
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 seems to me that this PR is probably premature for 1.3. For one, consider the following difference compared to main
:
qc = QuantumCircuit(2,2)
qc.cx(0,1)
pm = generate_preset_pass_manager(1, coupling_map=CouplingMap([[1,0]]))
tqc = pm.run(qc)
print(tqc)
The main
branch gives this:
┌───┐┌───┐┌───┐
q_0 -> 0 ┤ H ├┤ X ├┤ H ├
├───┤└─┬─┘├───┤
q_1 -> 1 ┤ H ├──■──┤ H ├
└───┘ └───┘
c: 2/═══════════════
But on transpile-only-target-pipeline
branch we get this:
q_0 -> 0 ──■──
┌─┴─┐
q_1 -> 1 ┤ X ├
└───┘
c: 2/═════
(GateDirection does not do what it's supposed to do here. See my line comments for more details).
The reason this is not caught by our unit testing is that we don't really have a way to directly compare transpilation results between versions AFAIK. Transpilation tests which do use pre-defined circuits as groundtruth (e.g. like in test_gate_direction.py
) could have catch this, but I guess none really use generate_preset_pass_manager
at all or
maybe use it but without just a coupling-map. I do see the FakeTarget
instantiation branch in target.py
reported as covered in the coverage report but probably not with those tests that compare output circuits and can flag a difference?
Anyway, once we have the above concern addressed, we should have explicit tests for the loose constraints and FakeTarget
execution path to make sure all passes are included as before and we get the expected output circuits.
Hi @eliarbel! Thanks for taking such a detailed look into the PR. I think you are raising some very good points. I definitely agree with avoiding the user exposure to the class, and I will work on an alternative not to generate the As for the implementation in Rust and use in
|
c34605d
to
bfd25d0
Compare
bfd25d0
to
ec6a46b
Compare
…level (Python interface only) instead of pm level.
…e-only-target-pipeline
7af4e42
to
10affb9
Compare
…e-only-target-pipeline
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.
So first pass over the renewed PR surfaced this:
- We need to remove the deprecated the
instruction_durations
andtiming_constraints
args fromgenerate_preset_pass_manager
. This is PR is a good place (really the last place :-) ) to do that. - Can we stop propagating
coupling_map
andbasis_gates
toPassManagerConfig
already in this PR?
The first point is a blocker for this PR, the second one is a strong nice-to-have but I wouldn't consider as a blocker.
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 went over the passes, thanks @ElePT for addressing the comments from my initial review!
I think it's a good start for the Target only flow that will facilitate cleaning the pass manager flows now, passing only target.
I've left suggestions and some questions in line.
qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py
Outdated
Show resolved
Hide resolved
… and custom basis_gates. Do not skip target unless dictated by backend. Add warning for backend + loose constraints and raise error if basis_gates contains 3q+ gates with a coupling map, as this generates a conflic in the model where it's not clear to which qubits the gates can apply. This is a limitation that comes from Target.from_configuration, but it's more user-friendly to raise the error from generate_preset_pass_manager.
…e-only-target-pipeline
Co-authored-by: Eli Arbel <46826214+eliarbel@users.noreply.github.com>
…lePT/qiskit-terra into transpile-only-target-pipeline
Thanks Eli! I still need to make sure tests pass (pretty sure there are still a few failures here and there after merging from main), and then I will make sure to apply your comments and update the reno with the input parameter removal from |
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 looks ready for me. Thanks @ElePT for the quick updates especially with the removals and 3Q gates and their related tests.
I've left a few tiny line comments for the docs; let's not block this PR over them but rather apply those in the final docs + reno updates before the final 2.0 release.
@@ -88,8 +70,7 @@ def generate_preset_pass_manager( | |||
The target constraints for the pass manager construction can be specified through a :class:`.Target` | |||
instance, a :class:`.BackendV2` instance, or via loose constraints | |||
(``basis_gates``, ``coupling_map``, ``instruction_durations``, | |||
``dt`` or ``timing_constraints``). | |||
(``basis_gates``, ``coupling_map``, or ``dt``). |
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.
(``basis_gates``, ``coupling_map``, or ``dt``). | |
(``basis_gates``, ``coupling_map`` or ``dt``). |
@@ -123,14 +102,12 @@ def generate_preset_pass_manager( | |||
backend (Backend): An optional backend object which can be used as the | |||
source of the default values for the ``basis_gates``, | |||
``coupling_map``, ``instruction_durations``, | |||
``timing_constraints``, and ``target``. If any of those other arguments | |||
``coupling_map``, and ``target``. If any of those other arguments |
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.
``coupling_map``, and ``target``. If any of those other arguments | |
``coupling_map`` and ``target``. If any of those other arguments |
raise ValueError( | ||
f"Gates with 3 or more qubits ({gate}) in `basis_gates` or `backend` are " | ||
"incompatible with a custom `coupling_map`. To include 3-qubit or larger " | ||
" gates in the transpilation basis, use a custom `target` instance instead." |
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.
" gates in the transpilation basis, use a custom `target` instance instead." | |
" gates in the transpilation basis, use a custom `Target` instance instead." |
|
||
# Check if coupling map has been provided (either standalone or through backend) | ||
# with user-defined basis_gates, and whether these have 3q or more. | ||
if coupling_map is not None and basis_gates is not 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.
That was a good catch! 👏
* `timing_constraints` | ||
In addition to this, the specification of custom basis gates through the ``basis`` gate argument of |
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.
In addition to this, the specification of custom basis gates through the ``basis`` gate argument of | |
In addition to this, the specification of custom basis gates through the ``basis_gates`` argument of |
Sounds good! Thanks for your review. I can also open a follow-up PR for the docs changes during the rc period. |
Summary
This PR is a step towards the target-only transpiler pipeline. It manages to almost exclusively use the target input to communicate transpilation constraints. To do this, I designed a (very simple) "FakeTarget" (name tbd) designed for internal use that augments the Target data model supporting the use-case of coupling map provided with no basis gates, and modified the preset pass manager creation mechanisms to contemplate this new use-case.
The creation of
FakeTarget
is not documented as part the public API, as it's designed for internal use.Details and comments
This PR addresses the following points from #9256:
Update preset pass manager construction to only pass a Target to passes. Stage plugins initialization will need to fill out all the fields in the PassManagerConfig from the Target for backwards compatibility. We can stop doing this as we deprecate non-target constraint fields in PassManagerConfig.
Deprecate anything we previously could represent that is lost in conversion to Target (or alternatively augment Target's data model to support these edge cases).
Note: There are 2 use cases where the Target is still skipped in the pass manager construction. Both are deprecated and will be removed in 2.0:
Whenever a custom basis gate is provided in
basis_gates
-> this use-case is now deprecated, the recommended alternative in these cases is to construct aTarget
user-side, which can be done through theTarget.from_configuration
method (there's acustom_name_mapping
argument that allows to use custom gate definitions). Until the deprecation period is over, we still allow custom basis gates by skipping the target.When
instruction_durations
are provided without a target or backend. The argument is deprecated, but we must support the use-case until the deprecation period is over.