View on QuantumAI
|
Run in Google Colab
|
View source on GitHub
|
|
This tutorial introduces the analog experiment infrastructure in cirq_google.experimental.analog_experiments for designing, simulating, and executing continuous-time analog (and hybrid digital-analog) experiments on Google's superconducting quantum processors.
Unlike purely digital quantum computing—where algorithms are decomposed into discrete quantum gates—analog experiments follow a trajectory-based workflow:
- Define the trajectory (
AnalogTrajectory): Specify the time-dependent frequency detuning paths for the qubits and coupling strengths for the couplers. - Circuit generation (
GenericAnalogCircuitBuilder/AnalogSimulationCircuitBuilder): Translate the physical frequency and coupling trajectories into hardware control gates (AnalogDetuneQubit,AnalogDetuneCouplerOnly, andWaitGateWithUnit) or into a Trotterized circuit of standard Cirq gates for noiseless simulation. - Execution and analysis: Combine the analog evolution block with digital state-preparation and measurement gates, run the circuit on a simulator or Quantum Engine processor, and analyze the measurement outcomes.
The effective Hamiltonian and parameter conventions
During an analog experiment, the qubits evolve in the rotating frame of a common reference (interaction) frequency. Expressed directly in terms of the linear qubit detuning frequencies \(f_i(t)\) and linear nearest-neighbor coupling strengths \(g_{ij}(t)\) passed to AnalogTrajectory, the effective Hamiltonian in the single-qubit computational subspace is:
\[ \frac{H(t)}{2\pi\hbar} = \sum_{\langle i, j \rangle} g_{ij}(t) \frac{X_i X_j + Y_i Y_j}{2} + \sum_i f_i(t) \hat{n}_i = \sum_{\langle i, j \rangle} g_{ij}(t) \frac{X_i X_j + Y_i Y_j}{2} - \frac{1}{2} \sum_i f_i(t) Z_i + \mathrm{const.} \]
where \(\langle i, j \rangle\) denotes pairs of adjacent qubits connected by a tunable coupler, and \(\hat{n}_i = |1\rangle\langle 1|_i = (I - Z_i)/2\) is the excitation number operator on qubit \(i\) (with eigenvalue \(0\) for \(|0\rangle\) and \(1\) for \(|1\rangle\)).
When translating between a model Hamiltonian and AnalogTrajectory parameters, keep the following conventions in mind:
- Linear vs. angular frequencies (\(2\pi\)): All frequencies \(f_i(t)\) and couplings \(g_{ij}(t)\) passed to
AnalogTrajectoryare linear frequencies specified withtunits(for example,tu.MHz), not angular frequencies (rad/s). Over a small time step \(\Delta t\) where \(H\) is constant, the unitary time-evolution operator is \(U(\Delta t) = \exp(-i H \Delta t / \hbar)\), which introduces the factor of \(2\pi\). Qubit detuning \(f_i\) vs. Pauli-\(Z\) field \(h_i\) (minus sign and factor of \(2\)): In the physics literature, the XY spin Hamiltonian is frequently written using Pauli-\(Z\) operators as:
\[ \frac{H(t)}{2\pi\hbar} = \sum_{\langle i, j \rangle} g_{ij}(t) \frac{X_i X_j + Y_i Y_j}{2} + \sum_i h_i(t) Z_i \]
Because \(Z_i = |0\rangle\langle 0|_i - |1\rangle\langle 1|_i = I - 2\hat{n}_i\), a positive detuning \(f_i > 0\) raises the energy of \(|1\rangle\) relative to \(|0\rangle\) by \(+2\pi\hbar f_i\), whereas \(+Z_i\) assigns \(+1\) to \(|0\rangle\) and \(-1\) to \(|1\rangle\) (a splitting of \(2\)). Up to a global phase, the Pauli-\(Z\) coefficient \(h_i(t)\) and the qubit detuning frequency \(f_i(t)\) are therefore related by a minus sign and a factor of \(2\):
\[ h_i(t) = -\frac{1}{2} f_i(t) \quad \Longleftrightarrow \quad f_i(t) = -2 h_i(t) \]
(or in angular frequency units, \(\omega_{Z, i} = 2\pi h_i = -\pi f_i\)).
Swap rate under \(XY\) coupling: For two resonant qubits (\(f_i = f_j = 0\)) coupled with constant strength \(g_{ij}\) for duration \(\Delta t\), the unitary evolution is \(\exp\left[-2\pi i g_{ij} \Delta t (X_i X_j + Y_i Y_j)/2\right] = \mathrm{iSWAP}^{-4 g_{ij} \Delta t}\). An excitation prepared in \(|10\rangle\) swaps completely to \(|01\rangle\) in time \(t_{\mathrm{swap} } = \frac{1}{4|g_{ij}|}\) (25 ns when \(g_{ij} = -10\) MHz) and returns to \(|10\rangle\) with period \(T = \frac{1}{2|g_{ij}|}\) (50 ns when \(g_{ij} = -10\) MHz).
Controllable parameters and hardware ranges
- Qubits (
cirq.GridQubit) and couplers (cirq_google.Coupler): Qubits on a Google processor grid are identified bycirq.GridQubit(row, col)(or shorthandcirq.q(row, col)). A tunable coupler between two nearest-neighbor qubits is represented bycirq_google.Coupler(q0, q1). - Qubit frequency detunings \(f_i(t)\): Specified in linear frequency units (
tu.MHzortu.GHz) relative to the common interaction reference frequency (0 MHz means on resonance at the reference frequency). Setting a qubit's frequency toNoneplaces it at its calibrated idle frequency, which is used before and after the analog trajectory when applying digital single-qubit gates or measurements. During the analog interaction, detunings are typically chosen within a few tens of MHz (e.g., \([-30\ \mathrm{MHz}, +30\ \mathrm{MHz}]\)) of the reference frequency. - Coupling strengths \(g_{ij}(t)\): Specified in linear frequency units (
tu.MHz). On Google superconducting processors, the tunable coupling strength is negative or zero, with an allowed hardware range of \(g_{ij}(t) \in [-10\ \mathrm{MHz}, 0\ \mathrm{MHz}]\) (i.e., \(|g_{ij}| \le 10\) MHz, where 0 MHz turns the coupling off). - Step durations \(\Delta t\): Specified with time units (
tu.ns,tu.us) or as asympy.Symbolfor parameter sweeps. To respect hardware control bandwidth and filters, ramp steps that change qubit frequencies or coupling strengths should have a duration of at least 2–3 ns.
try:
import cirq
import cirq_google
except ImportError:
print("installing cirq...")
!pip install --upgrade cirq-google
print("installed cirq.")
import cirq
import cirq_google
import matplotlib.pyplot as plt
import numpy as np
import sympy
import tunits as tu
from cirq_google.experimental import analog_experiments as aexp
Intro to classes for generating analog circuits
AnalogTrajectory: designing the frequency trajectory
To design an analog circuit, we use the AnalogTrajectory class. The time-dependent trajectories of the qubit detuning frequencies \(f_i(t)\) and coupling strengths \(g_{ij}(t)\) are defined via aexp.AnalogTrajectory.from_sparse_trajectory(sparse_trajectory, qubits=..., couplers=...).
The sparse_trajectory argument is a list of three-element tuples (duration, qubit_freq_dict, coupler_strength_dict), where each tuple describes one linear ramp (or hold) step:
duration: The duration of the step as atunits.Value(e.g.,10 * tu.ns) or asympy.Symbol.qubit_freq_dict: A dictionary mappingcirq.GridQubitobjects to their target detuning frequency at the end of the step (orNoneto return the qubit to its idle frequency). Any qubit omitted from the dictionary keeps its frequency from the previous step.coupler_strength_dict: A dictionary mappingcirq_google.Couplerobjects to their target coupling strength at the end of the step. Any coupler omitted from the dictionary keeps its coupling strength from the previous step.
For example, the tuple (50 * tu.ns, {}, {coupler: -5 * tu.MHz}) ramps coupler to -5 MHz over 50 ns while keeping all qubit frequencies and other couplers unchanged. An empty update (100 * tu.ns, {}, {}) holds all parameters constant for 100 ns.
# Let's make a simple analog trajectory on two adjacent qubits:
q0, q1 = cirq.q(5, 5), cirq.q(5, 6)
qubits = [q0, q1]
coupler = cirq_google.Coupler(q0, q1)
couplers = [coupler]
trajectory = [
# Ramp the qubits from idle (None) to resonance (0 MHz) over 10 ns
(10 * tu.ns, {q: 0 * tu.MHz for q in qubits}, {}),
# Ramp up the coupling to -5 MHz over 50 ns
(50 * tu.ns, {}, {coupler: -5 * tu.MHz}),
# Detune q(5, 5) by +10 MHz over 50 ns while ramping coupling to -10 MHz
(50 * tu.ns, {q0: 10 * tu.MHz}, {coupler: -10 * tu.MHz}),
# Hold all parameters constant for 100 ns
(100 * tu.ns, {}, {}),
# Bring qubits back to idle (None) and coupling back to 0 MHz over 3 ns
(3 * tu.ns, {q: None for q in qubits}, {c: 0 * tu.MHz for c in couplers}),
]
analog_trajectory = aexp.AnalogTrajectory.from_sparse_trajectory(
trajectory, qubits=qubits, couplers=couplers
)
# Visualize the trajectory. Note that the idle qubit frequencies (at the beginning
# and end of the trajectory when the detuning is None) are randomly generated
# for visualization; on hardware, each qubit has its own calibrated idle frequency.
ax1, ax2 = analog_trajectory.plot()

