qml.resource.add_in_parallel

add_in_parallel(r1, r2)[source]

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

The gates in r2 and r2 are assumed to act on disjoint sets of qubits. The resulting circuit depth is the max depth of r1 and r2. To add resources as if they were executed in series see add_in_series().

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_parallel(r1, r2))
wires: 5
gates: 4
depth: 2
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}