qml.resource.substitute

substitute(initial_resources, gate_info, replacement)[source]

Replaces a specified gate in a Resources object with the contents of another Resources object.

Parameters
  • initial_resources (Resources) – the Resources object to be modified

  • gate_info (Iterable(str, int)) – sequence containing the name of the gate to be replaced and the number of wires it acts on

  • replacement (Resources) – the Resources containing the resources that will replace the gate

Returns

the updated Resources after substitution

Return type

Resources

Example

First we build the Resources.

from pennylane.measurements import Shots
from pennylane.resource import Resources

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

# the RX gates will be replaced by the substitution
gate_info = ("RX", 1)

replacement = Resources(
    num_wires = 1,
    num_gates = 7,
    gate_types = {"Hadamard": 3, "S": 4},
    gate_sizes = {1: 7},
    depth = 7
)

Now we print the result of the substitution.

>>> res = qml.resource.substitute(initial_resources, gate_info, replacement)
>>> print(res)
wires: 2
gates: 15
depth: 9
shots: Shots(total=10)
gate_types:
{'CNOT': 1, 'H': 6, 'S': 8}
gate_sizes:
{1: 14, 2: 1}