qml.estimator.resource_config.ResourceConfig

class ResourceConfig[source]

Bases: object

A container to track the configuration for precisions and custom decompositions for the resource estimation pipeline.

adj_custom_decomps

Returns the dictionary of custom adjoint decompositions.

ctrl_custom_decomps

Returns the dictionary of custom controlled decompositions.

custom_decomps

Returns the dictionary of custom base decompositions.

pow_custom_decomps

Returns the dictionary of custom power decompositions.

adj_custom_decomps

Returns the dictionary of custom adjoint decompositions.

ctrl_custom_decomps

Returns the dictionary of custom controlled decompositions.

custom_decomps

Returns the dictionary of custom base decompositions.

pow_custom_decomps

Returns the dictionary of custom power decompositions.

set_decomp(op_type, decomp_func[, decomp_type])

Sets a custom function to override the default resource decomposition.

set_precision(op_type, precision)

Sets the precision for a given resource operator.

set_single_qubit_rot_precision(precision)

Sets the synthesis precision for all single-qubit rotation gates.

set_decomp(op_type, decomp_func, decomp_type=DecompositionType.BASE)[source]

Sets a custom function to override the default resource decomposition.

Parameters:
  • op_type (type[ResourceOperator]) – the operator class whose decomposition is being overriden.

  • decomp_func (Callable) – the new resource decomposition function to be set as default.

  • decomp_type (None | DecompositionType) – the decomposition type to override. Options are "adj", "pow", "ctrl", and "base". Default is "base".

Raises:

ValueError – If decomp_type is not a valid decomposition type.

Note

The new decomposition function decomp_func should have the same signature as the one it replaces. Specifically, the signature should match the resource_keys of the base resource operator class being overriden.

Example

import pennylane.estimator as qre

def custom_res_decomp(**kwargs):
    h = qre.resource_rep(qre.Hadamard)
    s = qre.resource_rep(qre.S)
    return [qre.GateCount(h, 1), qre.GateCount(s, 2)]
>>> print(qre.estimate_resources(qre.X(), gate_set={"Hadamard", "Z", "S"}))
--- Resources: ---
Total qubits: 1
Total gates : 4
Qubit breakdown:
  clean qubits: 0, dirty qubits: 0, algorithmic qubits: 1
Gate breakdown:
  {'Hadamard': 2, 'S': 2}
>>> config = qre.ResourceConfig()
>>> config.set_decomp(qre.X, custom_res_decomp)
>>> print(qre.estimate_resources(qre.X(), gate_set={"Hadamard", "Z", "S"}, config=config))
--- Resources: ---
Total qubits: 1
Total gates : 3
Qubit breakdown:
  clean qubits: 0, dirty qubits: 0, algorithmic qubits: 1
Gate breakdown:
  {'S': 1, 'Hadamard': 2}
set_precision(op_type, precision)[source]

Sets the precision for a given resource operator.

This method updates the precision value for operators that use a single tolerance parameter (e.g., for synthesis error). It will raise an error if you attempt to set the precision for an operator that is not configurable or uses bit-precisions. A negative precision will also raise an error.

Parameters:
  • op_type (type[ResourceOperator]) – the operator class for which to set the precision

  • precision (float) – The desired precision tolerance. A smaller value corresponds to a higher precision compilation, which may increase the required gate counts. Must be greater than 0.

Raises:

ValueError – If op_type is not a configurable operator or if setting the precision for it is not supported, or if precision is negative.

Example

import pennylane.estimator as qre

config = qre.ResourceConfig()

# Check the default precision
default = config.resource_op_precisions[qre.SelectPauliRot]['precision']
print(f"Default precision for SelectPauliRot: {default}")

# Set a new precision
config.set_precision(qre.SelectPauliRot, precision=1e-5)
new = config.resource_op_precisions[qre.SelectPauliRot]['precision']
print(f"New precision for SelectPauliRot: {new}")
Default precision for SelectPauliRot: 1e-09
New precision for SelectPauliRot: 1e-05
set_single_qubit_rot_precision(precision)[source]

Sets the synthesis precision for all single-qubit rotation gates.

This is a convenience method to update the synthesis precision tolerance for all standard single-qubit rotation gates (and their controlled versions) at once. The synthesis precision dictates the precision for compiling rotation gates into a discrete gate set, which in turn affects the number of gates required.

This method updates the precision value for the following operators: RX, RY, RZ, CRX, CRY, CRZ.

Parameters:

precision (float) – The desired synthesis precision tolerance. A smaller value corresponds to a higher precision compilation, which may increase the required gate counts. Must be greater than 0.

Raises:

ValueError – If precision is a negative value.

Example

import pennylane.estimator as qre

config = qre.ResourceConfig()
print(f"Default RX precision: {config.resource_op_precisions[qre.RX]['precision']}")
print(f"Default RY precision: {config.resource_op_precisions[qre.RY]['precision']}")
print(f"Default RZ precision: {config.resource_op_precisions[qre.RZ]['precision']}")

config.set_single_qubit_rot_precision(1e-5)
print(f"Updated RX precision: {config.resource_op_precisions[qre.RX]['precision']}")
print(f"Updated RY precision: {config.resource_op_precisions[qre.RY]['precision']}")
print(f"Updated RZ precision: {config.resource_op_precisions[qre.RZ]['precision']}")
Default RX precision: 1e-09
Default RY precision: 1e-09
Default RZ precision: 1e-09
Updated RX precision: 1e-05
Updated RY precision: 1e-05
Updated RZ precision: 1e-05