Skip to content

Commit ea5fb9d

Browse files
tanujkhattarrht
authored andcommitted
Add benchmarks for parameter resolution (quantumlib#5864)
* Add benchmarks for parameter resolution * Address feedback
1 parent a2cdd32 commit ea5fb9d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

benchmarks/parameter_resolution.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2022 The Cirq Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import random
16+
import numpy as np
17+
import sympy
18+
import cirq
19+
20+
21+
class RabiCalibration:
22+
params = ([50, 100, 150, 200], [20, 40, 60, 80, 100])
23+
param_names = ["num_qubits", "num_scan_points"]
24+
25+
def setup(self, num_qubits: int, _):
26+
qubits = cirq.GridQubit.rect(1, num_qubits)
27+
self.symbols = {q: sympy.Symbol(f'a_{q}') for q in qubits}
28+
self.circuit = cirq.Circuit(
29+
[cirq.X(q) ** self.symbols[q] for q in qubits], cirq.measure_each(*qubits)
30+
)
31+
self.qubit_amps = {q: random.uniform(0.48, 0.52) for q in qubits}
32+
33+
def time_parameter_resolution(self, _, num_scan_points: int):
34+
for diff in np.linspace(-0.3, 0.3, num=num_scan_points):
35+
resolver = {self.symbols[q]: amp + diff for q, amp in self.qubit_amps.items()}
36+
_ = cirq.resolve_parameters(self.circuit, resolver)

check/asv_run

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
cd "$(dirname "${BASH_SOURCE[0]}")"
1212
cd "$(git rev-parse --show-toplevel)"
1313

14-
export ASV_PYTHONPATH="$(git rev-parse --show-toplevel)/examples"
1514
asv run "$@"

0 commit comments

Comments
 (0)