qml.labs.resource_estimation.set_pow_decomp

set_pow_decomp(cls, decomp_func)[source]

Set a custom function to override the default pow-resource decomposition. This function will be set globally for every instance of the class.

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

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

Note

The new decomposition function 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. Addtionally, the pow-decomposition requires an additional argument: pow_z.

Example

from pennylane.labs import resource_estimation as plre

def custom_pow_decomp(pow_z, **kwargs):
    h = plre.resource_rep(plre.ResourceHadamard)
    s = plre.resource_rep(plre.ResourceS)
    id = plre.resource_rep(plre.ResourceIdentity)

    if pow_z % 2 == 0:
        return [plre.GateCount(id, 1)]

    return [plre.GateCount(h, 2), plre.GateCount(s, 2)]
>>> pow_x = plre.ResourcePow(plre.ResourceX(), 3)
>>> print(plre.estimate_resources(pow_x, gate_set={"X", "Hadamard", "S"}))
--- Resources: ---
Total qubits: 1
Total gates : 1
Qubit breakdown:
 clean qubits: 0, dirty qubits: 0, algorithmic qubits: 1
Gate breakdown:
 {'X': 1}
>>> plre.set_pow_decomp(plre.ResourceX, custom_pow_decomp)
>>> print(plre.estimate_resources(pow_x, gate_set={"X", "Hadamard", "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}