qml.estimator.ops.Controlled¶
- class Controlled(base_op, num_ctrl_wires, num_zero_ctrl, wires=None)[source]
Bases:
ResourceOperator
Resource class for the symbolic Controlled operation.
- Parameters:
base_op (
ResourceOperator
) – The base operator to be controlled.num_ctrl_wires (int) – the number of qubits the operation is controlled on
num_zero_ctrl (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state
- Resources:
The resources are determined as follows. If the base operator implements the
.controlled_resource_decomp()
method, then the resources are obtained directly from this object. Otherwise, the controlled resources are given in two steps. Firstly, any control qubits which should be triggered when in the \(|0\rangle\) state, are flipped. This corresponds to an additional cost of twoX
gates pernum_zero_ctrl
. Secondly, the base operation resources are extracted and we add to the cost the controlled variant of each operation in the resources.
See also
The corresponding PennyLane operation
Controlled
.Example
The controlled operation can be constructed like this:
>>> import pennylane.estimator as qre >>> x = qre.X() >>> cx = qre.Controlled(x, num_ctrl_wires=1, num_zero_ctrl=0) >>> ccx = qre.Controlled(x, num_ctrl_wires=2, num_zero_ctrl=2)
We can observe the expected gates when we estimate the resources.
>>> print(qre.estimate(cx)) --- Resources: --- Total wires: 2 algorithmic wires: 2 allocated wires: 0 zero state: 0 any state: 0 Total gates : 1 'CNOT': 1 >>> >>> print(qre.estimate(ccx)) --- Resources: --- Total wires: 3 algorithmic wires: 3 allocated wires: 0 zero state: 0 any state: 0 Total gates : 5 'Toffoli': 1, 'X': 4
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- resource_keys = {'base_cmpr_op', 'num_ctrl_wires', 'num_zero_ctrl'}¶
- resource_params¶
Returns a dictionary containing the minimal information needed to compute the resources.
- Returns:
- A dictionary containing the resource parameters:
base_cmpr_op (
CompressedResourceOp
): The base operator to be controlled.num_ctrl_wires (int): the number of qubits the operation is controlled on
num_zero_ctrl (int): the number of control qubits, that are controlled when in the \(|0\rangle\) state
- Return type:
dict
Methods
controlled_resource_decomp
(num_ctrl_wires, ...)Returns a list representing the resources for a controlled version of the operator.
resource_decomp
(base_cmpr_op, ...)Returns a list representing the resources of the operator.
resource_rep
(base_cmpr_op, num_ctrl_wires, ...)Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.
tracking_name
(base_cmpr_op, num_ctrl_wires, ...)Returns the tracking name built with the operator's parameters.
- classmethod controlled_resource_decomp(num_ctrl_wires, num_zero_ctrl, target_resource_params)[source]¶
Returns a list representing the resources for a controlled version of the operator.
- Parameters:
num_ctrl_wires (int) – The number of control qubits to further control the base controlled operation upon.
num_zero_ctrl (int) – The subset of those control qubits which further control the base controlled operation, which are controlled when in the \(|0\rangle\) state.
target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.
- Resources:
The resources are derived by simply combining the control qubits, control-values and work qubits into a single instance of
Controlled
gate, controlled on the whole set of control-qubits.
- 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_decomp(base_cmpr_op, num_ctrl_wires, num_zero_ctrl, **kwargs)[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:
base_cmpr_op (
CompressedResourceOp
) – The base operator to be controlled.num_ctrl_wires (int) – the number of qubits the operation is controlled on
num_zero_ctrl (int) – the number of control qubits that are controlled when in the \(|0\rangle\) state
- Resources:
The resources are determined as follows. If the base operator implements the
.controlled_resource_decomp()
method, then the resources are obtained directly from this method. Otherwise, the controlled resources are given in two steps. Firstly, any control qubits which should be triggered when in the \(|0\rangle\) state, are flipped. This corresponds to an additional cost of twoX
gates pernum_zero_ctrl
. Secondly, the base operation resources are extracted and we add to the cost the controlled variant of each operation in the resources.
- 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(base_cmpr_op, num_ctrl_wires, num_zero_ctrl)[source]¶
Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.
- Parameters:
base_cmpr_op (
CompressedResourceOp
) – The base operator to be controlled.num_ctrl_wires (int) – the number of qubits the operation is controlled on
num_zero_ctrl (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state
- Returns:
the operator in a compressed representation
- Return type: