DAGDependency#

class qiskit.dagcircuit.DAGDependency[ソース]#

ベースクラス: object

Object to represent a quantum circuit as a Directed Acyclic Graph (DAG) 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., Moyard, R., Metger, T., Sutter, D. and Woerner, S., 2020. Exact and practical pattern matching for quantum circuit optimization. arXiv:1909.05270

Create an empty DAGDependency.

Attributes

calibrations#

Return calibration dictionary.

The custom pulse definition of a given gate is of the form {'gate_name': {(qubits, params): schedule}}.

global_phase#

Return the global phase of the circuit.

Methods

add_clbits(clbits)[ソース]#

Add individual clbit wires.

add_creg(creg)[ソース]#

Add clbits in a classical register.

add_op_node(operation, qargs, cargs)[ソース]#

Add a DAGDepNode to the graph and update the edges.

パラメータ:
add_qreg(qreg)[ソース]#

Add qubits in a quantum register.

add_qubits(qubits)[ソース]#

Add individual qubit wires.

copy()[ソース]#

Function to copy a DAGDependency object. :returns: a copy of a DAGDependency object. :rtype: DAGDependency

depth()[ソース]#

Return the circuit depth. :returns: the circuit depth :rtype: int

direct_predecessors(node_id)[ソース]#

Direct predecessors id of a given node as sorted list.

パラメータ:

node_id (int) – label of considered node.

戻り値:

direct predecessors id as a sorted list

戻り値の型:

List

direct_successors(node_id)[ソース]#

Direct successors id of a given node as sorted list.

パラメータ:

node_id (int) – label of considered node.

戻り値:

direct successors id as a sorted list

戻り値の型:

List

draw(scale=0.7, filename=None, style='color')[ソース]#

Draws the DAGDependency graph.

This function needs pydot <https://github.com/erocarrera/pydot>, which in turn needs Graphviz <https://www.graphviz.org/>` to be installed.

パラメータ:
  • scale (float) – scaling factor

  • filename (str) – file path to save image to (format inferred from name)

  • style (str) – 『plain』: B&W graph 『color』 (default): color input/output/op nodes

戻り値:

if in Jupyter notebook and not saving to file, otherwise None.

戻り値の型:

Ipython.display.Image

get_all_edges()[ソース]#

Enumeration of all edges.

戻り値:

corresponding to the label.

戻り値の型:

List

get_edges(src_id, dest_id)[ソース]#

Edge enumeration between two nodes through method get_all_edge_data.

パラメータ:
  • src_id (int) – label of the first node.

  • dest_id (int) – label of the second node.

戻り値:

corresponding to all edges between the two nodes.

戻り値の型:

List

get_in_edges(node_id)[ソース]#

Enumeration of all incoming edges for a given node.

パラメータ:

node_id (int) – label of considered node.

戻り値:

corresponding incoming edges data.

戻り値の型:

List

get_node(node_id)[ソース]#
パラメータ:

node_id (int) – label of considered node.

戻り値:

corresponding to the label.

戻り値の型:

node

get_nodes()[ソース]#
戻り値:

iterator over all the nodes.

戻り値の型:

generator(dict)

get_out_edges(node_id)[ソース]#

Enumeration of all outgoing edges for a given node.

パラメータ:

node_id (int) – label of considered node.

戻り値:

corresponding outgoing edges data.

戻り値の型:

List

predecessors(node_id)[ソース]#

Predecessors id of a given node as sorted list.

パラメータ:

node_id (int) – label of considered node.

戻り値:

all predecessors id as a sorted list

戻り値の型:

List

replace_block_with_op(node_block, op, wire_pos_map, cycle_check=True)[ソース]#

Replace a block of nodes with a single node.

This is used to consolidate a block of DAGDepNodes into a single operation. A typical example is a block of CX and SWAP gates consolidated into a LinearFunction. This function is an adaptation of a similar function from DAGCircuit.

It is important that such consolidation preserves commutativity assumptions present in DAGDependency. As an example, suppose that every node in a block [A, B, C, D] commutes with another node E. Let F be the consolidated node, F = A o B o C o D. Then F also commutes with E, and thus the result of replacing [A, B, C, D] by F results in a valid DAGDependency. That is, any deduction about commutativity in consolidated DAGDependency is correct. On the other hand, suppose that at least one of the nodes, say B, does not commute with E. Then the consolidated DAGDependency would imply that F does not commute with E. Even though F and E may actually commute, it is still safe to assume that they do not. That is, the current implementation of consolidation may lead to suboptimal but not to incorrect results.

パラメータ:
  • node_block (List[DAGDepNode]) – A list of dag nodes that represents the node block to be replaced

  • op (qiskit.circuit.Operation) – The operation to replace the block with

  • wire_pos_map (Dict[Qubit, int]) – The dictionary mapping the qarg to the position. This is necessary to reconstruct the qarg order over multiple gates in the combined single op node.

  • cycle_check (bool) – When set to True this method will check that replacing the provided node_block with a single node would introduce a cycle (which would invalidate the DAGDependency) and will raise a DAGDependencyError if a cycle would be introduced. This checking comes with a run time penalty. If you can guarantee that your input node_block is a contiguous block and won’t introduce a cycle when it’s contracted to a single node, this can be set to False to improve the runtime performance of this method.

例外:

DAGDependencyError – if cycle_check is set to True and replacing the specified block introduces a cycle or if node_block is empty.

size()[ソース]#

Returns the number of gates in the circuit

successors(node_id)[ソース]#

Successors id of a given node as sorted list.

パラメータ:

node_id (int) – label of considered node.

戻り値:

all successors id as a sorted list

戻り値の型:

List

to_retworkx()[ソース]#

Returns the DAGDependency in retworkx format.

topological_nodes()[ソース]#

Yield nodes in topological order.

戻り値:

node in topological order.

戻り値の型:

generator(DAGNode)