qml.labs.resource_estimation.set_ctrl_decomp¶
- set_ctrl_decomp(cls, decomp_func)[source]¶
Set a custom function to override the default controlled-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 controlled decomposition requires two additional arguments:
ctrl_num_ctrl_wires
andctrl_num_ctrl_values
.Example
from pennylane.labs import resource_estimation as plre def custom_ctrl_decomp(ctrl_num_ctrl_wires, ctrl_num_ctrl_values, **kwargs): h = plre.resource_rep(plre.ResourceHadamard) cz = plre.resource_rep(plre.ResourceCZ) return [plre.GateCount(h, 2), plre.GateCount(cz, 1)]
>>> cx = plre.ResourceControlled(plre.ResourceX(), 1, 0) >>> print(plre.estimate_resources(cx, gate_set={"CNOT", "Hadamard", "CZ"})) --- Resources: --- Total qubits: 2 Total gates : 1 Qubit breakdown: clean qubits: 0, dirty qubits: 0, algorithmic qubits: 2 Gate breakdown: {'CNOT': 1} >>> plre.set_ctrl_decomp(plre.ResourceX, custom_ctrl_decomp) >>> print(plre.estimate_resources(cx, gate_set={"CNOT", "Hadamard", "CZ"})) --- Resources: --- Total qubits: 2 Total gates : 3 Qubit breakdown: clean qubits: 0, dirty qubits: 0, algorithmic qubits: 2 Gate breakdown: {'Hadamard': 2, 'CZ': 1}
code/api/api/pennylane.labs.resource_estimation.set_ctrl_decomp
Download Python script
Download Notebook
View on GitHub