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

Cannot build a circuit from qasm with an ecr gate #5536

Closed
nonhermitian opened this issue Dec 16, 2020 · 4 comments · Fixed by #9955
Closed

Cannot build a circuit from qasm with an ecr gate #5536

nonhermitian opened this issue Dec 16, 2020 · 4 comments · Fixed by #9955
Assignees
Labels
bug Something isn't working

Comments

@nonhermitian
Copy link
Contributor

Information

  • Qiskit Terra version: latest
  • Python version:
  • Operating system:

What is the current behavior?

In trying to build a circuit from qasm using an ecr gate:

['OPENQASM 2.0;',
 'include "qelib1.inc";',
 'gate ecr q0, q1 { U(3*pi/2, pi, pi) q0; U(pi/2, pi/2, 3*pi/2) q1; CX q0, q1; }',
 'qreg q[2];',
 'creg meas[2];',
 'h q[0];',
 'ecr q[0],q[1];',
 'barrier q[0],q[1];',
 'measure q[0] -> meas[0];',
 'measure q[1] -> meas[1];',
 '']

QuantumCircuit.from_qasm_str(qasm_str)

I get the following error:

 File "/opt/conda/lib/python3.7/site-packages/qiskit/converters/ast_to_dag.py", line 401, in _gate_rules_to_qiskit_circuit
    op = self._create_op(child_op.name, params=eparams)
AttributeError: 'UniversalUnitary' object has no attribute 'name'

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

@nonhermitian nonhermitian added the bug Something isn't working label Dec 16, 2020
@kdk
Copy link
Member

kdk commented Dec 16, 2020

Looks like .name is never set for the built-in Cnot and UniversalUnitary classes (so, this works if U/CX are replaced with u/cx). Any idea why @1ucian0 ?

@francabrera
Copy link
Member

in addition to that, should this gate be included in the qelib1.inc https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/qasm/libs/qelib1.inc being a basis gate?

@kdk kdk added this to the 0.18 milestone Apr 8, 2021
@1ucian0
Copy link
Member

1ucian0 commented Jun 15, 2021

I think the problem is about scoping. The following works:

qasm_str = '\n'.join(['OPENQASM 2.0;',
                      'include "qelib1.inc";',
                      'qreg q[2];',
                      'U(3*pi/2, pi, pi) q[0];',
                      'CX q[0], q[1];',
                      ''])

print(QuantumCircuit.from_qasm_str(qasm_str))

@1ucian0
Copy link
Member

1ucian0 commented Jun 15, 2021

in addition to that, should this gate be included in the qelib1.inc https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/qasm/libs/qelib1.inc being a basis gate?

We are moving towards leaving qelib1.inc fixed, following the paper definition. See #4312 and #6125

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.

4 participants