qml.resource.add_in_series

add_in_series(r1, r2)[source]

Add two Resources objects assuming the circuits are executed in series.

The gates in r1 and r2 are assumed to act on the same qubits. The resulting circuit depth is the sum of the depths of r1 and r2. To add resources as if they were executed in parallel see add_in_parallel().

Parameters
Returns

the combined resources

Return type

Resources

Example

First we build two Resources objects.

from pennylane.measurements import Shots
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,
    shots = Shots(10)
)

r2 = Resources(
    num_wires = 3,
    num_gates = 2,
    gate_types = {"RX": 1, "CNOT": 1},
    gate_sizes = {1: 1, 2: 1},
    depth = 1,
    shots = Shots((5, (2, 10)))
)

Now we print their sum.

>>> print(qml.resource.add_in_series(r1, r2))
wires: 3
gates: 4
depth: 3
shots: Shots(total=35, vector=[10 shots, 5 shots, 2 shots x 10])
gate_types:
{'Hadamard': 1, 'CNOT': 2, 'RX': 1}
gate_sizes:
{1: 2, 2: 2}