qml.labs.resource_estimation.ResourceQROMStatePreparation

class ResourceQROMStatePreparation(num_state_qubits, precision=None, positive_and_real=False, select_swap_depths=1, wires=None)[source]

Bases: ResourceOperator

Resource class for the QROMStatePreparation template.

This operation implements the state preparation method described in arXiv:0208112, using ResourceQROM to dynamically load the rotation angles.

Note

This decomposition assumes an appropriately sized phase gradient state is available. Users should ensure the cost of constructing such a state has been accounted for. See also ResourcePhaseGradient.

Parameters:
  • num_state_qubits (int) – number of qubits required to represent the state-vector

  • precision (float) – the precision threshold for loading in the binary representation of the rotation angles

  • positive_and_real (bool) – flag that the coefficients of the statevector are all real and positive

  • select_swap_depths (Union[None, int, Iterable(int)], optional) – a parameter of QROM used to trade-off extra qubits for reduced circuit depth

  • wires (Sequence[int], optional) – the wires the operation acts on

Resources:

The resources for QROMStatePreparation are computed according to the decomposition described in arXiv:0208112, using ResourceQROM to dynamically load the rotation angles. These rotations gates are implemented using an in-place controlled-adder operation (see figure 4. of arXiv:2409.07332) to a phase gradient.

Example

The resources for this operation are computed using:

>>> qrom_prep = plre.ResourceQROMStatePreparation(num_state_qubits=5, precision=1e-3)
>>> print(plre.estimate_resources(qrom_prep, gate_set=plre.StandardGateSet))
--- Resources: ---
 Total qubits: 28
 Total gates : 2.744E+3
 Qubit breakdown:
  clean qubits: 23, dirty qubits: 0, algorithmic qubits: 5
 Gate breakdown:
  {'X': 230, 'Toffoli': 236, 'CNOT': 1.522E+3, 'Hadamard': 732, 'S': 12, 'Adjoint(S)': 12}

This operation uses the QROM subroutine to dynamically load the rotation angles.

>>> gate_set = {"QROM", "Hadamard", "CNOT", "T", "Adjoint(QROM)"}
>>> qrom_prep = plre.ResourceQROMStatePreparation(
...     num_state_qubits = 4,
...     precision = 1e-2,
...     select_swap_depths = 2,  # default value is 1
... )
>>> res = plre.estimate_resources(qrom_prep, gate_set)
>>> print(res)
--- Resources: ---
 Total qubits: 21
 Total gates : 2.680E+3
 Qubit breakdown:
  clean qubits: 17, dirty qubits: 0, algorithmic qubits: 4
 Gate breakdown:
  {'QROM': 5, 'Adjoint(QROM)': 5, 'CNOT': 580, 'T': 1.832E+3, 'Hadamard': 258}

The precision argument is used to allocate the target wires in the underlying QROM operations. It corresponds to the precision with which the rotation angles of the template are encoded. This means that the binary representation of the angle is truncated up to the \(m\)-th digit, where \(m\) is the number of precision wires allocated. See Eq. 5 in arXiv:0208112 for more details.

The select_swap_depths parameter allows a user to configure the select_swap_depth of each individual ResourceQROM used. The select_swap_depths argument can be one of (int, None, Iterable(int, None)).

If an integer or None is passed (the default value for this parameter is 1), then that is used as the select_swap_depth for all QROM operations in the resource decomposition.

>>> for op in res.gate_types:
...     if op.name == "QROM":
...         print(op.name, op.params)
...
QROM {'num_bitstrings': 1, 'num_bit_flips': 4, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 2, 'num_bit_flips': 9, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 4, 'num_bit_flips': 18, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 8, 'num_bit_flips': 36, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 16, 'num_bit_flips': 72, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}

Alternatively, we can configure each value independently by specifying a list. Note the size of this list should be num_state_qubits + 1 (num_state_qubits if the state is positive and real).

>>> qrom_prep = plre.ResourceQROMStatePreparation(
...     num_state_qubits = 4,
...     precision = 1e-2,
...     select_swap_depths = [1, None, 2, 2, None],
... )
>>> res = plre.estimate_resources(qrom_prep, gate_set)
>>> for op in res.gate_types:
...     if op.name == "QROM":
...         print(op.name, op.params)
...
QROM {'num_bitstrings': 1, 'num_bit_flips': 4, 'size_bitstring': 9, 'select_swap_depth': 1, 'clean': False}
QROM {'num_bitstrings': 2, 'num_bit_flips': 9, 'size_bitstring': 9, 'select_swap_depth': None, 'clean': False}
QROM {'num_bitstrings': 4, 'num_bit_flips': 18, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 8, 'num_bit_flips': 36, 'size_bitstring': 9, 'select_swap_depth': 2, 'clean': False}
QROM {'num_bitstrings': 16, 'num_bit_flips': 72, 'size_bitstring': 9, 'select_swap_depth': None, 'clean': False}

