# DAGCircuit¶

class DAGCircuit[source]

Quantum circuit as a directed acyclic graph.

There are 3 types of nodes in the graph: inputs, outputs, and operations. The nodes are connected by directed edges that correspond to qubits and bits.

Create an empty circuit.

Attributes

 DAGCircuit.clbits Return a list of classical bits (as a list of Clbit instances). DAGCircuit.node_counter Returns the number of nodes in the dag. DAGCircuit.qubits Return a list of qubits (as a list of Qubit instances). DAGCircuit.wires Return a list of the wires in order.

Methods

 Add all wires in a classical register. Add all wires in a quantum register. Returns set of the ancestors of a node as DAGNodes. DAGCircuit.apply_operation_back(op[, qargs, …]) Apply an operation to the output of the circuit. DAGCircuit.apply_operation_front(op, qargs, …) Apply an operation to the input of the circuit. Returns an iterator of tuples of (DAGNode, [DAGNodes]) where the DAGNode is the current node and [DAGNode] is its successors in BFS order. DAGCircuit.collect_runs(namelist) Return a set of non-conditional runs of “op” nodes with the given names. DAGCircuit.compose(other[, edge_map, …]) Compose the other circuit onto the output of this circuit. DAGCircuit.compose_back(input_circuit[, …]) DEPRECATED: use DAGCircuit.compose() instead. Count the occurrences of operation names. Count the occurrences of operation names on the longest path. Return the circuit depth. Returns set of the descendants of a node as DAGNodes. DAGCircuit.draw([scale, filename, style]) Draws the dag circuit. DAGCircuit.edges([nodes]) Iterator for node values. DAGCircuit.extend_back(dag[, edge_map]) DEPRECATED: Add dag at the end of self, using edge_map. Get the list of gate nodes in the dag. DAGCircuit.idle_wires([ignore]) Return idle wires. Yield a shallow view on a layer of this DAGCircuit for all d layers of this circuit. Returns the longest path in the dag as a list of DAGNodes. Get list of 3+ qubit operations. Yield layers of the multigraph. DAGCircuit.named_nodes(*names) Get the set of “op” nodes with the given name. DAGCircuit.node(node_id) Get the node in the dag. Iterator for node values. DAGCircuit.nodes_on_wire(wire[, only_ops]) Iterator for nodes that affect a given wire. Return the total number of classical bits used by the circuit. Return the total number of qubits used by the circuit. Compute how many components the circuit can decompose into. DAGCircuit.op_nodes([op, include_directives]) Get the list of “op” nodes in the dag. Returns iterator of the predecessors of a node as DAGNodes. Return a dictionary of circuit properties. Returns iterator of the predecessors of a node that are connected by a quantum edge as DAGNodes. Returns iterator of the successors of a node that are connected by a quantum edge as DAGNodes. Remove all operation nodes with the given name. Remove all of the ancestor operation nodes of node. Remove all of the descendant operation nodes of node. Remove all of the non-ancestors operation nodes of node. Remove all of the non-descendants operation nodes of node. Remove an operation node n. Yield a layer for all gates of this circuit. Return the number of operations. DAGCircuit.substitute_node(node, op[, inplace]) Replace a DAGNode with a single instruction. Replace one node with dag. Returns iterator of the successors of a node as DAGNodes. Get list of 3-or-more-qubit gates: (id, data). Returns a copy of the DAGCircuit in networkx format. Yield nodes in topological order. Yield op nodes in topological order. Get list of 2-qubit gates. Get list of 2 qubit operations. Return the total number of qubits + clbits used by the circuit.