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

DecomposeBoxes doesn't decompose CircBox with nested classical control #1583

Closed
sjdilkes opened this issue Sep 16, 2024 · 5 comments · Fixed by #1746
Closed

DecomposeBoxes doesn't decompose CircBox with nested classical control #1583

sjdilkes opened this issue Sep 16, 2024 · 5 comments · Fixed by #1746
Assignees
Labels
bug Something isn't working classical-logic issues related to classical logical expressions

Comments

@sjdilkes
Copy link
Contributor

See:

from pytket.circuit import CircBox, Circuit, Bit, Qubit
from pytket.qasm import circuit_to_qasm_str
from pytket.passes import DecomposeBoxes

c_inner: Circuit = Circuit(4, 1)
cbox: CircBox = CircBox(Circuit(4).H(0).H(1).H(2).H(3).CX(0, 1).CX(1, 2).CX(2, 3))
c_inner.add_circbox(cbox, [Qubit(i) for i in range(4)], condition=Bit(0))

c_outer: Circuit = Circuit(4, 2)
c_outer.add_circbox(CircBox(c_inner), c_inner.qubits + c_inner.bits, condition=Bit(1))

DecomposeBoxes().apply(c_outer)
print(circuit_to_qasm_str(c_outer, header="hqslib1"))

This code gives an error as c_outer still has a CircBox internally. Printing the circuit commands will give IF ([c[1]] == 1) THEN IF ([c[0]] == 1) THEN CircBox q[0], q[1], q[2], q[3];.

@sjdilkes sjdilkes added the classical-logic issues related to classical logical expressions label Sep 16, 2024
@sjdilkes
Copy link
Contributor Author

Alternatively, applying auto_rebase_pass({OpType.ZZPhase, OpType.PhasedX, OpType.Rz}).apply(c_outer) to the circuit throws a BadOpType error, complaining about a conditional operation.

@cqc-alec cqc-alec added the bug Something isn't working label Oct 8, 2024
@cqc-alec cqc-alec self-assigned this Jan 15, 2025
@cqc-alec
Copy link
Collaborator

cqc-alec commented Jan 22, 2025

I have a fix for the DecomposeBoxes issue (PR coming soon), but even after the fix it doesn't seem possible to convert to QASM. I've created a separate issue for this ( #1745 ).

EDIT: Turns out nested conditionals are just not supported by QASM at all.

@sjdilkes
Copy link
Contributor Author

I have a fix for the DecomposeBoxes issue (PR coming soon), but even after the fix it doesn't seem possible to convert to QASM. I've created a separate issue for this ( #1745 ).

EDIT: Turns out nested conditionals are just not supported by QASM at all.

If they aren't supported then it sounds like we can close this issue once #1746 is merged?

@cqc-alec
Copy link
Collaborator

If they aren't supported then it sounds like we can close this issue once #1746 is merged?

Yes, though I may open another one for the rebase failure.

@cqc-alec
Copy link
Collaborator

If they aren't supported then it sounds like we can close this issue once #1746 is merged?

Yes, though I may open another one for the rebase failure.

Ah, there is already #1727 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working classical-logic issues related to classical logical expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants