qml.labs.resource_estimation.ResourceControlled

class ResourceControlled(base_op, num_ctrl_wires, num_ctrl_values, wires=None)[source]

Bases: ResourceOperator

Resource class for the symbolic Controlled operation.

A symbolic class used to represent the application of some base operation controlled on the state of some control qubits.

Parameters:
  • base_op (ResourceOperator) – The base operator to be controlled.

  • num_ctrl_wires (int) – the number of qubits the operation is controlled on

  • num_ctrl_values (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.

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 two ResourceX gates per num_ctrl_values. Secondly, the base operation resources are extracted and we add to the cost the controlled variant of each operation in the resources.

See also

ControlledOp

Example

The controlled operation can be constructed like this:

>>> x = plre.ResourceX()
>>> cx = plre.ResourceControlled(x, num_ctrl_wires=1, num_ctrl_values=0)
>>> ccx = plre.ResourceControlled(x, num_ctrl_wires=2, num_ctrl_values=2)

We can observe the expected gates when we estimate the resources.

>>> print(plre.estimate_resources(cx))
--- Resources: ---
Total qubits: 2
Total gates : 1
Qubit breakdown:
clean qubits: 0, dirty qubits: 0, algorithmic qubits: 2
Gate breakdown:
{'CNOT': 1}
>>>
>>> print(plre.estimate_resources(ccx))
--- Resources: ---
Total qubits: 3
Total gates : 5
Qubit breakdown:
clean qubits: 0, dirty qubits: 0, algorithmic qubits: 3
Gate breakdown:
{'X': 4, 'Toffoli': 1}

num_wires

resource_keys

resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

num_wires = 0
resource_keys = {'base_cmpr_op', 'num_ctrl_values', 'num_ctrl_wires'}
resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

Returns:

A dictionary containing the resource parameters: * base_cmpr_op (~.pennylane.labs.resource_estimation.CompressedResourceOp): The base operator to be controlled. * num_ctrl_wires (int): the number of qubits the operation is controlled on * num_ctrl_values (int): the number of control qubits, that are controlled when in the \(|0\rangle\) state

Return type:

dict

adjoint_resource_decomp(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

controlled_resource_decomp(...)

Returns a list representing the resources for a controlled version of the operator.

default_adjoint_resource_decomp(*args, **kwargs)

Returns a list representing the resources for the adjoint of the operator.

default_controlled_resource_decomp(...)

Returns a list representing the resources for a controlled version of the operator.

default_pow_resource_decomp(pow_z, *args, ...)

Returns a list representing the resources for an operator raised to a power.

default_resource_decomp(base_cmpr_op, ...)

Returns a list representing the resources of the operator.

pow_resource_decomp(pow_z, *args, **kwargs)

Returns a list representing the resources for an operator raised to a power.

queue(remove_base_op[, context])

Append the operator to the Operator queue.

resource_decomp(*args, **kwargs)

Returns a list of actions that define 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.

resource_rep_from_op()

Returns a compressed representation directly from the operator

set_resources(new_func[, override_type])

Set a custom function to override the default resource decomposition.

tracking_name(base_cmpr_op, num_ctrl_wires, ...)

Returns the tracking name built with the operator's parameters.

tracking_name_from_op()

Returns the tracking name built with the operator's parameters.

classmethod adjoint_resource_decomp(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

classmethod controlled_resource_decomp(ctrl_num_ctrl_wires, ctrl_num_ctrl_values, *args, **kwargs)

Returns a list representing the resources for a controlled version of the operator.

Parameters:
  • ctrl_num_ctrl_wires (int) – the number of qubits the operation is controlled on

  • ctrl_num_ctrl_values (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state

classmethod default_adjoint_resource_decomp(*args, **kwargs)

Returns a list representing the resources for the adjoint of the operator.

classmethod default_controlled_resource_decomp(ctrl_num_ctrl_wires, ctrl_num_ctrl_values, base_cmpr_op, num_ctrl_wires, num_ctrl_values)[source]

Returns a list representing the resources for a controlled version of the operator.

Parameters:
  • ctrl_num_ctrl_wires (int) – The number of control qubits to further control the base controlled operation upon.

  • ctrl_num_ctrl_values (int) – The subset of those control qubits, which further control the base controlled operation, which are controlled when in the \(|0\rangle\) state.

  • base_cmpr_op (CompressedResourceOp) – The base operator to be controlled.

  • num_ctrl_wires (int) – the number of control qubits of the operation

  • num_ctrl_values (int) – The subset of control qubits of the operation, that are controlled when in the \(|0\rangle\) state.

Resources:

The resources are derived by simply combining the control qubits, control-values and work qubits into a single instance of ResourceControlled 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 default_pow_resource_decomp(pow_z, *args, **kwargs)

Returns a list representing the resources for an operator raised to a power.

Parameters:

pow_z (int) – exponent that the operator is being raised to

classmethod default_resource_decomp(base_cmpr_op, num_ctrl_wires, num_ctrl_values, **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_ctrl_values (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.

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 two ResourceX gates per num_ctrl_values. 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]

See also

ControlledOp

Example

The controlled operation can be constructed like this:

>>> x = plre.ResourceX()
>>> cx = plre.ResourceControlled(x, num_ctrl_wires=1, num_ctrl_values=0)
>>> ccx = plre.ResourceControlled(x, num_ctrl_wires=2, num_ctrl_values=2)

We can observe the expected gates when we estimate the resources.

>>> print(plre.estimate_resources(cx))
--- Resources: ---
Total qubits: 2
Total gates : 1
Qubit breakdown:
clean qubits: 0, dirty qubits: 0, algorithmic qubits: 2
Gate breakdown:
{'CNOT': 1}
>>>
>>> print(plre.estimate_resources(ccx))
--- Resources: ---
Total qubits: 3
Total gates : 5
Qubit breakdown:
clean qubits: 0, dirty qubits: 0, algorithmic qubits: 3
Gate breakdown:
{'X': 4, 'Toffoli': 1}
classmethod pow_resource_decomp(pow_z, *args, **kwargs)

Returns a list representing the resources for an operator raised to a power.

Parameters:

pow_z (int) – exponent that the operator is being raised to

queue(remove_base_op, context=<class 'pennylane.queuing.QueuingManager'>)[source]

Append the operator to the Operator queue.

classmethod resource_decomp(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

classmethod resource_rep(base_cmpr_op, num_ctrl_wires, num_ctrl_values)[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_ctrl_values (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

resource_rep_from_op()

Returns a compressed representation directly from the operator

classmethod set_resources(new_func, override_type='base')

Set a custom function to override the default resource decomposition.

This method allows users to replace any of the resource_decomp, adjoint_resource_decomp, ctrl_resource_decomp, or pow_resource_decomp methods globally for every instance of the class.

static tracking_name(base_cmpr_op, num_ctrl_wires, num_ctrl_values)[source]

Returns the tracking name built with the operator’s parameters.

tracking_name_from_op()

Returns the tracking name built with the operator’s parameters.