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

InverseCancellation does not run in classical blocks like CXCancellation #13437

Open
1ucian0 opened this issue Nov 14, 2024 · 2 comments · May be fixed by #13454
Open

InverseCancellation does not run in classical blocks like CXCancellation #13437

1ucian0 opened this issue Nov 14, 2024 · 2 comments · May be fixed by #13454
Assignees
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@1ucian0
Copy link
Member

1ucian0 commented Nov 14, 2024

Environment

  • Qiskit version: 2.0.0.dev0+5de0232

What is happening?

In #11212 we decided to "stop using CXCancellation as part of the preset pass managers as it's been superseded by InverseCancellation". However, CXCancellation runs inside flow controlled blocks but InverseCancellation does not.

How can we reproduce the issue?

  1. Create a circuit with control flow:
from qiskit import QuantumCircuit
inner = QuantumCircuit(2,1)
inner.cx(0, 1)
inner.cx(0, 1)

qc = QuantumCircuit(2, 1)
qc.cx(0, 1)
qc.cx(0, 1)
qc.if_else((0, True), inner.copy(), inner.copy(), range(2), [0])
qc.draw()

Image

  1. Run InverseCancellation on it
from qiskit.transpiler.passes import InverseCancellation
from qiskit.circuit.library.standard_gates import CXGate
InverseCancellation([CXGate()])(qc).draw()

Image

Notice that the CX outside got cancelled, but not those inside.

What should happen?

It should be like CXCancellation

from qiskit.transpiler.passes import CXCancellation
CXCancellation()(qc).draw()

Image

Any suggestions?

Apply InverseCancellation recursively inside the code blocks.

@1ucian0 1ucian0 added the bug Something isn't working label Nov 14, 2024
@1ucian0 1ucian0 added this to the 1.3.0 milestone Nov 14, 2024
@1ucian0 1ucian0 added the good first issue Good for newcomers label Nov 14, 2024
@github-project-automation github-project-automation bot moved this to Tagged but unassigned in Contributor Monitoring Nov 14, 2024
@1ucian0
Copy link
Member Author

1ucian0 commented Nov 14, 2024

The fix is rather straightforward. It seems like just adding the decorator @control_flow.trivial_recurse should work. Tagging as good first issue.

@haimeng-zhang
Copy link

I am in. Please assign me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Tagged but unassigned
Development

Successfully merging a pull request may close this issue.

2 participants