DAGDependency

class DAGDependency[source]

Object to represent a quantum circuit as a directed acyclic graph via operation dependencies (i.e. lack of commutation).

The nodes in the graph are operations represented by quantum gates. The edges correspond to non-commutation between two operations (i.e. a dependency). A directed edge from node A to node B means that operation A does not commute with operation B. The object’s methods allow circuits to be constructed.

The nodes in the graph have the following attributes: ‘operation’, ‘successors’, ‘predecessors’.

Example:

Bell circuit with no measurement.

      ┌───┐
qr_0: ┤ H ├──■──
      └───┘┌─┴─┐
qr_1: ─────┤ X ├
           └───┘

The dependency DAG for the above circuit is represented by two nodes. The first one corresponds to Hadamard gate, the second one to the CNOT gate as the gates do not commute there is an edge between the two nodes.

Reference:

[1] Iten, R., Sutter, D. and Woerner, S., 2019. Efficient template matching in quantum circuits. arXiv:1909.05270

Create an empty DAGDependency.

Methods

DAGDependency.add_creg(creg)

Add clbits in a classical register.

DAGDependency.add_op_node(operation, qargs, …)

Add a DAGDepNode to the graph and update the edges.

DAGDependency.add_qreg(qreg)

Add qubits in a quantum register.

DAGDependency.copy()

Function to copy a DAGDependency object.

DAGDependency.depth()

Return the circuit depth.

DAGDependency.direct_predecessors(node_id)

Direct predecessors id of a given node as sorted list.

DAGDependency.direct_successors(node_id)

Direct successors id of a given node as sorted list.

DAGDependency.draw([scale, filename, style])

Draws the DAGDependency graph.

DAGDependency.get_all_edges()

Enumaration of all edges.

DAGDependency.get_edges(src_id, dest_id)

Edge enumeration between two nodes through method get_all_edge_data.

DAGDependency.get_in_edges(node_id)

Enumeration of all incoming edges for a given node.

DAGDependency.get_node(node_id)

param node_id

label of considered node.

DAGDependency.get_nodes()

returns

iterator over all the nodes.

DAGDependency.get_out_edges(node_id)

Enumeration of all outgoing edges for a given node.

DAGDependency.predecessors(node_id)

Predecessors id of a given node as sorted list.

DAGDependency.size()

Returns the number of gates in the circuit

DAGDependency.successors(node_id)

Successors id of a given node as sorted list.

DAGDependency.to_networkx()

Returns a copy of the DAGDependency in networkx format.

DAGDependency.to_retworkx()

Returns the DAGDependency in retworkx format.

DAGDependency.topological_nodes()

Yield nodes in topological order.