Converts a graph from PyZX to a PennyLane tape, if the graph is diagram-like.
graph (Graph) – ZX graph in PyZX.
decompose_phases (bool) – If True the phases are decomposed, meaning that
qml.RX()are simplified into other gates (e.g.
From the example for the
to_zx()function, one can convert back the PyZX graph to a PennyLane by using the function
import pyzx dev = qml.device('default.qubit', wires=2) @qml.transforms.to_zx def circuit(p): qml.RZ(p, wires=0), qml.RZ(p, wires=0), qml.RX(p, wires=1), qml.PauliZ(wires=1), qml.RZ(p, wires=0), qml.PauliX(wires=0), qml.CNOT(wires=[1, 0]), qml.CNOT(wires=[0, 1]), qml.SWAP(wires=[1, 0]), return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1)) params = [5 / 4 * np.pi, 3 / 4 * np.pi, 0.1, 0.3] g = circuit(params) pennylane_tape = qml.transforms.from_zx(g)
You can check that the operations are similar but some were decomposed in the process.
>>> pennylane_tape.operations [PauliZ(wires=), T(wires=), RX(0.1, wires=), PauliZ(wires=), Adjoint(T(wires=)), PauliZ(wires=), RZ(0.3, wires=), PauliX(wires=), CNOT(wires=[1, 0]), CNOT(wires=[0, 1]), CNOT(wires=[1, 0]), CNOT(wires=[0, 1]), CNOT(wires=[1, 0])]
Be careful because not all graphs are circuit-like, so the process might not be successful after you apply some optimization on your PyZX graph. You can extract a circuit by using the dedicated PyZX function.
It is a PennyLane adapted and reworked graph_to_circuit function.
Copyright (C) 2018 - Aleks Kissinger and John van de Wetering
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry
- Quantum Datasets