GenericAnalogCircuitBuilder: building the hardware circuit
To compile an AnalogTrajectory into a hardware-ready cirq.Circuit, use aexp.GenericAnalogCircuitBuilder. Calling make_circuit() converts each step of the trajectory into cirq_google.AnalogDetuneQubit and cirq_google.AnalogDetuneCouplerOnly ramp operations (and WaitGateWithUnit operations during hold steps with no frequency or coupling changes).
gac = aexp.GenericAnalogCircuitBuilder(analog_trajectory)
analog_pulse = gac.make_circuit()
print(analog_pulse)
c(q(5, 5),q(5, 6)): ──────────────────────────────AnalogDetuneCouplerOnly(length=50 ns, g_max=-5 MHz)───AnalogDetuneCouplerOnly(length=50 ns, g_max=-10 MHz)────────────────────────AnalogDetuneCouplerOnly(length=3 ns, g_max=0 MHz)───
(5, 5): ───────────────AnalogDetune(freq=0 MHz)───AnalogDetune(freq=0 MHz)──────────────────────────────AnalogDetune(freq=10 MHz)──────────────────────────────WaitGate(100.0 ns)───AnalogDetune(freq=None)─────────────────────────────
│
(5, 6): ───────────────AnalogDetune(freq=0 MHz)───AnalogDetune(freq=0 MHz)──────────────────────────────AnalogDetune(freq=0 MHz)───────────────────────────────#2───────────────────AnalogDetune(freq=None)─────────────────────────────
AnalogSimulationCircuitBuilder: building a circuit for simulation
Because AnalogDetuneQubit and AnalogDetuneCouplerOnly represent hardware pulse instructions rather than fixed unitary matrices, they cannot be simulated directly with cirq.Simulator. Instead, aexp.AnalogSimulationCircuitBuilder discretizes the trajectory into Trotter-Suzuki steps of duration trotter_step (with trotter_order=1 or trotter_order=2, where trotter_step must evenly divide the total trajectory duration) composed of standard cirq.ZPowGate and cirq.ISwapPowGate operations.
sim_builder = aexp.AnalogSimulationCircuitBuilder(analog_trajectory)
# Build a 3-step Trotter circuit (71 ns step divides the 213 ns total duration)
# to inspect the gate structure:
print(sim_builder.make_circuit(trotter_step=71 * tu.ns, trotter_order=1))
(5, 5): ───Z^0───iSwap─────Z^(-5/16)───iSwap────────Z^-1.42───iSwap────────
│ │ │
(5, 6): ───Z^0───iSwap^0───Z^0─────────iSwap^1.73───Z^0───────iSwap^2.84───
Warm-up example: two-qubit swap
As a concrete example, let's set up a two-qubit swap experiment between \(q_0 = \mathrm{q}(5, 5)\) and \(q_1 = \mathrm{q}(5, 6)\):
- Initialize the system in \(|10\rangle\) by applying an \(X\) gate to \(q_0\) while both qubits are at their idle frequencies.
- Ramp both qubits from idle (
None) to resonance (\(f_0 = f_1 = 0\) MHz) over 10 ns. - Ramp the coupler strength \(g\) from 0 MHz to -10 MHz over 10 ns.
- Hold the qubits on resonance at \(g = -10\) MHz for a variable wait time
t_wait(parameterized bysympy.Symbol("t_wait")). - Ramp the coupler back to 0 MHz and the qubits back to idle over 3 ns, then measure both qubits in the computational (\(Z\)) basis.
# Make trajectory for a two-qubit swap
def make_swap_trajectory(wait_time: tu.Value | sympy.Symbol) -> aexp.AnalogTrajectory:
trajectory = [
# Ramp both qubits from idle to resonance (0 MHz) over 10 ns
(10 * tu.ns, {q: 0 * tu.MHz for q in qubits}, {}),
# Ramp the coupling strength to -10 MHz over 10 ns
(10 * tu.ns, {}, {coupler: -10 * tu.MHz}),
# Hold for wait_time
(wait_time, {}, {}),
# Bring qubits back to idle (None) and coupling back to 0 MHz over 3 ns
(3 * tu.ns, {q: None for q in qubits}, {c: 0 * tu.MHz for c in couplers}),
]
return aexp.AnalogTrajectory.from_sparse_trajectory(
trajectory, qubits=qubits, couplers=couplers
)
analog_trajectory = make_swap_trajectory(sympy.Symbol("t_wait"))
# Visualize the trajectory by resolving the symbolic wait time to 100 ns
ax1, ax2 = analog_trajectory.plot(resolver={"t_wait": 100 * tu.ns})

