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

crash on a qasm with U gates #185

Closed
lpxz opened this issue Dec 9, 2017 · 3 comments
Closed

crash on a qasm with U gates #185

lpxz opened this issue Dec 9, 2017 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@lpxz
Copy link

lpxz commented Dec 9, 2017

the crash-inducing input is: https://github.com/QISKit/openqasm/blob/master/examples/ibmqx2/qe_qft_4.qasm

the code snippet:

from qiskit import qasm, unroll
basis_gates = "id,x,y,z,h,s,sdg,cx,t,tdg,u1,u2,u3,cy,cz,ccx,cu1,cu3".split(",")
ast = qasm.Qasm(filename=qasm_file).parse() # Node (AST)
unrolled_circuit = unroll.Unroller(ast=ast, backend=unroll.DAGBackend(basis_gates))
unrolled_circuit.execute()
circuit_unrolled = unrolled_circuit.backend.circuit # circuit DAG

The crash stack trace:

Traceback (most recent call last):
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/tools/sympy_executor/sympy_executor.py", line 106, in
qcheckermain(args)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/tools/sympy_executor/sympy_executor.py", line 88, in qcheckermain
unrolled_circuit.execute()
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_unroller.py", line 279, in execute
self._process_node(self.ast)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_unroller.py", line 187, in _process_node
self._process_children(node)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_unroller.py", line 182, in _process_children
self._process_node(kid)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_unroller.py", line 222, in _process_node
self._process_custom_unitary(node)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_unroller.py", line 111, in _process_custom_unitary
self.arg_stack[0:-1])
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_dagbackend.py", line 196, in start_gate
args)), condition)
File "/Users/liup/quantum/qiskit_dec_2017/qiskit/unroll/_dagbackend.py", line 195, in
name, qubits, [], list(map(lambda x: x.sym(nested_scope),
AttributeError: 'Prefix' object has no attribute 'sym'

Problem:

The problem lies in unroll/_dagbackend.py (line 195).
Not all node objects have the sym method.

Fix:

Changing x.sym(...) to x.real(...) solvesthe problem.

Further discussion:

I understand that you may want to keep the symbolic form in the circuit graph. But it is too aggressive to keep only the symbolic form.
Ideally, we should keep both the symbolic form and the floating point form so that it is always possible to fail back to the floating point form whenever the symbolic form is too complex to work with. (as a side note, this reminds me of the concolic execution technique, in which we keep both the symbolic variable and the concrete value of it.)

@1ucian0 1ucian0 self-assigned this Dec 11, 2017
@diego-plan9 diego-plan9 added the bug Something isn't working label Dec 12, 2017
@1ucian0
Copy link
Member

1ucian0 commented Dec 13, 2017

I was not able to reproduce this issue in the current master branch. Can you check out again?

@liupibm
Copy link
Contributor

liupibm commented Dec 21, 2017

At the time I reported the issue, _prefix.py does not have the sym() method, which caused the above error.

Since the developers have added sym() to _prefix.py, the bug is fixed and this issue can be closed.

@diego-plan9
Copy link
Member

Thanks for confirming, @liupibm!

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

No branches or pull requests

4 participants