Skip to content

Unroller raises unclear error when reaching a node without a definition #5840

@Cryoris

Description

@Cryoris

Information

  • Qiskit Terra version: master @ 06dd155
  • Python version: 3.7.9
  • Operating system: macOS Big Sur

What is the current behavior?

Using the Unroller to unroll a circuit can fail, while using transpile with optimization_level=0 works fine.

Steps to reproduce the problem

from qiskit import transpile
from qiskit.circuit.library import ZGate
from qiskit.transpiler.passes import Unroller

basis = ['u1', 'u2', 'u3', 'cx']
unroller = Unroller(basis)

circuit = ZGate().control().definition  # circuit with CZ gate
unroller(circuit)  # works

circuit = ZGate().control(2).definition  # circuit with CCZ gate
unroller(circuit)  # error, see traceback below
transpile(circuit, basis_gates=basis, optimization_level=0)  # works

The error in the unroller is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/Qiskit/qiskit-terra/qiskit/transpiler/passes/basis/unroller.py in run(self, dag)
     82                 try:
---> 83                     rule = rule[0][0].definition.data
     84                 except (TypeError, AttributeError) as err:

AttributeError: 'NoneType' object has no attribute 'data'

During handling of the above exception, another exception occurred:

QiskitError                               Traceback (most recent call last)
<ipython-input-17-c2529f65b3ed> in <module>
----> 1 Unroller(ubasis)(ZGate().control(2).definition)

~/Qiskit/qiskit-terra/qiskit/transpiler/basepasses.py in __call__(self, circuit, property_set)
    118             self.property_set = property_set_
    119
--> 120         result = self.run(circuit_to_dag(circuit))
    121
    122         result_circuit = circuit

~/Qiskit/qiskit-terra/qiskit/transpiler/passes/basis/unroller.py in run(self, dag)
     83                     rule = rule[0][0].definition.data
     84                 except (TypeError, AttributeError) as err:
---> 85                     raise QiskitError('Error decomposing node {}: {}'.format(node.name, err))
     86
     87             else:

QiskitError: "Error decomposing node p: 'NoneType' object has no attribute 'data'"

What is the expected behavior?

The unroller should be able to unroll any circuit if the basis is sufficient.

Suggested solutions

Not sure!

Metadata

Metadata

Labels

bugSomething isn't workingdocumentationSomething is not clear or an error documentationgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions