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

OpenQASM3 dumper does not work with repeated conditionals #11936

Closed
1ucian0 opened this issue Mar 2, 2024 · 1 comment · Fixed by #11940
Closed

OpenQASM3 dumper does not work with repeated conditionals #11936

1ucian0 opened this issue Mar 2, 2024 · 1 comment · Fixed by #11940
Labels
bug Something isn't working mod: qasm2 Relating to OpenQASM 2 import or export mod: qasm3 Related to OpenQASM 3 import or export

Comments

@1ucian0
Copy link
Member

1ucian0 commented Mar 2, 2024

Environment

  • Qiskit version: 1.1.0.dev0+197e78c
  • Python version: 3.11.7
  • Operating system: MacOS

What is happening?

While I was trying to reproduce #11935 (and succeeding), I noticed that the OpenQASM3 dumper has the same problem. It seems that is not working with repeated conditionals

How can we reproduce the issue?

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.library.standard_gates import CXGate

qr = QuantumRegister(2, name='qr')
cr = ClassicalRegister(2, name='cr')
qc = QuantumCircuit(qr, cr, name='qc')
qc.append(CXGate().c_if(cr, 0).repeat(1), qargs=qr)

from qiskit.qasm3 import dumps

print(dumps(qc))
KeyError: "'ClassicalRegister(2, 'cr')' is not defined in the current context"

What should happen?

Notice that the example works with OpenQASM 2 dumper:

from qiskit.qasm2 import dumps

print(dumps(qc))
OPENQASM 2.0;
include "qelib1.inc";
gate cx_1 q0,q1 { if(cr==0) cx q0,q1; }
qreg qr[2];
creg cr[2];
cx_1 qr[0],qr[1];

Any suggestions?

No response

@1ucian0 1ucian0 added the bug Something isn't working label Mar 2, 2024
@jakelishman
Copy link
Member

The problem here is happening some time before we get to the OQ2 and OQ3 dumpers (note that the OQ2 dumper's output is invalid OQ2). Looks like a Gate with a condition is being allowed to be used in some other Gate object, but classical conditions aren't unitary so that should have been forbidden. The error's more likely in Gate.repeat than the dumpers, here.

@jakelishman jakelishman added mod: qasm2 Relating to OpenQASM 2 import or export mod: qasm3 Related to OpenQASM 3 import or export labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: qasm2 Relating to OpenQASM 2 import or export mod: qasm3 Related to OpenQASM 3 import or export
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants