qml.estimator.templates.RegisterComparator

class RegisterComparator(first_register, second_register, geq=False, wires=None)[source]

Bases: ResourceOperator

This operation applies a controlled X gate using register comparison as the condition.

Given the basis states \(\vert a \rangle\), and \(\vert b \rangle\), where \(a\) and \(b\) are positive integers, a target qubit is flipped if \(a \geq b\). Alternatively, the flipping condition can be \(a \lt b\).

Parameters:
  • first_register (int) – the size of the first register

  • second_register (int) – the size of the second register

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

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

Resources:

The resources are obtained from appendix B of arXiv:1711.10460 for registers of the same size. If the sizes of the registers differ, the unary iteration technique from arXiv:1805.03662 is used to combine the results from extra qubits.

Example

The resources for this operation are computed using:

>>> import pennylane.estimator as qre
>>> register_compare = qre.RegisterComparator(4, 6)
>>> print(qre.estimate(register_compare))
--- Resources: ---
 Total wires: 17
    algorithmic wires: 11
    allocated wires: 6
         zero state: 6
         any state: 0
 Total gates : 131
  'Toffoli': 11,
  'CNOT': 63,
  'X': 36,
  'Hadamard': 21

resource_keys

resource_params

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

resource_keys = {'first_register', 'geq', 'second_register'}
resource_params

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

Returns:

A dictionary containing the resource parameters:
  • first_register (int): the size of the first register

  • second_register (int): the size of the second register

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

Return type:

dict

resource_decomp(first_register, second_register)

Returns a list representing the resources of the operator.

resource_rep(first_register, second_register)

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

classmethod resource_decomp(first_register, second_register, 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:
  • first_register (int) – the size of the first register

  • second_register (int) – the size of the second register

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

Resources:

The resources are obtained from appendix B, Figure 3 in arXiv:1711.10460 for registers of the same size. If the sizes of the registers differ, the unary iteration technique from arXiv:1805.03662 is used to combine the results from extra 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_rep(first_register, second_register, geq=False)[source]

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

Parameters:
  • first_register (int) – the size of the first register

  • second_register (int) – the size of the second register

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

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

Contents

Using PennyLane

Release news

Development

API

Internals