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.
Expectation Value Functions¶
|
Estimate the error in computing an expectation value with a given number of measurements. |
|
Estimate the number of measurements required to compute an expectation value with a target error. |
Circuit specifications¶
|
Resource information about a quantum circuit. |
Quantum Phase Estimation Resources¶
|
Estimate the number of non-Clifford gates and logical qubits for a quantum phase estimation algorithm in first quantization using a plane-wave basis. |
|
Estimate the number of non-Clifford gates and logical qubits for a quantum phase estimation algorithm in second quantization with a double-factorized Hamiltonian. |
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. |
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 the pennylane.Tracker
to track the resources
used in a quantum circuit with custom operations without execution.
from functools import partial
from pennylane import numpy as pnp
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])
@partial(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])
num_wires: 3
num_gates: 7
depth: 5
shots: Shots(total=100)
gate_types:
{'RZ': 1, 'CNOT': 2, 'Hadamard': 2, 'PauliZ': 2}
gate_sizes:
{1: 5, 2: 2}