qml.labs.resource_estimation.ResourceIntegerComparator¶
- class ResourceIntegerComparator(value, register_size, geq=False, wires=None)[source]¶
Bases:
ResourceOperatorThis operation applies a controlled X gate using integer comparison as the condition.
Given a basis state \(\vert n \rangle\), where \(n\) is a positive integer, and a fixed positive integer \(L\), a target qubit is flipped if \(n \geq L\). Alternatively, the flipping condition can be \(n \lt L\).
- 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\). IfFalse, the comparison made will be \(n \lt L\).wires (Sequence[int], optional) – the wires the operation acts on
- Resources:
This decomposition uses the minimum number of
MultiControlledXgates. The given integer is first converted into its binary representation, and compared to the quantum register iteratively, starting with the most significant bit, and progressively including more qubits. For example, whengeqisFalse,valueis \(22\) (Binary \(010110\)), andnum_wiresis \(6\):Evaluating most significant bit: For all \(6\)-bit numbers where the first two control qubits are in the \(00\) state, \(n \lt 22\) condition is always
True. AMultiControlledXgate can be applied with these two wires as controls and control values corresponding to \(00\).Refining with subsequent bits: Considering the next most significant bit, since the target value begins with \(0101\). Therefore, all \(6\)-bit numbers beginning with \(0100\) will satisfy the condition, so a
MultiControlledXgate can be applied with the first four wires as controls and control values corresponding to \(0100\).This iterative procedure continues, with
MultiControlledXgates being added for each significant bit of the target value, until the full conditional operation is realized with the minimum number of multi-controlled operations.
The circuit which applies the comparison operation for the above example is defined as:
0: ────╭○─╭○─╭○─┤ 1: ────├○─├●─├●─┤ 2: ────│──├○─├○─┤ 3: ────│──├○─├●─┤ 4: ────│──│──├○─┤ 5: ──-─│──│──│──┤ 6: ────╰X─╰X─╰X─┤
Example
The resources for this operation are computed using:
>>> integer_compare = plre.ResourceIntegerComparator(value=4, register_size=6) >>> print(plre.estimate(integer_compare)) --- Resources: --- Total qubits: 9 Total gates : 19 Qubit breakdown: clean qubits: 2, dirty qubits: 0, algorithmic qubits: 7 Gate breakdown: {'X': 8, 'Toffoli': 3, 'Hadamard': 6, 'CNOT': 2}
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- num_wires = 1¶
- 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\). IfFalse, the comparison made will be \(n \lt L\).
- Return type:
dict
Methods
adjoint_resource_decomp(*args, **kwargs)Returns a list representing the resources for the adjoint of the operator.
Returns a list representing the resources for a controlled version of the operator.
dequeue(op_to_remove[, context])Remove the given resource operator(s) from the Operator queue.
pow_resource_decomp(pow_z, *args, **kwargs)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.
Returns a compressed representation directly from the operator
tracking_name(*args, **kwargs)Returns a name used to track the operator during resource estimation.
Returns the tracking name built with the operator's parameters.
- classmethod adjoint_resource_decomp(*args, **kwargs)¶
Returns a list representing the resources for the adjoint 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
- static dequeue(op_to_remove, context=<class 'pennylane.queuing.QueuingManager'>)¶
Remove the given resource operator(s) from the Operator queue.
- 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(context=<class 'pennylane.queuing.QueuingManager'>)¶
Append the operator to the Operator queue.
- classmethod resource_decomp(value, register_size, geq=False, **kwargs)[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\). IfFalse, the comparison made will be \(n \lt L\).
- Resources:
This decomposition uses the minimum number of
MultiControlledXgates. The given integer is first converted into its binary representation, and compared to the quantum register iteratively, starting with the most significant bit, and progressively including more qubits. For example, whengeqisFalse,valueis \(22\) (Binary \(010110\)), andnum_wiresis \(6\):Evaluating most significant bit: For all \(6\)-bit number where the first two control qubits are in the \(00\) state, \(n \lt 22\) condition is always
True. AMultiControlledXgate can be applied with these two wires as controls and control values corresponding to \(00\).Refining with subsequent bits: Considering the next most significant bit, since the target value begins with \(0101\). Therefore, all \(6\)-bit numbers beginning with \(0100\) will satisfy the condition, so a
MultiControlledXgate can be applied with the first four wires as controls and control values corresponding to \(0100\).This iterative procedure continues, with
MultiControlledXgates being added for each significant bit of the target value, until the full conditional operation is realized with the minimum number of multi-controlled operations.
The circuit which applies the comparison operation for the above example is defined as:
0: ────╭○─╭○─╭○─┤ 1: ────├○─├●─├●─┤ 2: ────│──├○─├○─┤ 3: ────│──├○─├●─┤ 4: ────│──│──├○─┤ 5: ──-─│──│──│──┤ 6: ────╰X─╰X─╰X─┤
- Returns:
A list of
GateCountobjects, 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(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\). IfFalse, the comparison made will be \(n \lt L\).
- Returns:
the operator in a compressed representation
- Return type:
- 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.
- tracking_name_from_op()¶
Returns the tracking name built with the operator’s parameters.