qp.labs.estimator_beta.templates.OutOfPlaceIntegerComparator

class OutOfPlaceIntegerComparator(value, register_size=None, geq=False, wires=None)[source]

Bases: ResourceOperator

Resource class for an out-of-place integer comparator.

Compares an n-bit quantum register \(|x\rangle\) against a classical integer \(L\), storing the result \(x < L\) (or \(x \geq L\)) in a dedicated output qubit.

The circuit computes the borrow chain of the subtraction \(x - L\). The n - 1 intermediate borrow qubits are kept dirty after the forward pass, enabling the inverse to be performed with Clifford gates only (0 Toffoli cost).

Parameters:
  • value (int) – The value \(L\) that the state’s decimal representation is compared against.

  • register_size (int) – size of the register for basis state

  • geq (bool) – If set to True, the comparison made will be \(n \geq L\). If False, the comparison made will be \(n \lt L\).

  • wires (WiresLike | None) – The wires the operation acts on.

Resources:

The resources are computed based on Figure 6 of Appendix E in Su et al. (2021). This decomposition is useful when extra auxiliary wires are available and an inverse of the operation is required in the same circuit.

The resources are as follows: register_size - 1 TemporaryAND gates, register_size - 1 CNOT gates, and the number of X gates depend on the number of ones in binary representation of the value we are comparing to. There are also register_size - 1 auxiliary qubits that are allocated in the circuit and are deallocated by its adjoint.

Example

The resources for this operation are computed using:

>>> import pennylane.labs.estimator_beta as qre
>>> comparator = qre.OutOfPlaceIntegerComparator(value=11, register_size=4, geq=False)
>>> print(qre.estimate(comparator))
--- Resources: ---
 Total wires: 8
   algorithmic wires: 5
   allocated wires: 3
     zero state: 0
     any state: 3
 Total gates : 17
   'Toffoli': 3,
   'CNOT': 4,
   'X': 10

num_wires

resource_keys

resource_params

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

num_wires = None
resource_keys = {'geq', 'register_size', 'value'}
resource_params

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

Returns:

A dictionary containing the resource parameters:
  • value (int): The value \(L\) that the state’s decimal representation is compared against.

  • register_size (int): size of the register for basis state

  • geq (bool): If set to True, the comparison made will be \(n \geq L\). If False, the comparison made will be \(n \lt L\).

Return type:

dict

add_parallel(other)

Adds a ResourceOperator or Resources in parallel.

add_series(other)

Adds a ResourceOperator or Resources in series.

adjoint_resource_decomp(target_resource_params)

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

controlled_resource_decomp(num_ctrl_wires, ...)

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

pow_resource_decomp(pow_z[, ...])

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

queue([context])

Append the operator to the Operator queue.

resource_decomp(value, register_size[, geq])

Returns a list representing the resources of the operator.

resource_rep(value, register_size[, geq])

Returns a compressed representation containing only the parameters of the Operator that are needed to compute the resources.

resource_rep_from_op()

Returns a compressed representation directly from the operator

tracking_name(*args, **kwargs)

Returns a name used to track the operator during resource estimation.

add_parallel(other)

Adds a ResourceOperator or Resources in parallel.

Parameters:

other (ResourceOperator) – The other object to combine with, it can be another ResourceOperator or a Resources object.

Returns:

added Resources

Return type:

Resources

add_series(other)

Adds a ResourceOperator or Resources in series.

Parameters:

other (ResourceOperator) – The other object to combine with, it can be another ResourceOperator or a Resources object.

Returns:

added Resources

Return type:

Resources

classmethod adjoint_resource_decomp(target_resource_params)[source]

Returns a list representing the resources of the adjoint of the operator. Each object in the list represents a gate and the number of times it occurs in the circuit.

Parameters:

target_resource_params (dict) – Dictionary containing the resource parameters of the target operator.

Resources:

The resources are computed based on Figure 6 of Appendix E in Su et al. (2021). This decomposition is useful when extra auxiliary wires are available and an inverse of the operation is required in the same circuit.

The resources are as follows: register_size - 1 TemporaryAND gates, register_size - 1 CNOT gates, and the number of X gates depend on the number of ones in binary representation of the value we are comparing to. There are also register_size - 1 auxiliary qubits that are allocated in the circuit and are deallocated by its adjoint.

Returns:

A list of gate counts representing the resources of the adjoint of the operator.

Return type:

list[GateCount]

classmethod controlled_resource_decomp(num_ctrl_wires, num_zero_ctrl, target_resource_params=None)

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

For a ResourceOperator that doesn’t define a controlled_resource_decomp method, this will be the default controlled_resource_decomp method.

Resources:

The resources for the controlled operator are obtained by controlling (with the same number of control wires and zero controlled values) each gate in the base operator’s resource decomposition.

Parameters:
  • 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

  • target_resource_params (dict | None) – A dictionary containing the resource parameters of the target operator.

classmethod pow_resource_decomp(pow_z, target_resource_params=None)

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

For a ResourceOperator that doesn’t define a pow_resource_decomp method, this will be its pow_resource_decomp method.

Resources:

The resources for an operator raised to some power are obtained by taking the base resource decomposition of the operator and tracking each gate raised to the given power. For a power of zero, the identity operator is returned. For a power of one, the base operator is returned.

Parameters:
  • pow_z (int) – exponent that the operator is raised to

  • target_resource_params (dict | None) – A dictionary containing the resource parameters of the target operator.

queue(context=<class 'pennylane.queuing.QueuingManager'>)

Append the operator to the Operator queue.

classmethod resource_decomp(value, register_size, geq=False)[source]

Returns a list representing the resources of the operator. Each object in the list represents a gate and the number of times it occurs in the circuit.

Parameters:
  • value (int) – The value \(L\) that the state’s decimal representation is compared against.

  • register_size (int) – size of the register for basis state

  • geq (bool) – If set to True, the comparison made will be \(n \geq L\). If False, the comparison made will be \(n \lt L\).

Resources:

The resources are computed based on Figure 6 of Appendix E in Su et al. (2021). This decomposition is useful when extra auxiliary wires are available and an inverse of the operation is required in the same circuit.

The resources are as follows: register_size - 1 TemporaryAND gates, register_size - 1 CNOT gates, and the number of X gates depend on the number of ones in binary representation of the value we are comparing to. There are also register_size - 1 auxiliary qubits that are allocated in the circuit and are deallocated by its adjoint.

Returns:

A list of gate counts representing the resources of the operator.

Return type:

list[GateCount]

classmethod resource_rep(value, register_size, geq=False)[source]

Returns a compressed representation containing only the parameters of the Operator that are needed to compute the resources.

Parameters:
  • value (int) – The value \(L\) that the state’s decimal representation is compared against.

  • register_size (int) – size of the register for basis state

  • geq (bool) – If set to True, the comparison made will be \(n \geq L\). If False, the comparison made will be \(n \lt L\).

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

resource_rep_from_op()

Returns a compressed representation directly from the operator

classmethod tracking_name(*args, **kwargs)

Returns a name used to track the operator during resource estimation.