qml.estimator.ops.Prod¶
- class Prod(res_ops, wires=None)[source]
Bases:
ResourceOperator
Resource class for the symbolic Prod operation.
This symbolic class can be used to represent a product of some base operations.
- Parameters:
res_ops (tuple[
ResourceOperator
]) – A tuple of resource operators or a nested tuple of resource operators and counts.wires (Sequence[int], optional) – the wires the operation acts on
- Resources:
This symbolic class represents a product of operations. The resources are defined trivially as the counts for each operation in the product.
See also
The corresponding PennyLane operation
Prod
.Example
The product of operations can be constructed from a list of operations or a nested tuple where each operator is accompanied by its count. Each operation in the product must be a valid
ResourceOperator
.We can construct a product operator as follows:
>>> import pennylane.estimator as qre >>> factors = [qre.X(), qre.Y(), qre.Z()] >>> prod_xyz = qre.Prod(factors) >>> >>> print(qre.estimate(prod_xyz)) --- Resources: --- Total wires: 1 algorithmic wires: 1 allocated wires: 0 zero state: 0 any state: 0 Total gates : 3 'X': 1, 'Y': 1, 'Z': 1
We can also specify the factors as a tuple with
>>> factors = [(qre.X(), 2), (qre.Z(), 3)] >>> prod_x2z3 = qre.Prod(factors) >>> >>> print(qre.estimate(prod_x2z3)) --- Resources: --- Total wires: 1 algorithmic wires: 1 allocated wires: 0 zero state: 0 any state: 0 Total gates : 5 'X': 2, 'Z': 3
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- resource_keys = {'cmpr_factors_and_counts', 'num_wires'}¶
- resource_params¶
Returns a dictionary containing the minimal information needed to compute the resources.
- Returns:
- A dictionary containing the resource parameters:
num_wires (int): the number of wires the operator acts upon
cmpr_factors_and_counts (Tuple[Tuple[
CompressedResourceOp
, int]]): A sequence of tuples containing the operations, in the compressed representation, and a count for how many times they are repeated corresponding to the factors in the product.
- Return type:
dict
Methods
resource_decomp
(cmpr_factors_and_counts, ...)Returns a list representing the resources of the operator.
resource_rep
(cmpr_factors_and_counts[, ...])Returns a compressed representation containing only the parameters of the operator that are needed to compute a resource estimation.
- classmethod resource_decomp(cmpr_factors_and_counts, num_wires)[source]¶
Returns a list representing the resources of the operator. Each object represents a quantum gate and the number of times it occurs in the decomposition.
- Parameters:
cmpr_factors_and_counts (Tuple[Tuple[
CompressedResourceOp
, int]]) – A sequence of tuples containing the operations, in the compressed representation, and a count for how many times they are repeated corresponding to the factors in the product.num_wires (int) – the number of wires this operator acts upon
- Resources:
This symbolic class represents a product of operations. The resources are defined trivially as the counts for each operation in the product.
- Returns:
A list of
GateCount
objects, where each object represents a specific quantum gate and the number of times it appears in the decomposition.- Return type:
list[
GateCount
]
- classmethod resource_rep(cmpr_factors_and_counts, num_wires=None)[source]¶
Returns a compressed representation containing only the parameters of the operator that are needed to compute a resource estimation.
- Parameters:
cmpr_factors_and_counts (Tuple[Tuple[
CompressedResourceOp
, int]]) – A sequence of tuples containing the operations, in the compressed representation, and a count for how many times they are repeated corresponding to the factors in the product.num_wires (int) – an optional integer representing the number of wires this operator acts upon
- Returns:
the operator in a compressed representation
- Return type: