qml.qcut.fragment_graph

fragment_graph(graph)[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.

Note

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

Parameters

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

Returns

the subgraphs of the cut graph and the communication graph.

Return type

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

Example

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])

ops = [
    qml.RX(0.4, wires=0),
    wire_cut_0,
    qml.RY(0.5, wires=0),
    wire_cut_1,
    qml.CNOT(wires=[0, 1]),
    multi_wire_cut,
    qml.RZ(0.6, wires=1),
]
measurements = [qml.expval(qml.Z(0))]
tape = qml.tape.QuantumTape(ops, measurements)

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

>>> graph = qml.qcut.tape_to_graph(tape)
>>> qml.qcut.replace_wire_cut_nodes(graph)
>>> qml.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>)