qml.labs.resource_estimation.set_adj_decomp

set_adj_decomp(cls, decomp_func)[source]

Set a custom function to override the default adjoint-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.

Example

from pennylane.labs import resource_estimation as plre

def custom_adj_decomp(**kwargs):
    h = plre.resource_rep(plre.ResourceHadamard)
    s = plre.resource_rep(plre.ResourceS)
    return [plre.GateCount(h, 2), plre.GateCount(s, 2)]
>>> adj_x = plre.ResourceAdjoint(plre.ResourceX())
>>> print(plre.estimate_resources(adj_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_adj_decomp(plre.ResourceX, custom_adj_decomp)
>>> print(plre.estimate_resources(adj_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}