qml.template¶
-
template
(func)[source]¶ Register a quantum template with PennyLane.
This decorator wraps the given function and makes it return a list of all queued Operations.
Example:
When defining a template, simply decorate the template function with this decorator.
@qml.template def bell_state_preparation(wires): qml.Hadamard(wires=wires[0]) qml.CNOT(wires=wires)
This registers the template with PennyLane, making it compatible with functions that act on templates, such as
pennylane.inv()
:dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(): qml.inv(bell_state_preparation(wires=[0, 1])) return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
- Parameters
func (callable) – A template function
- Returns
The wrapper function
- Return type
callable
Contents
Using PennyLane
Development
API
Downloads