qml.transforms.remove_barrier¶
-
remove_barrier
(tape)[source]¶ Quantum function transform to remove Barrier gates.
- Parameters
qfunc (function) – A quantum function.
- Returns
the transformed quantum function
- Return type
function
Example
Consider the following quantum function:
def qfunc(x, y): qml.Hadamard(wires=0) qml.Hadamard(wires=1) qml.Barrier(wires=[0,1]) qml.PauliX(wires=0) return qml.expval(qml.PauliZ(0))
The circuit before optimization:
>>> dev = qml.device('default.qubit', wires=2) >>> qnode = qml.QNode(qfunc, dev) >>> print(qml.draw(qnode)(1, 2)) 0: ──H──╭||──X──┤ ⟨Z⟩ 1: ──H──╰||─────┤
We can remove the Barrier by running the
remove_barrier
transform:>>> optimized_qfunc = remove_barrier(qfunc) >>> optimized_qnode = qml.QNode(optimized_qfunc, dev) >>> print(qml.draw(optimized_qnode)(1, 2)) 0: ──H──X──┤ ⟨Z⟩ 1: ──H─────┤
code/api/pennylane.transforms.remove_barrier
Download Python script
Download Notebook
View on GitHub