qml.resource.Resources

class Resources(num_wires=0, num_gates=0, gate_types=<factory>, gate_sizes=<factory>, depth=0, shots=<factory>)[source]

Bases: object

Contains attributes which store key resources such as number of gates, number of wires, shots, depth and gate types.

Parameters
  • num_wires (int) – number of qubits

  • num_gates (int) – number of gates

  • gate_types (dict) – dictionary storing operation names (str) as keys and the number of times they are used in the circuit (int) as values

  • gate_sizes (dict) – dictionary storing the number of \(n\) qubit gates in the circuit as a key-value pair where \(n\) is the key and the number of occurances is the value

  • depth (int) – the depth of the circuit defined as the maximum number of non-parallel operations

  • shots (Shots) – number of samples to generate

The resources being tracked can be accessed as class attributes. Additionally, the Resources instance can be nicely displayed in the console.

Example

>>> from pennylane.resource import Resources
>>> r = Resources(num_wires=2, num_gates=2, gate_types={'Hadamard': 1, 'CNOT':1}, gate_sizes={1: 1, 2: 1}, depth=2)
>>> print(r)
num_wires: 2
num_gates: 2
depth: 2
shots: Shots(total=None)
gate_types:
{'Hadamard': 1, 'CNOT': 1}
gate_sizes:
{1: 1, 2: 1}

Resources objects can be added together or multiplied by a scalar.

>>> from pennylane.resource import Resources
>>> r1 = Resources(num_wires=2, num_gates=2, gate_types={'Hadamard': 1, 'CNOT':1}, gate_sizes={1: 1, 2: 1}, depth=2)
>>> r2 = Resources(num_wires=2, num_gates=2, gate_types={'RX': 1, 'CNOT':1}, gate_sizes={1: 1, 2: 1}, depth=2)
>>> print(r1 + r2)
wires: 2
gates: 4
depth: 4
shots: Shots(total=None)
gate_types:
{'Hadamard': 1, 'CNOT': 2, 'RX': 1}
gate_sizes:
{1: 2, 2: 2}
>>> print(r1 * 2)
wires: 2
gates: 4
depth: 4
shots: Shots(total=None)
gate_types:
{'Hadamard': 2, 'CNOT': 2}
gate_sizes:
{1: 2, 2: 2}

depth

num_gates

num_wires

gate_types

gate_sizes

shots

depth = 0
num_gates = 0
num_wires = 0
gate_types
gate_sizes
shots