qp.resource.resources_from_tape

resources_from_tape(tape, compute_depth=True)[source]

Extracts the resource information from a quantum circuit (tape).

The depth of the circuit is computed by default, but can be set to None by setting the compute_depth argument to False. This is useful when the depth is not needed, for example, in some resource counting scenarios or heavy circuits where computing depth is expensive.

Parameters:
  • tape (.QuantumScript) – The quantum circuit for which we extract resources

  • compute_depth (bool) – If True, the depth of the circuit is computed and included in the resources. If False, the depth is set to None.

Returns:

The resources associated with this tape.

Return type:

SpecsResources

Example

import pennylane as qp
from pennylane.resource import resources_from_tape

dev = qp.device("default.qubit", wires=2)

@qp.qnode(dev)
def circuit(theta):
    qp.RX(theta, wires=0)
    qp.CNOT(wires=[0, 1])
    return qp.expval(qp.PauliZ(0))

tape = qp.workflow.construct_tape(circuit)(3)
resources = resources_from_tape(tape)
>>> print(resources)
Quantum operations:
- Total: 2
    - RX: 1
    - CNOT: 1
Measurement processes:
- expval(PauliZ): 1
Total wires: 2
Circuit Depth: 2