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

Support standalone Var throughout transpiler #12322

Merged
merged 2 commits into from
May 2, 2024

Conversation

jakelishman
Copy link
Member

Summary

This adds the missing pieces to fully support standalone Var nodes through every part of the transpiler (that I could detect). It's quite possible there's some problem in a more esoteric non-preset pass somewhere, but I couldn't spot them.

For the most part there were very few changes needed to the actual passes, and only one place in QuantumCircuit that had previously been missed. Most of the commit is updating passes to correctly pass inline_captures=True when appropriate for dealing with DAGCircuit.compose, and making sure that any place that needed to build a raw DAGCircuit for a rebuild without using DAGCircuit.copy_empty_like made sure to correctly add in the variables.

This commit adds specific tests for every pass that I touched, plus the general integration tests that we have for the transpiler to make sure that OQ3 and QPY serialisation work afterwards.

Details and comments

Close #10931.

This is the top of the stack and depends on #12215 and #12308 (the latter of which depends on #12307, though those could be merged together).

I'll write the full release note as a full PR after the tagging of rc1.

@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels May 1, 2024
@jakelishman jakelishman added this to the 1.1.0 milestone May 1, 2024
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented May 1, 2024

Pull Request Test Coverage Report for Build 8923296656

Details

  • 26 of 29 (89.66%) changed or added relevant lines in 10 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.06%) to 89.599%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/layout/apply_layout.py 5 6 83.33%
qiskit/transpiler/passes/layout/sabre_layout.py 5 6 83.33%
qiskit/transpiler/passes/routing/stochastic_swap.py 8 9 88.89%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.03%
crates/qasm2/src/lex.rs 2 92.37%
Totals Coverage Status
Change from base Build 8917584107: 0.06%
Covered Lines: 61660
Relevant Lines: 68818

💛 - Coveralls

This adds the missing pieces to fully support standalone `Var` nodes
through every part of the transpiler (that I could detect).  It's quite
possible there's some problem in a more esoteric non-preset pass
somewhere, but I couldn't spot them.

For the most part there were very few changes needed to the actual
passes, and only one place in `QuantumCircuit` that had previously been
missed.  Most of the commit is updating passes to correctly pass
`inline_captures=True` when appropriate for dealing with
`DAGCircuit.compose`, and making sure that any place that needed to
build a raw `DAGCircuit` for a rebuild _without_ using
`DAGCircuit.copy_empty_like` made sure to correctly add in the
variables.

This commit adds specific tests for every pass that I touched, plus the
general integration tests that we have for the transpiler to make sure
that OQ3 and QPY serialisation work afterwards.
@jakelishman
Copy link
Member Author

Now rebased over #12308 (speculatively assuming the merge-queue commit passes CI).

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, this was much easier to integrate than I expected. Before we merge though I had one question about treating store as a directive for backends that don't have any dynamic circuits capabilities and won't support Vars at all.

Comment on lines +62 to +63
# This is a compiler/backend intrinsic operation, separate to any quantum processing.
_directive = True
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this, but this basically means we're treating this as always supported through the transpiler regardless of what the target says. Is that the correct behavior for this? I'm mostly wondering for backends that don't have any classical logic support, and how we intend to indicate this to backends. For other control flow operations they have to be explicitly in the target to work. Is the answer just documentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Short of adding more magic fields to supported_instruction Target, which could never really capture all the constraints of dynamic-circuits requirements already, or some sort of global flag on Target/BackendV2 that we haven't really prepared to put in place, I think documentation is the answer.

Dynamic circuits have always been tricky through these tests, because there's so much that's never really been possible to represent as a restriction to the transpiler (nesting can only be to n levels, max of m blocks, switches must have a default, etc etc).

Copy link
Member

Choose a reason for hiding this comment

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

Let just go with documenting this for now as part of the 1.1.x final documentation, I'll convert this into an issue to track. Both as an upgrade note in the final release notes and also as a guidance in the writing a backend section of the docs.

I think for 1.2.x we can look at adding a global flag in the target for something like supports store, etc to provide a high level indicator for this kind of capability above the per instruction look ups. We'd probably need to do this into an opt-in way (so it defaults true) but I think having the capability to express this in the target is what we'll want longer term.

test/python/circuit/test_circuit_operations.py Outdated Show resolved Hide resolved
Comment on lines +2435 to +2437
# TODO: There's not a huge amount we can sensibly test for the output here until we can
# round-trip the OpenQASM 3 back into a Terra circuit. Mostly we're concerned that the dump
# itself doesn't throw an error, though.
Copy link
Member

Choose a reason for hiding this comment

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

You could assert the stores are preserved and present in the qasm string independent of the transpilers optimization or something I guess. But yeah it probably just makes more sense to wait for the parser to gain support for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This comment is basically just copied from the tests above from when we added the enhanced conditions to control flow.

@jakelishman
Copy link
Member Author

I'll try closing and re-opening this to see if that triggers GH to recalculate the merge base.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, I'm still mildly concerned about how we handling Store for the target/backends, but I'm fine documenting it. Realistically I feel like this will be an uncommon use case in practice and the only people using it to start will know the backend is capable of supporting it. We can look at evolving our target model to better account for this in 1.2.0

@mtreinish mtreinish added this pull request to the merge queue May 2, 2024
Merged via the queue into Qiskit:main with commit 469c989 May 2, 2024
15 of 20 checks passed
@jakelishman jakelishman deleted the var/transpiler branch May 2, 2024 14:48
ElePT pushed a commit to ElePT/qiskit that referenced this pull request May 31, 2024
* Support standalone `Var` throughout transpiler

This adds the missing pieces to fully support standalone `Var` nodes
through every part of the transpiler (that I could detect).  It's quite
possible there's some problem in a more esoteric non-preset pass
somewhere, but I couldn't spot them.

For the most part there were very few changes needed to the actual
passes, and only one place in `QuantumCircuit` that had previously been
missed.  Most of the commit is updating passes to correctly pass
`inline_captures=True` when appropriate for dealing with
`DAGCircuit.compose`, and making sure that any place that needed to
build a raw `DAGCircuit` for a rebuild _without_ using
`DAGCircuit.copy_empty_like` made sure to correctly add in the
variables.

This commit adds specific tests for every pass that I touched, plus the
general integration tests that we have for the transpiler to make sure
that OQ3 and QPY serialisation work afterwards.

* Clarify comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add testing for manual variables to transpile
4 participants