from qiskit.circuit import QuantumCircuit
from qiskit.visualization import dag_drawer
from qiskit.converters import circuit_to_dag

# Create basic Bell circuit

qc = QuantumCircuit(2, 1)
qc.x(1)
qc.h(0)
qc.cx(0, 1)

display(qc.draw('mpl', cregbundle=False))
print(qc._data)

# Convert circuit to dag and display dag

dag = circuit_to_dag(qc)
display(dag_drawer(dag))

# Using pre-6567 branch

for node in dag.topological_nodes():
    if node.type == "op":
        print(type(node), node.type, node.op)
    else:
        print(type(node), node.type, node.wire)

# Using post-6567 branch

from qiskit.dagcircuit import DAGOpNode

for node in dag.topological_nodes():
    if isinstance(node, DAGOpNode):
        print(type(node), node.op)
    else:
        print(type(node), node.wire)

<class 'qiskit.dagcircuit.dagnode.DAGInNode'> Qubit(QuantumRegister(2, 'q'), 0)
<class 'qiskit.dagcircuit.dagnode.DAGOpNode'> <qiskit.circuit.library.standard_gates.h.HGate object at 0x7f65b6f89d30>
<class 'qiskit.dagcircuit.dagnode.DAGInNode'> Qubit(QuantumRegister(2, 'q'), 1)
<class 'qiskit.dagcircuit.dagnode.DAGOpNode'> <qiskit.circuit.library.standard_gates.x.XGate object at 0x7f65b6f89fd0>
<class 'qiskit.dagcircuit.dagnode.DAGOpNode'> <qiskit.circuit.library.standard_gates.x.CXGate object at 0x7f65b6f89400>
<class 'qiskit.dagcircuit.dagnode.DAGOutNode'> Qubit(QuantumRegister(2, 'q'), 0)
<class 'qiskit.dagcircuit.dagnode.DAGOutNode'> Qubit(QuantumRegister(2, 'q'), 1)
<class 'qiskit.dagcircuit.dagnode.DAGInNode'> Clbit(ClassicalRegister(1, 'c'), 0)
<class 'qiskit.dagcircuit.dagnode.DAGOutNode'> Clbit(ClassicalRegister(1, 'c'), 0)