graph_to_tape(graph: networkx.classes.multidigraph.MultiDiGraph) → pennylane.tape.tape.QuantumTape¶
Converts a directed multigraph to the corresponding
To account for the possibility of needing to perform mid-circuit measurements, if any operations follow a
MeasureNodeoperation on a given wire then these operations are mapped to a new wire.
This function 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 to be converted to a tape
the quantum tape corresponding to the input graph
- Return type
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
2instead of wire
>>> 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─────────────────╰●─┤
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry