|
17 | 17 |
|
18 | 18 | from typing import Any, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING
|
19 | 19 | import numpy as np
|
20 |
| -import sympy |
21 | 20 |
|
22 | 21 | from matplotlib import pyplot as plt
|
23 | 22 |
|
24 | 23 | # this is for older systems with matplotlib <3.2 otherwise 3d projections fail
|
25 | 24 | from mpl_toolkits import mplot3d # pylint: disable=unused-import
|
26 |
| -from cirq import circuits, ops, protocols, study |
| 25 | +from cirq import circuits, ops, protocols |
27 | 26 |
|
28 | 27 | if TYPE_CHECKING:
|
29 | 28 | import cirq
|
@@ -54,52 +53,6 @@ class Cliffords:
|
54 | 53 | s1_y: List[List[ops.Gate]]
|
55 | 54 |
|
56 | 55 |
|
57 |
| -class RabiResult: |
58 |
| - """Results from a Rabi oscillation experiment.""" |
59 |
| - |
60 |
| - def __init__(self, rabi_angles: Sequence[float], excited_state_probabilities: Sequence[float]): |
61 |
| - """Inits RabiResult. |
62 |
| -
|
63 |
| - Args: |
64 |
| - rabi_angles: The rotation angles of the qubit around the x-axis |
65 |
| - of the Bloch sphere. |
66 |
| - excited_state_probabilities: The corresponding probabilities that |
67 |
| - the qubit is in the excited state. |
68 |
| - """ |
69 |
| - self._rabi_angles = rabi_angles |
70 |
| - self._excited_state_probs = excited_state_probabilities |
71 |
| - |
72 |
| - @property |
73 |
| - def data(self) -> Sequence[Tuple[float, float]]: |
74 |
| - """Returns a sequence of tuple pairs with the first item being a Rabi |
75 |
| - angle and the second item being the corresponding excited state |
76 |
| - probability. |
77 |
| - """ |
78 |
| - return [(angle, prob) for angle, prob in zip(self._rabi_angles, self._excited_state_probs)] |
79 |
| - |
80 |
| - def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes: |
81 |
| - """Plots excited state probability vs the Rabi angle (angle of rotation |
82 |
| - around the x-axis). |
83 |
| -
|
84 |
| - Args: |
85 |
| - ax: the plt.Axes to plot on. If not given, a new figure is created, |
86 |
| - plotted on, and shown. |
87 |
| - **plot_kwargs: Arguments to be passed to 'plt.Axes.plot'. |
88 |
| - Returns: |
89 |
| - The plt.Axes containing the plot. |
90 |
| - """ |
91 |
| - show_plot = not ax |
92 |
| - if not ax: |
93 |
| - fig, ax = plt.subplots(1, 1, figsize=(8, 8)) |
94 |
| - ax.set_ylim([0, 1]) |
95 |
| - ax.plot(self._rabi_angles, self._excited_state_probs, 'ro-', **plot_kwargs) |
96 |
| - ax.set_xlabel(r"Rabi Angle (Radian)") |
97 |
| - ax.set_ylabel('Excited State Probability') |
98 |
| - if show_plot: |
99 |
| - fig.show() |
100 |
| - return ax |
101 |
| - |
102 |
| - |
103 | 56 | class RandomizedBenchMarkResult:
|
104 | 57 | """Results from a randomized benchmarking experiment."""
|
105 | 58 |
|
@@ -216,45 +169,6 @@ def plot(self, axes: Optional[List[plt.Axes]] = None, **plot_kwargs: Any) -> Lis
|
216 | 169 | return axes
|
217 | 170 |
|
218 | 171 |
|
219 |
| -def rabi_oscillations( |
220 |
| - sampler: 'cirq.Sampler', |
221 |
| - qubit: 'cirq.Qid', |
222 |
| - max_angle: float = 2 * np.pi, |
223 |
| - *, |
224 |
| - repetitions: int = 1000, |
225 |
| - num_points: int = 200, |
226 |
| -) -> RabiResult: |
227 |
| - """Runs a Rabi oscillation experiment. |
228 |
| -
|
229 |
| - Rotates a qubit around the x-axis of the Bloch sphere by a sequence of Rabi |
230 |
| - angles evenly spaced between 0 and max_angle. For each rotation, repeat |
231 |
| - the circuit a number of times and measure the average probability of the |
232 |
| - qubit being in the |1> state. |
233 |
| -
|
234 |
| - Args: |
235 |
| - sampler: The quantum engine or simulator to run the circuits. |
236 |
| - qubit: The qubit under test. |
237 |
| - max_angle: The final Rabi angle in radians. |
238 |
| - repetitions: The number of repetitions of the circuit for each Rabi |
239 |
| - angle. |
240 |
| - num_points: The number of Rabi angles. |
241 |
| -
|
242 |
| - Returns: |
243 |
| - A RabiResult object that stores and plots the result. |
244 |
| - """ |
245 |
| - theta = sympy.Symbol('theta') |
246 |
| - circuit = circuits.Circuit(ops.X(qubit) ** theta) |
247 |
| - circuit.append(ops.measure(qubit, key='z')) |
248 |
| - sweep = study.Linspace(key='theta', start=0.0, stop=max_angle / np.pi, length=num_points) |
249 |
| - results = sampler.run_sweep(circuit, params=sweep, repetitions=repetitions) |
250 |
| - angles = np.linspace(0.0, max_angle, num_points) |
251 |
| - excited_state_probs = np.zeros(num_points) |
252 |
| - for i in range(num_points): |
253 |
| - excited_state_probs[i] = np.mean(results[i].measurements['z']) |
254 |
| - |
255 |
| - return RabiResult(angles, excited_state_probs) |
256 |
| - |
257 |
| - |
258 | 172 | def single_qubit_randomized_benchmarking(
|
259 | 173 | sampler: 'cirq.Sampler',
|
260 | 174 | qubit: 'cirq.Qid',
|
|
0 commit comments