qp.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
qp.transform.- Return type:
qnode (QNode) or quantum function (Callable) or tuple[List[.QuantumTape], function]
Example
The transform can be applied on
QNodedirectly.@remove_barrier @qp.qnode(qp.device('default.qubit')) def circuit(x, y): qp.Hadamard(wires=0) qp.Hadamard(wires=1) qp.Barrier(wires=[0,1]) qp.X(0) return qp.expval(qp.Z(0))
The barrier is then removed before execution.
Usage Details
Consider the following quantum function:
def qfunc(x, y): qp.Hadamard(wires=0) qp.Hadamard(wires=1) qp.Barrier(wires=[0,1]) qp.X(0) return qp.expval(qp.Z(0))
The circuit before optimization:
>>> dev = qp.device('default.qubit') >>> qnode = qp.QNode(qfunc, dev) >>> print(qp.draw(qnode)(1, 2)) 0: ──H─╭||──X─┤ <Z> 1: ──H─╰||────┤
We can remove the Barrier by running the
remove_barriertransform:>>> optimized_qfunc = remove_barrier(qfunc) >>> optimized_qnode = qp.QNode(optimized_qfunc, dev) >>> print(qp.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