fragment_graph(graph: networkx.classes.multidigraph.MultiDiGraph)Tuple[Tuple[networkx.classes.multidigraph.MultiDiGraph], networkx.classes.multidigraph.MultiDiGraph][source]

Fragments a graph into a collection of subgraphs as well as returning the communication (quotient) graph.

The input graph is fragmented by disconnecting each MeasureNode and PrepareNode pair and finding the resultant disconnected subgraph fragments. Each node of the communication graph represents a subgraph fragment and the edges denote the flow of qubits between fragments due to the removed MeasureNode and PrepareNode pairs.


This operation is designed for use as part of the circuit cutting workflow. Check out the qml.cut_circuit() transform for more details.


graph (nx.MultiDiGraph) – directed multigraph containing measure and prepare nodes at cut locations


the subgraphs of the cut graph and the communication graph.

Return type

Tuple[Tuple[nx.MultiDiGraph], nx.MultiDiGraph]


Consider the following circuit with manually-placed wire cuts:

wire_cut_0 = qml.WireCut(wires=0)
wire_cut_1 = qml.WireCut(wires=1)
multi_wire_cut = qml.WireCut(wires=[0, 1])

with qml.tape.QuantumTape() as tape:
    qml.RX(0.4, wires=0)
    qml.RY(0.5, wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RZ(0.6, wires=1)

We can find the corresponding graph, remove all the wire cut nodes, and find the subgraphs and communication graph by using:

>>> graph = qml.transforms.qcut.tape_to_graph(tape)
>>> qml.transforms.qcut.replace_wire_cut_nodes(graph)
>>> qml.transforms.qcut.fragment_graph(graph)
((<networkx.classes.multidigraph.MultiDiGraph object at 0x7fb3b2311940>,
  <networkx.classes.multidigraph.MultiDiGraph object at 0x7fb3b2311c10>,
  <networkx.classes.multidigraph.MultiDiGraph object at 0x7fb3b23e2820>,
  <networkx.classes.multidigraph.MultiDiGraph object at 0x7fb3b23e27f0>),
 <networkx.classes.multidigraph.MultiDiGraph object at 0x7fb3b23e26a0>)