prod(*ops, id=None, lazy=True)¶
Construct an operator which represents the generalized product of the operators provided.
The generalized product operation represents both the tensor product as well as matrix composition. This can be resolved naturally from the wires that the given operators act on.
*ops (Union[tuple[Operator], Callable]) – The operators we would like to multiply. Alternatively, a single qfunc that queues operators can be passed to this function.
- Keyword Arguments
id (str or None) – id for the product operator. Default is None.
lazy=True (bool) – If
lazy=False, a simplification will be performed such that when any of the operators is already a product operator, its operands will be used instead.
the operator representing the product.
- Return type
This operator supports batched operands:
>>> op = qml.prod(qml.RX(np.array([1, 2, 3]), wires=0), qml.PauliX(1)) >>> op.matrix().shape (3, 4, 4)
But it doesn’t support batching of operators:
>>> op = qml.prod(np.array([qml.RX(0.5, 0), qml.RZ(0.3, 0)]), qml.PauliZ(0)) AttributeError: 'numpy.ndarray' object has no attribute 'wires'
>>> prod_op = prod(qml.PauliX(0), qml.PauliZ(0)) >>> prod_op PauliX(wires=) @ PauliZ(wires=) >>> prod_op.matrix() array([[ 0, -1], [ 1, 0]])
You can also create a prod operator by passing a qfunc to prod, like the following:
>>> def qfunc(x): ... qml.RX(x, 0) ... qml.CNOT([0, 1]) >>> prod_op = prod(qfunc)(1.1) >>> prod_op CNOT(wires=[0, 1]) @ RX(1.1, wires=)
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry
- Quantum Datasets
- QNode returns