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

Quantum circuits with a C3SX gate fail to convert back from qasm #7148

Closed
jond01 opened this issue Oct 17, 2021 · 3 comments · Fixed by #9183
Closed

Quantum circuits with a C3SX gate fail to convert back from qasm #7148

jond01 opened this issue Oct 17, 2021 · 3 comments · Fixed by #9183
Assignees
Labels
bug Something isn't working mod: qasm2 Relating to OpenQASM 2 import or export

Comments

@jond01
Copy link
Contributor

jond01 commented Oct 17, 2021

Information

  • Qiskit Terra version: 0.18.3
  • Python version: 3.8.5
  • Operating system: macOS-10.16-x86_64-i386-64bit

What is the current behavior?

A circuit that contains a C3SX gate can be translated to qasm, but the generated qasm cannot be translated back to a quantum circuit.
The error stems from a mismatch in the name of this gate between qelib1.inc ("c3sqrtx"):
https://github.com/Qiskit/qiskit-terra/blob/6af71f9d1e249a3747772449f299160df4047b83/qiskit/qasm/libs/qelib1.inc#L242
and qiskit's python code ("c3sx"):
https://github.com/Qiskit/qiskit-terra/blob/cf4005ff9fdc672111a827582e6b7d8ae2683be5/qiskit/circuit/library/standard_gates/x.py#L446
https://github.com/Qiskit/qiskit-terra/blob/6af71f9d1e249a3747772449f299160df4047b83/qiskit/circuit/quantumcircuit.py#L1563

Steps to reproduce the problem

import qiskit

qc = qiskit.QuantumCircuit(4)
gate = qiskit.circuit.library.C3SXGate()
qc.append(gate, qargs=qc.qubits)

qasm = qc.qasm()
qc_from_qasm = qiskit.QuantumCircuit.from_qasm_str(qasm)  # fails:
# QasmError(
# qiskit.qasm.exceptions.QasmError: "Cannot find gate definition for 'c3sx', line 4 file "

What is the expected behavior?

I would like the gate names to concur and the qasm to be convertible to a quantum circuit.

Suggested solutions

  • Rename the gate in qelib1.inc to "c3sx".
  • Change the python code to use "c3sqrtx".

(This issue probably relates to #4943.)

image

@jond01 jond01 added the bug Something isn't working label Oct 17, 2021
@Cryoris
Copy link
Contributor

Cryoris commented Oct 19, 2021

Good catch! I think renaming the qasm definition to c3sx is the way to go so we stay consistent in our naming policy.

@jond01
Copy link
Contributor Author

jond01 commented Oct 19, 2021

Thanks, if this solution is accepted I would like to submit a PR that replaces all the occurrences of c3sqrtx with c3sx - please let me know.

@Cryoris
Copy link
Contributor

Cryoris commented Oct 21, 2021

Yeah please go ahead!

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
3 participants