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

Qasm exporter fails with RYYGate in subcircuit (with inverse) QasmError: "Duplicate declaration for gate 'ryy' #7771

Closed
MattePalte opened this issue Mar 13, 2022 · 0 comments · Fixed by #9953
Labels
bug Something isn't working mod: qasm2 Relating to OpenQASM 2 import or export

Comments

@MattePalte
Copy link

Environment

  • Qiskit Terra version: 0.19.1
  • Python version: 3.8
  • Operating system: Ubuntu 18.04.6 LTS

What is happening?

Using an RYYGate in a subcircuit and then exporting it to qasm gives an invalid qasm code, which raise an error in case it is reimported. This happens only if the subcircuit and the subcircuit's inverse are both added to the larger circuit.

How can we reproduce the issue?

Run this snippets:

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.library.standard_gates import *
qr = QuantumRegister(2, name='qr')
cr = ClassicalRegister(2, name='cr')
qc = QuantumCircuit(qr, cr, name='qc')
subcircuit = QuantumCircuit(qr, name='subcircuit')
subcircuit.append(RYYGate(5.76), qargs=[qr[0], qr[1]], cargs=[])
qc.append(subcircuit, qargs=qr)
qc.append(subcircuit.inverse(), qargs=qr)
qc.qasm(formatted=True)

Output:

OPENQASM 2.0;
include "qelib1.inc";
gate ryy(param0) q0,q1 { rx(pi/2) q0; rx(pi/2) q1; cx q0,q1; rz(-5.76) q1; cx q0,q1; rx(-pi/2) q0; rx(-pi/2) q1; }
gate ryy(param0) q0,q1 { rx(pi/2) q0; rx(pi/2) q1; cx q0,q1; rz(5.76) q1; cx q0,q1; rx(-pi/2) q0; rx(-pi/2) q1; }
gate subcircuit q0,q1 { ryy(5.76) q0,q1; }
gate subcircuit_dg q0,q1 { ryy(-5.76) q0,q1; }
qreg qr[2];
creg cr[2];
subcircuit qr[0],qr[1];
subcircuit_dg qr[0],qr[1];

Reimport the qasm code:

qc = QuantumCircuit.from_qasm_str(qc.qasm())

Output

QasmError: "Duplicate declaration for gate 'ryy' at line 4, file .\nPrevious occurrence at line 3, file "

What should happen?

The QASMexporter should generate a valid qasm.

Any suggestions?

This is probably related to the issue #7749 , but I fear they might be different since this case involves a subcircuit and an call to the inverse.
Looking forward to listening to your feedback. Thanks in advance

@MattePalte MattePalte added the bug Something isn't working label Mar 13, 2022
@1ucian0 1ucian0 added the mod: qasm2 Relating to OpenQASM 2 import or export label Mar 14, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants