Skip to content

Commit f551b33

Browse files
committed
Rabi content has been moved to ReCirq: Delete the items in Cirq (quantumlib#5448)
Rabi Oscillations have been moved per quantumlib/ReCirq#292. Also update the intro notebook to not use now-moved recirq experiment (replaced with single_qubit_state_tomography) Also ran a formatter and cleared outputs from intro notebook Only merge with redirect cl/452988155
1 parent ef5424d commit f551b33

File tree

8 files changed

+339
-2002
lines changed

8 files changed

+339
-2002
lines changed

cirq-core/cirq/experiments/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
)
2121

2222
from cirq.experiments.qubit_characterizations import (
23-
rabi_oscillations,
24-
RabiResult,
2523
RandomizedBenchMarkResult,
2624
single_qubit_randomized_benchmarking,
2725
single_qubit_state_tomography,

cirq-core/cirq/experiments/qubit_characterizations.py

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
from typing import Any, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING
1919
import numpy as np
20-
import sympy
2120

2221
from matplotlib import pyplot as plt
2322

2423
# this is for older systems with matplotlib <3.2 otherwise 3d projections fail
2524
from mpl_toolkits import mplot3d # pylint: disable=unused-import
26-
from cirq import circuits, ops, protocols, study
25+
from cirq import circuits, ops, protocols
2726

2827
if TYPE_CHECKING:
2928
import cirq
@@ -54,52 +53,6 @@ class Cliffords:
5453
s1_y: List[List[ops.Gate]]
5554

5655

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-
10356
class RandomizedBenchMarkResult:
10457
"""Results from a randomized benchmarking experiment."""
10558

@@ -216,45 +169,6 @@ def plot(self, axes: Optional[List[plt.Axes]] = None, **plot_kwargs: Any) -> Lis
216169
return axes
217170

218171

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-
258172
def single_qubit_randomized_benchmarking(
259173
sampler: 'cirq.Sampler',
260174
qubit: 'cirq.Qid',

cirq-core/cirq/experiments/qubit_characterizations_test.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,13 @@
2222
from cirq import GridQubit
2323
from cirq import circuits, ops, sim
2424
from cirq.experiments import (
25-
rabi_oscillations,
2625
single_qubit_randomized_benchmarking,
2726
two_qubit_randomized_benchmarking,
2827
single_qubit_state_tomography,
2928
two_qubit_state_tomography,
3029
)
3130

3231

33-
def test_rabi_oscillations():
34-
# Check that the excited state population matches the ideal case within a
35-
# small statistical error.
36-
simulator = sim.Simulator()
37-
qubit = GridQubit(0, 0)
38-
results = rabi_oscillations(simulator, qubit, np.pi, repetitions=1000)
39-
data = np.asarray(results.data)
40-
angles = data[:, 0]
41-
actual_pops = data[:, 1]
42-
target_pops = 0.5 - 0.5 * np.cos(angles)
43-
rms_err = np.sqrt(np.mean((target_pops - actual_pops) ** 2))
44-
assert rms_err < 0.1
45-
46-
4732
def test_single_qubit_cliffords():
4833
I = np.eye(2)
4934
X = np.array([[0, 1], [1, 0]])

docs/tutorials/_index.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ landing_page:
4343
path: /cirq/tutorials/hidden_linear_function
4444
icon:
4545
name: menu_book
46-
- heading: Rabi oscillation experiment
47-
description: Example of using sweeps and symbols to show rotation of a qubit by different angles.
48-
path: /cirq/tutorials/rabi_oscillations
49-
icon:
50-
name: menu_book
5146
- heading: Shor's algorithm
5247
description: Factor numbers using a quantum computer.
5348
path: /cirq/tutorials/shor

0 commit comments

Comments
 (0)