Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Control flow operations are not .decomposed #13544

Closed
Cryoris opened this issue Dec 10, 2024 · 0 comments · Fixed by #13545
Closed

Control flow operations are not .decomposed #13544

Cryoris opened this issue Dec 10, 2024 · 0 comments · Fixed by #13545
Labels
bug Something isn't working

Comments

@Cryoris
Copy link
Contributor

Cryoris commented Dec 10, 2024

Environment

  • Qiskit version: main
  • Python version: 3.11
  • Operating system: macOS

What is happening?

Operations inside control flow are not decomposed when calling QuantumCircuit.decompose. I would expect decompose to unroll the blocks inside a control flow, alike to the c_if behavior.

How can we reproduce the issue?

        qr = QuantumRegister(2)
        cr = ClassicalRegister(1)
        qc = QuantumCircuit(qr, cr)

        qc.p(0.2, 0)
        qc.measure(0, 0)

        with qc.if_test((cr[0], 0)) as else_:
            qc.cry(0.5, 0, 1)
        with else_:
            qc.crz(0.5, 0, 1)

        print(qc.decompose())

prints

      ┌────────────┐┌─┐  ┌──────              ┌────────             ───────┐
q3_0: ┤ U(0,0,0.2) ├┤M├──┤       ───────■─────┤         ─────■─────        ├─
      └────────────┘└╥┘  │ If-0    ┌────┴────┐│ Else-0  ┌────┴────┐  End-0 │
q3_1: ───────────────╫───┤       ──┤ Ry(0.5) ├┤         ┤ Rz(0.5) ├        ├─
                     ║   └──╥───   └─────────┘└──────── └─────────┘ ───────┘
                     ║ ┌────╨─────┐
c1: 1/═══════════════╩═╡ c1_0=0x0 ╞══════════════════════════════════════════
                     0 └──────────┘

What should happen?

      ┌────────────┐┌─┐  ┌──────                                      ┌────────                                     ───────┐
q3_0: ┤ U(0,0,0.2) ├┤M├──┤       ────────────────■─────────────────■──┤         ──────────────■─────────────────■──        ├─
      └────────────┘└╥┘  │ If-0    ┌──────────┐┌─┴─┐┌───────────┐┌─┴─┐│ Else-0  ┌──────────┐┌─┴─┐┌───────────┐┌─┴─┐  End-0 │
q3_1: ───────────────╫───┤       ──┤ Ry(0.25) ├┤ X ├┤ Ry(-0.25) ├┤ X ├┤         ┤ Rz(0.25) ├┤ X ├┤ Rz(-0.25) ├┤ X ├        ├─
                     ║   └──╥───   └──────────┘└───┘└───────────┘└───┘└──────── └──────────┘└───┘└───────────┘└───┘ ───────┘
                     ║ ┌────╨─────┐
c1: 1/═══════════════╩═╡ c1_0=0x0 ╞══════════════════════════════════════════════════════════════════════════════════════════
                     0 └──────────┘

Any suggestions?

No response

@Cryoris Cryoris added the bug Something isn't working label Dec 10, 2024
@Cryoris Cryoris linked a pull request Dec 10, 2024 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant