qml.resource¶
The resource module provides classes and functionality to track the quantum resources
(number of qubits, circuit depth, etc.) required to implement advanced quantum algorithms.
See also
The estimator module for higher level resource estimation of quantum programs.
Circuit Specifications (specs)¶
|
Provides the specifications of a quantum circuit. |
Circuit Specification Classes and Utilities¶
|
Class for storing specifications of a qnode. |
|
Class for storing resource information for a quantum circuit. |
|
Extracts the resource information from a quantum circuit (tape). |
Error Tracking¶
|
Abstract base class representing an abstract type of error. |
|
Class representing the spectral norm error. |
|
Base class that represents quantum operations which carry some form of algorithmic error. |
|
Computes the algorithmic errors in a quantum circuit. |
Warning
The functions estimate_error, estimate_shots and the classes DoubleFactorization,
FirstQuantization have been moved to the pennylane.estimator module.
Accessing them from the pennylane.resource module is deprecated and will be removed
in v0.45.
Resource Classes¶
|
Contains attributes which store key resources such as number of gates, number of wires, shots, depth and gate types. |
|
Base class that represents quantum gates or channels applied to quantum states and stores the resource requirements of the quantum gate. |
Resource Functions¶
|
Add two |
|
Add two |
|
Multiply the |
|
Multiply the |
|
Replaces a specified gate in a |
Tracking Resources for Custom Operations¶
We can use the null.qubit device with pennylane.Tracker
to track the resources used in a quantum circuit with custom operations without execution.
from pennylane import numpy as pnp
from pennylane.resource import Resources, ResourcesOperation
class MyCustomAlgorithm(ResourcesOperation):
num_wires = 2
def resources(self):
return Resources(
num_wires=self.num_wires,
num_gates=5,
gate_types={"Hadamard": 2, "CNOT": 1, "PauliZ": 2},
gate_sizes={1: 4, 2: 1},
depth=3,
)
dev = qml.device("null.qubit", wires=[0, 1, 2])
@qml.set_shots(shots=100)
@qml.qnode(dev)
def circuit(theta):
qml.RZ(theta, wires=0)
qml.CNOT(wires=[0,1])
MyCustomAlgorithm(wires=[1, 2])
return qml.expval(qml.Z(1))
x = pnp.array(1.23, requires_grad=True)
with qml.Tracker(dev) as tracker:
circuit(x)
We can examine the resources by accessing the resources key:
>>> resources_lst = tracker.history['resources']
>>> print(resources_lst[0])
Total wire allocations: 3
Total gates: 7
Circuit depth: 5
Gate types:
RZ: 1
CNOT: 2
Hadamard: 2
PauliZ: 2
Measurements:
expval(PauliZ): 1