# qml.transforms.qcut.graph_to_tape¶

graph_to_tape(graph: networkx.classes.multidigraph.MultiDiGraph)pennylane.tape.tape.QuantumTape[source]

Converts a directed multigraph to the corresponding QuantumTape.

To account for the possibility of needing to perform mid-circuit measurements, if any operations follow a MeasureNode operation on a given wire then these operations are mapped to a new wire.

Note

This function 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 to be converted to a tape

Returns

the quantum tape corresponding to the input graph

Return type

QuantumTape

Example

Consider the following circuit:

with qml.tape.QuantumTape() as tape:
qml.RX(0.4, wires=0)
qml.RY(0.5, wires=1)
qml.CNOT(wires=[0, 1])
qml.transforms.qcut.MeasureNode(wires=1)
qml.transforms.qcut.PrepareNode(wires=1)
qml.CNOT(wires=[1, 0])
qml.expval(qml.PauliZ(0))


This circuit contains operations that follow a MeasureNode. These operations will subsequently act on wire 2 instead of wire 1:

>>> graph = qml.transforms.qcut.tape_to_graph(tape)
>>> tape = qml.transforms.qcut.graph_to_tape(graph)
>>> print(tape.draw())
0: ──RX──────────╭●──────────────╭X─┤  <Z>
1: ──RY──────────╰X──MeasureNode─│──┤
2: ──PrepareNode─────────────────╰●─┤