Build the circuit
To construct the full hardware circuit, we build the analog evolution block with GenericAnalogCircuitBuilder, prepend cirq.X.on(qubits[0]) to prepare \(|10\rangle\), and append a computational-basis measurement cirq.measure(*qubits, key="z").
# Build the hardware circuit with GenericAnalogCircuitBuilder
circ = cirq.Circuit(cirq.X.on(qubits[0])) # Initialize the first qubit in |1>
gac = aexp.GenericAnalogCircuitBuilder(analog_trajectory)
analog_pulse = gac.make_circuit()
circ += analog_pulse
circ += cirq.Circuit(cirq.measure(*qubits, key="z"))
print(circ)
c(q(5, 5),q(5, 6)): ──────────────────────────────────AnalogDetuneCouplerOnly(length=10 ns, g_max=-10 MHz)──────────────────────AnalogDetuneCouplerOnly(length=3 ns, g_max=0 MHz)────────────
(5, 5): ───────────────X───AnalogDetune(freq=0 MHz)───AnalogDetune(freq=0 MHz)───────────────────────────────WaitGate(t_wait)───AnalogDetune(freq=None)─────────────────────────────M('z')───
│ │
(5, 6): ───────────────────AnalogDetune(freq=0 MHz)───AnalogDetune(freq=0 MHz)───────────────────────────────#2─────────────────AnalogDetune(freq=None)─────────────────────────────M────────
Run the circuit on hardware through Quantum Engine
Once circ is constructed, you can run the wait-time sweep on a Google quantum processor through Quantum Engine by authenticating with your Google Cloud project, creating a remote_sampler for your target processor, and calling remote_sampler.run_sweep.
The code cell below is commented out so that this tutorial can run automatically without hardware access. To run on hardware, uncomment the lines below and fill in your own gcp_proj, processor_id, config_name, and snapshot_id:
# from cirq_google.engine.qcs_notebook import authenticate_user
#
# gcp_proj = "" # Specify your GCP project ID
# processor_id = "" # Specify the processor name
# config_name = "" # Specify the device config name
# snapshot_id = "" # Specify the calibration snapshot ID
#
# authenticate_user()
# engine = cirq_google.get_engine(gcp_proj)
# remote_sampler = engine.get_sampler(
# processor_id,
# device_config_name=config_name,
# device_config_revision=cirq_google.Snapshot(snapshot_id),
# )
#
# repetitions = 5000
# wait_times = np.linspace(2, 100, 50) * tu.ns
# params = cirq.Points("t_wait", list(wait_times))
# results = remote_sampler.run_sweep(
# program=circ, params=params, repetitions=repetitions
# )
Simulate the circuit locally
Without hardware access, we can simulate the wait-time sweep locally using AnalogSimulationCircuitBuilder and cirq.Simulator (passing resolved positive tunits.Value wait times, since AnalogSimulationCircuitBuilder requires concrete positive step durations):
# Simulate the two-qubit swap sweep using AnalogSimulationCircuitBuilder
repetitions = 2000
wait_times_ns = np.linspace(2, 100, 50)
sim_circuits = []
for t_ns in wait_times_ns:
sim_builder = aexp.AnalogSimulationCircuitBuilder(make_swap_trajectory(t_ns * tu.ns))
sim_pulse = sim_builder.make_circuit(trotter_step=0.5 * tu.ns, trotter_order=2)
sim_circuits.append(
cirq.Circuit(cirq.X.on(qubits[0]))
+ sim_pulse
+ cirq.Circuit(cirq.measure(*qubits, key="z"))
)
simulator = cirq.Simulator(seed=0)
results = [simulator.run(c, repetitions=repetitions) for c in sim_circuits]
Analyze data
From the measurement bitstrings, we compute the populations \(P(|10\rangle)\) and \(P(|01\rangle)\) as a function of t_wait. At \(g = -10\) MHz, the excitation swaps coherently between \(|10\rangle\) and \(|01\rangle\) with period \(T = \frac{1}{2|g|} = 50\) ns (with the phase at t_wait = 0 offset slightly because coupling already begins during the finite 10 ns ramp-up and 3 ns ramp-down intervals).
# Analyze data: extract P(|10>) and P(|01>) vs wait time
p_10 = []
p_01 = []
for res in results:
bits = res.measurements["z"]
p_10.append(np.mean((bits[:, 0] == 1) & (bits[:, 1] == 0)))
p_01.append(np.mean((bits[:, 0] == 0) & (bits[:, 1] == 1)))
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(wait_times_ns, p_10, "o-", label=r"$P(|10\rangle)$", markersize=4)
ax.plot(wait_times_ns, p_01, "s-", label=r"$P(|01\rangle)$", markersize=4)
ax.set_xlabel("Wait time t_wait (ns)")
ax.set_ylabel("Population")
ax.set_title("Two-qubit XY swap oscillations (g = -10 MHz)")
ax.legend()
ax.grid(True, alpha=0.3)

Next steps
To see how AnalogTrajectory and GenericAnalogCircuitBuilder are used in a many-qubit research experiment on a Google quantum processor—including readout error mitigation, staggered initial fields, and two-point \(XY\) correlation analysis—see the Kibble-Zurek (KZ) experiment tutorial in ReCirq.
View on QuantumAI
Run in Google Colab
View source on GitHub