num_wires

resource_keys

resource_params

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

num_wires = 0
resource_keys = {'num_state_qubits', 'positive_and_real', 'precision', 'selswap_depths'}
resource_params

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

Returns:

A dictionary containing the resource parameters:
  • num_state_qubits (int): number of qubits required to represent the state-vector

  • precision (float): the precision threshold for loading in the binary representation of the rotation angles

  • positive_and_real (bool): flag that the coefficients of the statevector are all real and positive

  • selswap_depths (Union[None, int, Iterable(int)], optional): a parameter of QROM used to trade-off extra qubits for reduced circuit depth

Return type:

dict

adjoint_resource_decomp(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

controlled_resource_decomp(...)

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

controlled_ry_resource_decomp(...[, ...])

Returns a list representing the resources of the operator.

default_adjoint_resource_decomp(*args, **kwargs)

Returns a list representing the resources for the adjoint of the operator.

default_controlled_resource_decomp(...)

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

default_pow_resource_decomp(pow_z, *args, ...)

Returns a list representing the resources for an operator raised to a power.

default_resource_decomp(num_state_qubits, ...)

Returns a list representing the resources 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(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

resource_rep(num_state_qubits[, precision, ...])

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

resource_rep_from_op()

Returns a compressed representation directly from the operator

set_resources(new_func[, override_type])

Set a custom function to override the default resource decomposition.

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.

classmethod adjoint_resource_decomp(*args, **kwargs)

Returns a list of actions that define the resources 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

classmethod controlled_ry_resource_decomp(num_state_qubits, positive_and_real, precision=None, selswap_depths=1, **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:
  • num_state_qubits (int) – number of qubits required to represent the state-vector

  • positive_and_real (bool) – Flag that the coefficients of the statevector are all real and positive.

  • precision (float) – The precision threshold for loading in the binary representation of the rotation angles.

  • select_swap_depths (Union[None, int, Iterable(int)], optional) – A parameter of QROM used to trade-off extra qubits for reduced circuit depth.

Resources:

The resources for QROMStatePreparation are according to the decomposition as described in arXiv:0208112, using ResourceQROM to dynamically load the rotation angles. Controlled-RY (and phase shifts) gates are used to apply all of the rotations coherently.

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 default_adjoint_resource_decomp(*args, **kwargs)

Returns a list representing the resources for the adjoint of the operator.

classmethod default_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

classmethod default_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

classmethod default_resource_decomp(num_state_qubits, positive_and_real, precision=None, selswap_depths=1, **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.

Note

This decomposition assumes an appropriately sized phase gradient state is available. Users should ensure the cost of constructing such a state has been accounted for. See also ResourcePhaseGradient.

Parameters:
  • num_state_qubits (int) – number of qubits required to represent the state-vector

  • positive_and_real (bool) – Flag that the coefficients of the statevector are all real and positive.

  • precision (float) – The precision threshold for loading in the binary representation of the rotation angles.

  • select_swap_depths (Union[None, int, Iterable(int)], optional) – A parameter of QROM used to trade-off extra qubits for reduced circuit depth.

Resources:

The resources for QROMStatePreparation are according to the decomposition as described in arXiv:0208112, using ResourceQROM to dynamically load the rotation angles. These rotations gates are implmented using an inplace controlled-adder operation (see figure 4. of arXiv:2409.07332) to phase gradient.

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]

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(*args, **kwargs)

Returns a list of actions that define the resources of the operator.

classmethod resource_rep(num_state_qubits, precision=None, positive_and_real=False, selswap_depths=1)[source]

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

Parameters:
  • num_state_qubits (int) – number of qubits required to represent the state-vector

  • precision (float) – the precision threshold for loading in the binary representation of the rotation angles

  • positive_and_real (bool) – flag that the coefficients of the statevector are all real and positive

  • selswap_depths (Union[None, int, Iterable(int)], optional) – a parameter of QROM used to trade-off extra qubits for reduced circuit depth

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

resource_rep_from_op()

Returns a compressed representation directly from the operator

classmethod set_resources(new_func, override_type='base')

Set a custom function to override the default resource decomposition.

This method allows users to replace any of the resource_decomp, adjoint_resource_decomp, ctrl_resource_decomp, or pow_resource_decomp methods globally for every instance of the class.

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.