qml.s_prod¶
- s_prod(scalar, operator, lazy=True, id=None)[source]¶
Construct an operator which is the scalar product of the given scalar and operator provided.
- Parameters
scalar (float or complex) – the scale factor being multiplied to the operator.
operator (Operator) – the operator which will get scaled.
- Keyword Arguments
lazy=True (bool) – If
lazy=False
and the operator is already a scalar product operator, the scalar provided will simply be combined with the existing scaling factor.id (str or None) – id for the scalar product operator. Default is None.
- Returns
The operator representing the scalar product.
- Return type
Note
This operator supports a batched base, a batched coefficient and a combination of both:
>>> op = qml.s_prod(scalar=4, operator=qml.RX([1, 2, 3], wires=0)) >>> qml.matrix(op).shape (3, 2, 2) >>> op = qml.s_prod(scalar=[1, 2, 3], operator=qml.RX(1, wires=0)) >>> qml.matrix(op).shape (3, 2, 2) >>> op = qml.s_prod(scalar=[4, 5, 6], operator=qml.RX([1, 2, 3], wires=0)) >>> qml.matrix(op).shape (3, 2, 2)
But it doesn’t support batching of operators:
>>> op = qml.s_prod(scalar=4, operator=[qml.RX(1, wires=0), qml.RX(2, wires=0)]) AttributeError: 'list' object has no attribute 'batch_size'
See also
SProd
andSymbolicOp
Example
>>> sprod_op = s_prod(2.0, qml.X(0)) >>> sprod_op 2.0 * X(0) >>> sprod_op.matrix() array([[ 0., 2.], [ 2., 0.]])
code/api/pennylane.s_prod
Download Python script
Download Notebook
View on GitHub