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

Assertion error attempting to convert circuit containing nested conditional to QASM #1745

Open
cqc-alec opened this issue Jan 22, 2025 · 1 comment

Comments

@cqc-alec
Copy link
Collaborator

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

cbox = CircBox(Circuit(1, 1).H(Qubit(0), condition=Bit(0)))
c = Circuit(1, 2).add_circbox(cbox, [Qubit(0), Bit(0)], condition=Bit(1))
DecomposeBoxes().apply(c)

print(c.get_commands())
print(circuit_to_qasm_str(c, header="hqslib1"))

Output:

[IF ([c[1]] == 1) THEN IF ([c[0]] == 1) THEN H q[0];]
Traceback (most recent call last):
  File "/home/alec/r/tket/play/1583a.py", line 10, in <module>
    print(circuit_to_qasm_str(c, header="hqslib1"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alec/r/tket/pytket/pytket/qasm/qasm.py", line 1192, in circuit_to_qasm_str
    qasm_writer.add_op(command.op, command.args)
  File "/home/alec/r/tket/pytket/pytket/qasm/qasm.py", line 1953, in add_op
    self.add_conditional(op, args)
  File "/home/alec/r/tket/pytket/pytket/qasm/qasm.py", line 1728, in add_conditional
    assert string is not None
           ^^^^^^^^^^^^^^^^^^
AssertionError
@cqc-alec
Copy link
Collaborator Author

Having checked the specification for QASM 2 (both the original version and the extended version as defined in https://github.com/CQCL/tket/blob/main/pytket/pytket/qasm/grammar.py ), I've realized that nested conditionals are not supported in QASM at all. So the only issue here is that we fail with an AssertionError rather than a more friendly error.

@cqc-alec cqc-alec removed their assignment Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant