qml.labs.resource_estimation.estimate

estimate(obj, gate_set=None, work_wires=0, tight_budget=False, config=None)[source]

Estimate the quantum resources required from a circuit or operation in terms of the gates provided in the gateset.

Parameters:
  • obj (Union[ResourceOperator, Callable, Resources, List]) – The quantum circuit or operation to obtain resources from.

  • gate_set (Set, optional) – A set of names (strings) of the fundamental operations to track counts for throughout the quantum workflow.

  • work_wires (int | dict | optional) – The number of available zeroed and/or any_state ancilla qubits. If an integer is provided, it specifies the number of zeroed ancillas. If a dictionary is provided, it should have the keys "zeroed" and "any_state". Defaults to 0.

  • tight_budget (bool | None) – Determines whether extra zeroed state wires can be allocated when they exceed the available amount. The default is False.

  • config (ResourceConfig, optional) – A ResourceConfig object of additional parameters which sets default values when they are not specified on the operator.

Returns:

the quantum resources required to execute the circuit

Return type:

Resources

Raises:

TypeError – could not obtain resources for obj of type type(obj)

Example

We can track the resources of a quantum workflow by passing the quantum function defining our workflow directly into this function.

import pennylane.labs.resource_estimation as plre

def my_circuit():
    for w in range(2):
        plre.ResourceHadamard(wires=w)

    plre.ResourceCNOT(wires=[0,1])
    plre.ResourceRX(wires=0)
    plre.ResourceRY(wires=1)

    plre.ResourceQFT(num_wires=3, wires=[0, 1, 2])
    return

Note that we are passing a python function NOT a QNode. The resources for this workflow are then obtained by:

>>> config = plre.ResourceConfig()
>>> config.set_single_qubit_rot_precision(1e-4)
>>> res = plre.estimate(
...     my_circuit,
...     gate_set = plre.DefaultGateSet,
...     config=config,
... )()
...
>>> print(res)
--- Resources: ---
Total qubits: 3
Total gates : 279
Qubit breakdown:
 clean qubits: 0, dirty qubits: 0, algorithmic qubits: 3
Gate breakdown:
 {'Hadamard': 5, 'CNOT': 10, 'T': 264}