Skip to content

Flip one selected atom

Apply a pi pulse to q0 while leaving q1 in its ground state. Then change the addressed site and phase to separate spatial selection from coherent rotation. Complete local detuning and physical units first.

This example uses two atoms 20 um apart, zero global Rabi drive and zero detuning. The local amplitude is π rad/us for 1 us, so the addressed atom receives a rotation angle π. With the initial state |00⟩ and zero phase, predict the final bitstring before running.

Specify a sparse mask

"""Drive one selected site with a coherent local Rabi term.

``SiteMask.constant`` is a sparse static selection and lowers to
register-aligned binary weights. The local amplitude and phase are consumed by
ideal evolution; ``SiteMask.piecewise`` provides the dynamic form.
"""

from __future__ import annotations

import json
import math

from cascaqit import AHSProgram, AtomRegister, LocalBackend, Waveform
from cascaqit.analog import SiteMask


def main() -> None:
    """Apply a pi pulse to q0 while q1 remains unaddressed."""
    program = (
        AHSProgram(
            AtomRegister.line(count=2, spacing=20.0),
            program_id="lesson.experimentalist.local_rabi",
        )
        .drive(
            rabi=Waveform.constant(0.0, duration=1.0),
            detuning=Waveform.constant(0.0, duration=1.0),
            phase=0.0,
        )
        .local_rabi(
            rabi=Waveform.constant(math.pi, duration=1.0),
            phase=0.0,
            pattern=SiteMask.constant(("q0",), duration=1.0),
        )
        .measure()
    )
    result = (
        LocalBackend(analog_time_steps=16).run(program, shots=32, seed=304).result()
    )
    term = program.to_ir().hamiltonian.local_rabi_terms[0]

    payload = {
        "track": "quantum_experimentalist",
        "level": "advanced",
        "lesson": "local_rabi",
        "facts": {
            "site_ids": list(term.addressing.site_ids),
            "weights": list(term.addressing.weights[0]),
            "phase": term.phase,
            "counts": result.counts,
            "selected_simulator": result.metadata["selected_simulator"],
            "addressing_frame_count": term.addressing.frame_count,
        },
        "boundaries": {
            "hardware_execution": False,
            "cloud_execution": False,
            "network_accessed": False,
            "credentials_loaded": False,
        },
    }
    print(json.dumps(payload, sort_keys=True))


if __name__ == "__main__":
    main()

Download the full script

python3 examples/user/tracks/quantum_experimentalist/04_advanced_local_rabi_en.py

SiteMask.constant(("q0",), duration=1.0) selects one site for the whole pulse. It expands to binary weights aligned with the register. The global zero-valued drive still defines the common duration; the local term adds a coherent drive on the selected site.

{
  "boundaries": {
    "cloud_execution": false,
    "credentials_loaded": false,
    "hardware_execution": false,
    "network_accessed": false
  },
  "facts": {
    "addressing_frame_count": 1,
    "counts": {
      "10": 32
    },
    "phase": 0.0,
    "selected_simulator": "ScalableIdealEngine",
    "site_ids": [
      "q0",
      "q1"
    ],
    "weights": [
      1.0,
      0.0
    ]
  },
  "lesson": "local_rabi",
  "level": "advanced",
  "track": "quantum_experimentalist"
}

The weights are [1, 0] for [q0, q1]; all 32 ideal samples are 10. This asymmetric result is a useful check of bit ordering. The geometry lies beyond the mock target's blockade radius, and no finite interaction is configured. A different geometry, nonzero detuning or additional drive would require a fresh prediction.

The backend uses 16 Analog time steps. Check probabilities as well as counts when perturbing the pulse: 32 samples can miss a small residual population. selected_simulator identifies the chosen local implementation; it is not a hardware-device identifier.

Distinguish phase from selection

A local phase changes the rotation axis in the transverse plane. It is not a random phase assigned after execution. Several local Rabi terms on one site add as coherent amplitudes, so their relative phase affects the net drive.

  1. Change the mask to ("q1",). Predict the output and verify the aligned weights.
  2. Restore q0 and change the pulse phase to math.pi. Does its Z-basis population reveal the sign change of this single pi rotation?
  3. Restore phase zero and append a second local Rabi term on q0 with identical amplitude and duration but phase math.pi. Predict the net drive before running.
Check your reasoning

Addressing q1 gives weights [0, 1] and ideal outcome 01. A single pi pulse with phase π still gives 10; its phase effect is not visible in these final populations. Two equal simultaneous terms with opposite phase cancel their transverse amplitudes, leaving 00 in this zero-detuning control. Do not add their pulse areas as unsigned positive numbers. Relative phases require coherent reasoning even when the final measurement is in Z.

A SiteMask accepts known filled site IDs; unknown or vacant sites are errors. SiteMask.piecewise() can change the selected set at explicit numeric frame times with step interpolation. Continuous mask interpolation and parameterized frame topology are not supported. See the local-Rabi guide for additional site phase offsets and the supported control range.

Next, validate and inspect a reference compile before interpreting a program as compatible with a target.

中文版

SDK 1.0.8a · `8b227bff`