qml.estimator.templates.QROM¶
- class QROM(num_bitstrings, size_bitstring, num_bit_flips=None, restored=True, select_swap_depth=None, wires=None)[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.restored (bool) – Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). 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 the following references:
restored=False: Uses the Select-Swap tree decomposition from Figure 1.C of Low et al. (2018), further optimized using the measurement-based uncomputation technique described in Berry et al. (2019).restored=True: Uses the standard QROM resource accounting from Figure 4 of Berry et al. (2019).
See also
The associated PennyLane operation
QROMExample
The resources for this operation are computed using:
>>> import pennylane.estimator as qre >>> qrom = qre.QROM( ... 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 : 85 'Toffoli': 8, 'CNOT': 36, 'X': 17, 'Hadamard': 24
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- resource_keys = {'num_bit_flips', 'num_bitstrings', 'restored', '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.restored (bool): Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). 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
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.
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 a resource estimation.
single_controlled_res_decomp(num_bitstrings, ...)The resource decomposition for QROM controlled on a single wire.
- classmethod adjoint_resource_decomp(target_resource_params)[source]¶
Returns a list representing the resources of the adjoint of the operator. Each object represents a quantum gate and the number of times it occurs in the decomposition.
- Parameters:
target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.
- Resources:
This resources are based on Appendix C of arXiv:1902.02134.
- 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)[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 taken from the following two papers: Low et al. (2024) (Figure 1.C) for
restored = Falseand Berry et al. (2019) (Figure 4) forrestored = True.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 resource_decomp(num_bitstrings, size_bitstring, num_bit_flips=None, select_swap_depth=None, restored=True)[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.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.restored (bool) – Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). Defaults to
True.
- Resources:
The resources for QROM are derived from the following references:
restored=False: Uses the Select-Swap tree decomposition from Figure 1.C of Low et al. (2018), further optimized using the measurement-based uncomputation technique described in Berry et al. (2019).restored=True: Uses the standard QROM resource accounting from Figure 4 of 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, restored=True, select_swap_depth=None)[source]¶
Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.
- 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.restored (bool) – Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). 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: