qml.resource.substitute¶
- substitute(initial_resources, gate_info, replacement)[source]¶
Replaces a specified gate in a
Resources
object with the contents of anotherResources
object.- Parameters
- Returns
the updated
Resources
after substitution- Return type
Usage Details
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}
code/api/pennylane.resource.substitute
Download Python script
Download Notebook
View on GitHub