qml.estimator.resources_base.Resources¶
- class Resources(zeroed_wires, any_state_wires=0, algo_wires=0, gate_types=None)[source]¶
Bases:
object
Stores the estimated resource requirements of a quantum circuit.
The
estimate()
function returns an object of this class. It contains estimates of all resource types tracked by the resource estimation pipeline, including the number of gates and the number of wires.- Parameters:
zeroed_wires (int) – Number of allocated wires returned in the zeroed state.
any_state_wires (int) – Number of allocated wires returned in an unknowned state.
algo_wires (int) – Number of algorithmic wires, default value is
0
.gate_types (dict) – A dictionary mapping operations (
ResourceOperator
) to their number of occurences in the decomposed circuit.
Example
import pennylane.estimator as qre def circuit(): qre.Hadamard() qre.CNOT() qre.RX(precision=1e-8) qre.RX(precision=1e-6) qre.AliasSampling(num_coeffs=3)
>>> res = qre.estimate(circuit, gate_set={"RX", "Toffoli", "T", "CNOT", "Hadamard"})() >>> print(res) --- Resources: --- Total wires: 123 algorithmic wires: 2 allocated wires: 121 zero state: 58 any state: 63 Total gates : 2.248E+3 'RX': 2, 'Toffoli': 65, 'T': 868, 'CNOT': 639, 'Hadamard': 674
You can also access a more detailed breakdown of resources using the
gate_breakdown()
method>>> print(res.gate_breakdown()) RX total: 2 RX {'precision': 1e-08}: 1 RX {'precision': 1e-06}: 1 Toffoli total: 65 Toffoli {'elbow': None}: 4 Toffoli {'elbow': 'left'}: 61 T total: 868 CNOT total: 639 Hadamard total: 674
Attributes
Produce a dictionary which stores the gate counts using the operator names as keys.
- gate_counts¶
Produce a dictionary which stores the gate counts using the operator names as keys.
- Returns:
- A dictionary with operator names (str) as keys
and the number of occurrences in the circuit (int) as values.
- Return type:
dict
Methods
add_parallel
(other)Add two Resources objects in parallel.
add_series
(other)Add two Resources objects in series.
gate_breakdown
([gate_set])Generates a string breakdown of gate counts by type and parameters, optionally for a specific set of gates.
multiply_parallel
(scalar)Scale a Resources object in parallel
multiply_series
(scalar)Scale a Resources object in series
- add_parallel(other)[source]¶
Add two Resources objects in parallel.
When combining resources for parallel execution, the following rules apply:
Zeroed wires: The maximum of the
zeroed
auxiliary wires is used, as they can be reused across parallel circuits.Any state wires: The
any_state
wires are added together, as they cannot be reused between circuits.Algorithmic wires: The
algo_wires
are added together, as each circuit is a separate unit running simultaneously.Gates: The gates from each circuit are added together.
- Parameters:
other (
Resources
) – other resource object to combine with- Returns:
combined resources
- Return type:
Resources
Example
>>> import pennylane.estimator as qre >>> gate_set = {"X", "Y", "Z", "CNOT", "T", "S", "Hadamard"} >>> res1 = qre.estimate(qre.Toffoli(), gate_set) >>> res2 = qre.estimate(qre.QFT(num_wires=4), gate_set) >>> res_in_parallel = res1.add_parallel(res2) >>> print(res_in_parallel) --- Resources: --- Total wires: 9 algorithmic wires: 7 allocated wires: 2 zero state: 2 any state: 0 Total gates : 838 'T': 796, 'CNOT': 28, 'Z': 2, 'S': 3, 'Hadamard': 9
- add_series(other)[source]¶
Add two Resources objects in series.
When combining resources for serial execution, the following rules apply:
Zeroed wires: The total
zeroed
auxiliary wires are the maximum of thezeroed
wires in each circuit, as they can be reused.Any state wires: The
any_state
wires are added together, as they cannot be reused.Algorithmic wires: The total
algo_wires
are the maximum of thealgo_wires
from each circuit.Gates: The gates from each circuit are added together.
- Parameters:
other (
Resources
) – the other resource object to add in series with- Returns:
combined resources
- Return type:
Resources
Example
>>> import pennylane.estimator as qre >>> gate_set = {"X", "Y", "Z", "CNOT", "T", "S", "Hadamard"} >>> res1 = qre.estimate(qre.Toffoli(), gate_set) >>> res2 = qre.estimate(qre.QFT(num_wires=4), gate_set) >>> res_in_series = res1.add_series(res2) >>> print(res_in_series) --- Resources: --- Total wires: 6 algorithmic wires: 4 allocated wires: 2 zero state: 2 any state: 0 Total gates : 838 'T': 796, 'CNOT': 28, 'Z': 2, 'S': 3, 'Hadamard': 9
- gate_breakdown(gate_set=None)[source]¶
Generates a string breakdown of gate counts by type and parameters, optionally for a specific set of gates.
- Parameters:
gate_set (list) – A list of gate names to break down. If
None
, details will be provided for all gate types.
Example
>>> import pennylane.estimator as qre >>> def circ(): ... qre.SemiAdder(10) ... qre.Toffoli() ... qre.RX(precision=1e-5) ... qre.RX(precision=1e-7) >>> res1 = qre.estimate(circ, gate_set=['Toffoli', 'RX', 'CNOT', 'Hadamard'])() >>> print(res1.gate_breakdown()) RX total: 2 RX {'precision': 1e-05}: 1 RX {'precision': 1e-07}: 1 Toffoli total: 10 Toffoli {'elbow': 'left'}: 9 Toffoli {'elbow': None}: 1 CNOT total: 60 Hadamard total: 27
- multiply_parallel(scalar)[source]¶
Scale a Resources object in parallel
- Parameters:
scalar (int) – integer value by which to scale the resources
- Returns:
scaled resources
- Return type:
Resources
Example
>>> import pennylane.estimator as qre >>> gate_set = {"X", "Y", "Z", "CNOT", "T", "S", "Hadamard"} >>> res1 = qre.estimate(qre.Toffoli(), gate_set) >>> res_in_parallel = res1.multiply_parallel(3) >>> print(res_in_parallel) --- Resources: --- Total wires: 11 algorithmic wires: 9 allocated wires: 2 zero state: 2 any state: 0 Total gates : 72 'T': 12, 'CNOT': 30, 'Z': 6, 'S': 9, 'Hadamard': 15
- multiply_series(scalar)[source]¶
Scale a Resources object in series
- Parameters:
scalar (int) – integer value by which to scale the resources
- Returns:
scaled resources
- Return type:
Resources
Example
>>> import pennylane.estimator as qre >>> gate_set = {"X", "Y", "Z", "CNOT", "T", "S", "Hadamard"} >>> res1 = qre.estimate(qre.Toffoli(), gate_set) >>> res_in_series = res1.multiply_series(3) >>> print(res_in_series) --- Resources: --- Total wires: 5 algorithmic wires: 3 allocated wires: 2 zero state: 2 any state: 0 Total gates : 72 'T': 12, 'CNOT': 30, 'Z': 6, 'S': 9, 'Hadamard': 15