qml.transforms.qcut.place_wire_cuts¶
-
place_wire_cuts
(graph, cut_edges)[source]¶ Inserts a
WireCut
node for each provided cut edge into a circuit graph.- Parameters
- Returns
Copy of the input graph with
WireCut
nodes inserted.- Return type
MultiDiGraph
Example
Consider the following 2-wire circuit with one CNOT gate connecting the wires:
ops = [ qml.RX(0.432, wires=0), qml.RY(0.543, wires="a"), qml.CNOT(wires=[0, "a"]), ] measurements = [qml.expval(qml.PauliZ(wires=[0]))] tape = qml.tape.QuantumTape(ops, measurements)
>>> print(qml.drawer.tape_text(tape)) 0: ──RX(0.432)──╭●──┤ ⟨Z⟩ a: ──RY(0.543)──╰X──┤
If we know we want to place a
WireCut
node between the nodes corresponding to theRY(0.543, wires=["a"])
andCNOT(wires=[0, 'a'])
operations after the tape is constructed, we can first find the edge in the graph:>>> graph = qml.transforms.qcut.tape_to_graph(tape) >>> op0, op1 = tape.operations[1], tape.operations[2] >>> cut_edges = [e for e in graph.edges if e[0] is op0 and e[1] is op1] >>> cut_edges [(RY(0.543, wires=['a']), CNOT(wires=[0, 'a']), 0)]
Then feed it to this function for placement:
>>> cut_graph = qml.transforms.qcut.place_wire_cuts(graph=graph, cut_edges=cut_edges) >>> cut_graph <networkx.classes.multidigraph.MultiDiGraph at 0x7f7251ac1220>
And visualize the cut by converting back to a tape:
>>> print(qml.transforms.qcut.graph_to_tape(cut_graph).draw()) 0: ──RX(0.432)──────╭●──┤ ⟨Z⟩ a: ──RY(0.543)──//──╰X──┤
code/api/pennylane.transforms.qcut.place_wire_cuts
Download Python script
Download Notebook
View on GitHub