qml.estimator.templates.QROM

class QROM(num_bitstrings, size_bitstring, num_bit_flips=None, restored=True, select_swap_depth=None, wires=None)[source]

Bases: ResourceOperator

Resource class for the 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, optional) – The total number of \(1\)’s in the dataset. Defaults to (num_bitstrings * size_bitstring) // 2, which is half the dataset.

  • restored (bool, optional) – 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, 1 or a positive integer power of two. Defaults to None, which internally determines the optimal depth.

  • wires (Sequence[int], 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 taken from the following two papers: Low et al. (2024) (Figure 1.C) for restored = False and Berry et al. (2019) (Figure 4) for restored = True.

See also

The associated PennyLane operation QROM

Example

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 : 178
'Toffoli': 16,
'CNOT': 72,
'X': 34,
'Hadamard': 56

resource_keys

resource_params

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, optional): The total number of \(1\)’s in the dataset. Defaults to (num_bitstrings * size_bitstring) // 2, which is half the dataset.

  • restored (bool, optional): Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). Defaults to :code`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, 1 or a positive integer power of two. Defaults to None, which internally determines the optimal depth.

Return type:

dict

controlled_resource_decomp(num_ctrl_wires, ...)

Returns a list representing the resources for a controlled version of the operator.

resource_decomp(num_bitstrings, ...[, ...])

Returns a list of GateCount objects 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 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 = False and Berry et al. (2019) (Figure 4) for restored = True.

Note: we use the single-controlled unary iterator trick to implement the Select. This implementation assumes we have access to \(n - 1\) additional work qubits, where \(n = \ceil{log_{2}(N)}\) and \(N\) is the number of batches of unitaries to select.

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_decomp(num_bitstrings, size_bitstring, num_bit_flips, select_swap_depth=None, restored=True)[source]

Returns a list of GateCount objects 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, optional) – 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, 1 or a positive integer power of two. Defaults to None, which internally determines the optimal depth.

  • restored (bool, optional) – Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). Defaults to :code`True`.

Resources:

The resources for QROM are taken from the following two papers: Low et al. (2024) (Figure 1.C) for restored = False and Berry et al. (2019) (Figure 4) for restored = True.

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.

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, optional) – The total number of \(1\)’s in the dataset. Defaults to (num_bitstrings * size_bitstring) // 2, which is half the dataset.

  • restored (bool, optional) – Determine if allocated qubits should be reset after the computation (at the cost of higher gate counts). Defaults to :code`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, 1 or a positive integer power of two. Defaults to None, which internally determines the optimal depth.

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

classmethod single_controlled_res_decomp(num_bitstrings, size_bitstring, num_bit_flips, select_swap_depth, restored)[source]

The resource decomposition for QROM controlled on a single wire.

Contents

Using PennyLane

Release news

Development

API

Internals