qml.resource.SpecsResources¶
- class SpecsResources(gate_types, gate_sizes, measurements, num_allocs, depth=None)[source]¶
Bases:
objectClass for storing resource information for a quantum circuit. Contains attributes which store key resources such as gate counts, number of wire allocations, measurements, and circuit depth.
- Parameters:
gate_types (dict[str, int]) – A dictionary mapping gate names to their counts.
gate_sizes (dict[int, int]) – A dictionary mapping gate sizes to their counts.
measurements (dict[str, int]) – A dictionary mapping measurements to their counts.
num_allocs (int) – The number of unique wire allocations. For circuits that do not use dynamic wires, this should be equal to the number of device wires.
depth (int | None) – The depth of the circuit, or None if not computed.
- Properties:
num_gates (int): The total number of gates in the circuit (computed from gate_types).
Usage Details
Methods have been provided to allow pretty-printing, as well as indexing into it as a dictionary. See examples below.
Example
>>> from pennylane.resource import SpecsResources >>> res = SpecsResources( ... gate_types={'Hadamard': 1, 'CNOT': 1}, ... gate_sizes={1: 1, 2: 1}, ... measurements={'expval(PauliZ)': 1}, ... num_allocs=2, ... depth=2 ... )
>>> print(res.num_gates) 2
>>> print(res["num_gates"]) 2
>>> print(res) Total wire allocations: 2 Total gates: 2 Circuit depth: 2 Gate types: Hadamard: 1 CNOT: 1 Measurements: expval(PauliZ): 1
Attributes
Total number of gates in the circuit.
- depth = None¶
- num_gates¶
Total number of gates in the circuit.
- gate_types¶
- gate_sizes¶
- measurements¶
- num_allocs¶
Methods
to_dict()Convert the SpecsResources to a dictionary.
to_pretty_str([preindent])Pretty string representation of the SpecsResources object.