qp.labs.estimator_beta.templates.LabsQROM¶
- class LabsQROM(num_bitstrings, size_bitstring, num_bit_flips=None, borrow_qubits=True, select_swap_depth=None, wires=None, **kwargs)[source]¶
Bases:
ResourceOperatorResource class for the Quantum Read-Only Memory (QROM) template.
- Parameters:
num_bitstrings (int) – the number of bitstrings that are to be encoded
size_bitstring (int) – the length of each bitstring
num_bit_flips (int | None) – The total number of \(1\)’s in the dataset. Defaults to
(num_bitstrings * size_bitstring) // 2, which is half the dataset.borrow_qubits (bool) – Determine whether the auxiliary qubits should be borrowed (higher gate cost) or freshly allocated (higher qubit cost). Defaults to
True.select_swap_depth (int | None) – A parameter \(\lambda\) that determines if data will be loaded in parallel by adding more rows following Figure 1.C of Low et al. (2024). Can be
None,1or a positive integer power of two. Defaults toNone, which sets the depth that minimizes T-gate count.wires (WiresLike | None) – The wires the operation acts on (control and target), excluding any additional qubits allocated during the decomposition (e.g select-swap wires).
- Resources:
The resources for QROM are derived from Appendix A, B from Berry et al. (2019).
borrow_qubits=True: Uses the borrowed qubit decomposition from Figure 4 of Appendix A in Berry et al. (2019).borrow_qubits=False: Uses the clean qubit decomposition from Appendix B in Berry et al. (2019).
See also
The associated PennyLane operation
QROMand the resource operatorQROM.Example
The resources for this operation are computed using:
>>> import pennylane.labs.estimator_beta as qre >>> qrom = qre.LabsQROM( ... num_bitstrings=10, ... size_bitstring=4, ... ) >>> print(qre.estimate(qrom)) --- Resources: --- Total wires: 11 algorithmic wires: 8 allocated wires: 3 zero state: 3 any state: 0 Total gates : 86 'Toffoli': 8, 'CNOT': 36, 'X': 18, 'Hadamard': 24
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- num_wires = None¶
- resource_keys = {'borrow_qubits', 'num_bit_flips', 'num_bitstrings', 'select_swap_depth', 'size_bitstring'}¶
- resource_params¶
Returns a dictionary containing the minimal information needed to compute the resources.
- Returns:
- A dictionary containing the resource parameters:
num_bitstrings (int): the number of bitstrings that are to be encoded
size_bitstring (int): the length of each bitstring
num_bit_flips (int | None): The total number of \(1\)’s in the dataset. Defaults to
(num_bitstrings * size_bitstring) // 2, which is half the dataset.borrow_qubits (bool): Determine whether the auxiliary qubits should be borrowed (higher gate cost) or freshly allocated (higher qubit cost). Defaults to
True.select_swap_depth (int | None): A parameter \(\lambda\) that determines if data will be loaded in parallel by adding more rows following Figure 1.C of Low et al. (2024). Can be
None,1or a positive integer power of two. Defaults to None, which sets the depth that minimizes T-gate count.
- Return type:
dict
Methods
add_parallel(other)Adds a
ResourceOperatororResourcesin parallel.add_series(other)Adds a
ResourceOperatororResourcesin 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.
Returns a list representing the resources of the adjoint of the operator.
Returns a list representing the resources of the adjoint of the operator.
queue([context])Append the operator to the Operator queue.
resource_decomp(num_bitstrings, size_bitstring)Returns a list of
GateCountobjects representing the operator's resources.resource_rep(num_bitstrings, size_bitstring)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
single_controlled_res_decomp(num_bitstrings, ...)The resource decomposition for LabsQROM controlled on a single wire.
tracking_name(num_bitstrings, size_bitstring)Returns a name used to track the operator during resource estimation.
- add_parallel(other)¶
Adds a
ResourceOperatororResourcesin parallel.- Parameters:
other (
ResourceOperator) – The other object to combine with, it can be anotherResourceOperatoror aResourcesobject.- Returns:
added
Resources- Return type:
Resources
- add_series(other)¶
Adds a
ResourceOperatororResourcesin series.- Parameters:
other (
ResourceOperator) – The other object to combine with, it can be anotherResourceOperatoror aResourcesobject.- Returns:
added
Resources- Return type:
Resources
- classmethod adjoint_resource_decomp(target_resource_params=None)[source]¶
Returns a list representing the resources of the adjoint of the operator.
- Parameters:
target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.
- Resources:
This is an alternate decomposition for the adjoint of QROM which uses a measurement and phase fixup algorithm. This decomposition requires one clean auxiliary qubit. The resources are based on Figure 7 in Appendix C of Berry et al. (2019).
- 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 controlled_resource_decomp(num_ctrl_wires, num_zero_ctrl, target_resource_params=None)[source]¶
Returns a list representing the resources for a controlled version of the operator.
- 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) – A dictionary containing the resource parameters of the target operator.
- Resources:
The resources for QROM are derived from Appendix A, B from Berry et al. (2019).
borrow_qubits=True: Uses the borrowed qubit decomposition from Figure 4 of Appendix A in Berry et al. (2019).borrow_qubits=False: Uses the clean qubit decomposition from Appendix B in Berry et al. (2019).
Note: we use the single-controlled unary iterator trick to implement the
Select. This implementation assumes we have access to \(n\) additional work qubits, where \(n = \lceil \log_{2}(N) \rceil\) and \(N\) is the number of batches of unitaries to select.
- 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 pow_resource_decomp(pow_z, target_resource_params=None)¶
Returns a list representing the resources for an operator raised to a power.
For a
ResourceOperatorthat doesn’t define apow_resource_decompmethod, this will be itspow_resource_decompmethod.- 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.
- classmethod qrom_clean_auxiliary_adjoint_resource_decomp(target_resource_params)[source]¶
Returns a list representing the resources of the adjoint of the operator.
- Parameters:
target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.
- Resources:
This is an alternate decomposition for the adjoint of QROM which uses a measurement and phase fixup algorithm. This decomposition requires one clean auxiliary qubit. The resources are based on Figure 7 in Appendix C of Berry et al. (2019).
- 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 qrom_dirty_auxiliary_adjoint_resource_decomp(target_resource_params)[source]¶
Returns a list representing the resources of the adjoint of the operator.
- Parameters:
target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.
- Resources:
This is an alternate decomposition for the adjoint of QROM which uses a measurement and phase fixup algorithm. This decomposition requires one borrowed auxiliary qubit. The resources are based on Figure 7 in Appendix C of Berry et al. (2019).
- 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]
- queue(context=<class 'pennylane.queuing.QueuingManager'>)¶
Append the operator to the Operator queue.
- classmethod resource_decomp(num_bitstrings, size_bitstring, num_bit_flips=None, borrow_qubits=True, select_swap_depth=None)[source]¶
Returns a list of
GateCountobjects representing the operator’s resources.- Parameters:
num_bitstrings (int) – the number of bitstrings that are to be encoded
size_bitstring (int) – the length of each bitstring
num_bit_flips (int | None) – The total number of \(1\)’s in the dataset. Defaults to
(num_bitstrings * size_bitstring) // 2, which is half the dataset.borrow_qubits (bool) – Determine whether the auxiliary qubits should be borrowed (higher gate cost) or freshly allocated (higher qubit cost). Defaults to
True.select_swap_depth (int | None) –
A parameter \(\lambda\) that determines if data will be loaded in parallel by adding more rows following Figure 1.C of Low et al. (2024). Can be
None,1or a positive integer power of two. Defaults toNone, which sets the depth that minimizes T-gate count.
- Resources:
The resources for QROM are derived from Appendix A, B from Berry et al. (2019).
borrow_qubits=True: Uses the borrowed qubit decomposition from Figure 4 of Appendix A in Berry et al. (2019).borrow_qubits=False: Uses the clean qubit decomposition from Appendix B in Berry et al. (2019).
Note: we use the unary iterator trick to implement the
Select. This implementation assumes we have access to \(n - 1\) additional work qubits, where \(n = \left\lceil \log_{2}(N) \right\rceil\) and \(N\) is the number of batches of unitaries to select.
- 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(num_bitstrings, size_bitstring, num_bit_flips=None, borrow_qubits=True, select_swap_depth=None)[source]¶
Returns a compressed representation containing only the parameters of the Operator that are needed to compute the resources.
- Parameters:
num_bitstrings (int) – the number of bitstrings that are to be encoded
size_bitstring (int) – the length of each bitstring
num_bit_flips (int | None) – The total number of \(1\)’s in the dataset. Defaults to
(num_bitstrings * size_bitstring) // 2, which is half the dataset.borrow_qubits (bool) – Determine whether the auxiliary qubits should be borrowed (higher gate cost) or freshly allocated (higher qubit cost). Defaults to
True.select_swap_depth (int | None) –
A parameter \(\lambda\) that determines if data will be loaded in parallel by adding more rows following Figure 1.C of Low et al. (2024). Can be
None,1or a positive integer power of two. Defaults toNone, which sets the depth that minimizes T-gate count.
- Returns:
the operator in a compressed representation
- Return type:
- resource_rep_from_op()¶
Returns a compressed representation directly from the operator
- classmethod single_controlled_res_decomp(num_bitstrings, size_bitstring, num_bit_flips=None, select_swap_depth=None, borrow_qubits=True)[source]¶
The resource decomposition for LabsQROM controlled on a single wire.
- Parameters:
num_bitstrings (int) – the number of bitstrings that are to be encoded
size_bitstring (int) – the length of each bitstring
num_bit_flips (int | None) – The total number of \(1\)’s in the dataset. Defaults to
(num_bitstrings * size_bitstring) // 2, which is half the dataset.borrow_qubits (bool) – Determine whether the auxiliary qubits should be borrowed (higher gate cost) or freshly allocated (higher qubit cost). Defaults to
True.select_swap_depth (int | None) –
A parameter \(\lambda\) that determines if data will be loaded in parallel by adding more rows following Figure 1.C of Low et al. (2024). Can be
None,1or a positive integer power of two. Defaults toNone, which sets the depth that minimizes T-gate count.
- 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]