qml.estimator.templates.TwoQubitComparator

class TwoQubitComparator(wires=None)[source]

Bases: ResourceOperator

Resource class for comparing the integer values encoded in two quantum registers of two qubits each.

This operation modifies the input registers. The original values can be restored by applying the operation’s adjoint.

Parameters:

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

Resources:

The resources are obtained from appendix B, Figure 3 in arXiv:1711.10460. Specifically, the resources are given as \(2\) CSWAP gates, \(3\) CNOT gates, and \(1\) X gate. This decomposition requires one zeroed auxiliary qubit. The circuit which applies the comparison operation on registers \((x_0,x_1)\) and \((y_0, y_1)\) is defined as:

 x1 : ─╭X─╭●────╭●───────┤
 y1 : ─╰●─│─────├SWAP────┤
 x0 : ─╭X─├SWAP─│─────╭X─┤
 y0 : ─╰●─│─────╰SWAP─╰●─┤
|1> : ────╰SWAP──────────┤

Note that this operation provides an alternate decomposition using TemporaryAND. See the TemporaryAND_based_decomp method for more details.

Example

The resources for this operation are computed using:

>>> import pennylane.estimator as qre
>>> two_qubit_compare = qre.TwoQubitComparator()
>>> print(qre.estimate(two_qubit_compare))
--- Resources: ---
 Total wires: 5
    algorithmic wires: 4
    allocated wires: 1
         zero state: 1
         any state: 0
 Total gates : 10
  'Toffoli': 2,
  'CNOT': 7,
  'X': 1

num_wires

resource_params

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

num_wires = 4
resource_params

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

Returns:

An empty dictionary

Return type:

dict

TemporaryAND_based_decomp()

Returns a list representing the resources of the operator.

resource_decomp()

Returns a list representing the resources of the operator.

resource_rep()

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

classmethod TemporaryAND_based_decomp()[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.

Resources:

The resources are obtained from appendix B, Figure 3 in arXiv:1711.10460. Specifically, the resources are given as \(2\) CSWAP gates, \(3\) CNOT gates, and \(1\) X gate. This decomposition is modified to use TemporaryAND gates for building blocks of CSWAP gates.

 x1: ─╭X───────╭●──────────╭●──────────┤
 y1: ─╰●───────│────────╭X─├●────╭X────┤
|0>: ──────────│────────│──╰──╭●─│─────┤
 x0: ─╭X─╭X────├●────╭X─│─────│──│──╭X─┤
 y0: ─╰●─│─────│─────│──╰●────╰X─╰●─╰●─┤
|1>: ────╰●──X─╰───X─╰●────────────────┤
classmethod resource_decomp()[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.

Resources:

The resources are obtained from appendix B, Figure 3 in arXiv:1711.10460. Specifically, the resources are given as \(2\) CSWAP gates, \(3\) CNOT gates, and \(1\) X gate. This decomposition requires one zeroed auxiliary qubit. The circuit which applies the comparison operation on registers \((x0,x1)\) and \((y0, y1)\) is defined as:

 x1 : ─╭X─╭●────╭●───────┤
 y1 : ─╰●─│─────├SWAP────┤
 x0 : ─╭X─├SWAP─│─────╭X─┤
 y0 : ─╰●─│─────╰SWAP─╰●─┤
|1> : ────╰SWAP──────────┤
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()[source]

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

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

Contents

Using PennyLane

Release news

Development

API

Internals