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

Add ContractIdleWiresInControlFlow optimisation pass #13779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakelishman
Copy link
Member

Summary

This transpiler pass removes data dependencies on idle qubits from control-flow operations. For example, given a circuit such as::

from qiskit.circuit import QuantumCircuit

qc = QuantumCircuit(1, 1)
qc.x(0)
with qc.if_test((qc.clbits[0], True)):
    qc.x(0)
    qc.x(0)
qc.x(0)

the current optimisation passes will collapse the inner control-flow block to the identity, but the qubit dependency will remain, preventing the outer two X gates from being cancelled. This pass removes the now-spurious dependency, making it possible to detect and remove the two X gates in a follow-up loop iteration.

As an accidental side-effect of their algorithms, the control-flow-aware routing passes currently do this when they run. This aims to move the logic into a suitable place to run before routing (so the spurious dependency never arises in routing in the first place) and in the low-level optimisation stage.

The aim of this pass is also to centralise the logic, so when the addition of the new box scope with different semantics around whether a wire is truly idle in the box or not, the routers aren't accidentally breaking them, and it's clearer when the modifications happen.

Details and comments

Built on top of #13774, since it's very convenient to have that method for writing the tests. This is one part of #13768.

I haven't hooked this up to the preset pass-managers in this commit; I wanted to do that after #13768 is fixed properly and potentially once box itself has landed.

@jakelishman jakelishman added on hold Can not fix yet Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Feb 3, 2025
@jakelishman jakelishman added this to the 2.0.0 milestone Feb 3, 2025
@jakelishman jakelishman requested a review from a team as a code owner February 3, 2025 13:07
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Feb 3, 2025

Pull Request Test Coverage Report for Build 13156083905

Details

  • 51 of 51 (100.0%) changed or added relevant lines in 3 files are covered.
  • 11 unchanged lines in 4 files lost coverage.
  • Overall coverage remained the same at 88.667%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 92.08%
crates/accelerate/src/unitary_synthesis.rs 1 92.97%
crates/qasm2/src/lex.rs 3 92.23%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 13154732632: 0.0%
Covered Lines: 79006
Relevant Lines: 89104

💛 - Coveralls

This transpiler pass removes data dependencies on idle qubits from
control-flow operations.  For example, given a circuit such as::

    from qiskit.circuit import QuantumCircuit

    qc = QuantumCircuit(1, 1)
    qc.x(0)
    with qc.if_test((qc.clbits[0], True)):
        qc.x(0)
        qc.x(0)
    qc.x(0)

the current optimisation passes will collapse the inner control-flow
block to the identity, but the qubit dependency will remain, preventing
the outer two X gates from being cancelled.  This pass removes the
now-spurious dependency, making it possible to detect and remove the two
X gates in a follow-up loop iteration.

As an accidental side-effect of their algorithms, the control-flow-aware
routing passes currently do this when they run.  This aims to move the
logic into a suitable place to run before routing (so the spurious
dependency never arises in routing in the first place) and in the
low-level optimisation stage.

The aim of this pass is also to centralise the logic, so when the
addition of the new `box` scope with different semantics around whether
a wire is truly idle in the box or not, the routers aren't accidentally
breaking them, and it's clearer when the modifications happen.
@jakelishman jakelishman force-pushed the control-flow/strip-data-dependency branch from c3ba4bf to ff133cf Compare February 5, 2025 11:11
@jakelishman jakelishman removed the on hold Can not fix yet label Feb 5, 2025
@jakelishman
Copy link
Member Author

Rebased over main and no longer on hold.

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: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants