# How does one get the attributes of a circuit from its DAG in qiskit?

I have the following code, which runs properly.

from qiskit import *
from qiskit.converters import *

ghz2 = QuantumCircuit(5, 5)
ghz2.h(2)
ghz2.cx(2, 1)
ghz2.cx(1, 0)
ghz2.cx(2, 3)
ghz2.cx(3, 4)

ghz_dag = circuit_to_dag(ghz2)


How do I access properties of this dag? For instance, I would like to get all the 2-qubit gates using the collect 2qubit gates method (the output is supposed to be a dictionary) or simply draw the DAG but again, dag_drawer(ghz_dag) throws up an error ('MultiDiGraph' object has no attribute 'number_of_selfloops') even though, that's done in an example here.

Maybe this is just a Python usage question but how does one access the properties of the DAG?

• Hi, which versions of qiskit are you running? I am unable to recreate this – met927 Nov 18 at 11:53
• @met927 if I type conda list, I see 0.13.0 under the version for qiskit. I am running the commands from the question in the Spyder IPython console after restarting the kernel. – user1936752 Nov 18 at 12:02
• Ah ok, that is good. Which version of networkx are you running? – met927 Nov 18 at 13:24
• @met927 I'm using 2.4. Just to add, it's not only the specific dag_drawer that I'm having trouble with - it'd be good to know generally how to access these various properties of the dag. Thank you – user1936752 Nov 18 at 14:06

Properties of the DAG are simply accessed using dot notation. For example, if you would like to get all the two qubit gates you would do dag.twoQ_gates() which returns a list of the two qubit gates present in the dag.
The code you have linked to is a transpiler pass. This is a method that looks over the dag to identify some property or to perform some optimization. It stores variables to the property set, self.property_set. There is more information about using the transpiler here.
• This is a list, of type DAGNode. From the DAGNodes you can read all the properties of the node, for example node.op will get you the operation that corresponds to this node. You can see the whole class here – met927 Nov 18 at 18:14