qml.qcut.graph_to_tape¶
- graph_to_tape(graph)[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
Example
Consider the following circuit:
ops = [ qml.RX(0.4, wires=0), qml.RY(0.5, wires=1), qml.CNOT(wires=[0, 1]), qml.qcut.MeasureNode(wires=1), qml.qcut.PrepareNode(wires=1), qml.CNOT(wires=[1, 0]), ] measurements = [qml.expval(qml.Z(0))] tape = qml.tape.QuantumTape(ops, measurements)
This circuit contains operations that follow a
MeasureNode
. These operations will subsequently act on wire2
instead of wire1
:>>> graph = qml.qcut.tape_to_graph(tape) >>> tape = qml.qcut.graph_to_tape(graph) >>> print(tape.draw()) 0: ──RX──────────╭●──────────────╭X─┤ <Z> 1: ──RY──────────╰X──MeasureNode─│──┤ 2: ──PrepareNode─────────────────╰●─┤
code/api/pennylane.qcut.graph_to_tape
Download Python script
Download Notebook
View on GitHub