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: wrong order of gate definitions Cannot find gate definition for 'rcccx' #7773

Closed
MattePalte opened this issue Mar 14, 2022 · 0 comments · Fixed by #9953
Closed
Labels
bug Something isn't working

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?

The qasm exporter gives an invalid qasm in the order of gate definition, this happens with RC3XGate and C4XGate in a subcircuit.

How can we reproduce the issue?

Run:

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.library.standard_gates import *
qr = QuantumRegister(5, name='qr')
cr = ClassicalRegister(5, name='cr')
qc = QuantumCircuit(qr, cr, name='qc')
qc.append(RC3XGate(), qargs=[qr[0], qr[1], qr[2], qr[3]], cargs=[])
subcircuit = QuantumCircuit(qr, name='subcircuit')
subcircuit.append(C4XGate(), qargs=[qr[0], qr[1], qr[2], qr[3], qr[4]])
qc.append(subcircuit, qargs=qr)
qc.measure(qr, cr)
qc.qasm(formatted=True)

Output:

OPENQASM 2.0;
include "qelib1.inc";
gate rcccx_dg q0,q1,q2,q3 { u2(-2*pi,pi) q3; u1(pi/4) q3; cx q2,q3; u1(-pi/4) q3; u2(-2*pi,pi) q3; u1(pi/4) q3; cx q1,q3; u1(-pi/4) q3; cx q0,q3; u1(pi/4) q3; cx q1,q3; u1(-pi/4) q3; cx q0,q3; u2(-2*pi,pi) q3; u1(pi/4) q3; cx q2,q3; u1(-pi/4) q3; u2(-2*pi,pi) q3; }
gate mcx q0,q1,q2,q3,q4 { h q4; cu1(pi/2) q3,q4; h q4; rcccx q0,q1,q2,q3; h q4; cu1(-pi/2) q3,q4; h q4; rcccx_dg q0,q1,q2,q3; c3sx q0,q1,q2,q4; }
gate rcccx q0,q1,q2,q3 { u2(0,pi) q3; u1(pi/4) q3; cx q2,q3; u1(-pi/4) q3; u2(0,pi) q3; cx q0,q3; u1(pi/4) q3; cx q1,q3; u1(-pi/4) q3; cx q0,q3; u1(pi/4) q3; cx q1,q3; u1(-pi/4) q3; u2(0,pi) q3; u1(pi/4) q3; cx q2,q3; u1(-pi/4) q3; u2(0,pi) q3; }
gate subcircuit q0,q1,q2,q3,q4 { mcx q0,q1,q2,q3,q4; }
qreg qr[5];
creg cr[5];
rcccx qr[0],qr[1],qr[2],qr[3];
subcircuit qr[0],qr[1],qr[2],qr[3],qr[4];
measure qr[0] -> cr[0];
measure qr[1] -> cr[1];
measure qr[2] -> cr[2];
measure qr[3] -> cr[3];
measure qr[4] -> cr[4];

Read the qasm, leads to error: Cannot find gate definition for 'rcccx', line 4 file

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

What should happen?

The generated qasm should have had rcccx and mcx definitions swapped.

Any suggestions?

Provided that #7148 will be fixed, then it would be sufficient to reorder the gate definition. Thus fixing this bug, with a post-processing reordering will probably benefit also #7769 .
I am wondering if you think that this and #7769 have the same root cause or they have different reason why they end up with out of order gate definitions?

These features of the program concur to produce the error (removing any of them result in a valid qasm):

  • the RC3XGate
  • the C4XGate (SPECIFICALLY in the subcircuit)

Looking forward to hearing your feedback on this situation, thanks in advance

@MattePalte MattePalte added the bug Something isn't working 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant