qml.transforms.remove_barrier¶
- remove_barrier(tape)[source]¶
Quantum transform to remove Barrier gates.
- Parameters
tape (QNode or QuantumTape or Callable) – A quantum circuit.
- Returns
The transformed circuit as described in
qml.transform
.- Return type
qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]
Example
The transform can be applied on
QNode
directly.@remove_barrier @qml.qnode(device=dev) def circuit(x, y): qml.Hadamard(wires=0) qml.Hadamard(wires=1) qml.Barrier(wires=[0,1]) qml.X(0) return qml.expval(qml.Z(0))
The barrier is then removed before execution.
Usage Details
Consider the following quantum function:
def qfunc(x, y): qml.Hadamard(wires=0) qml.Hadamard(wires=1) qml.Barrier(wires=[0,1]) qml.X(0) return qml.expval(qml.Z(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