Metadata-Version: 2.4
Name: tergite-chipcal
Version: 0.2.0
Summary: A simulated superconducting-qubit chip-calibration environment for LLM agents
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/tergite/tergite-chipcal
Project-URL: Repository, https://github.com/tergite/tergite-chipcal
Project-URL: Issues, https://github.com/tergite/tergite-chipcal/issues
Project-URL: Dataset, https://huggingface.co/datasets/tergite/tergite-chipcal
Keywords: reinforcement-learning,llm-agents,quantum-computing,superconducting-qubits,calibration,benchmark,tergite
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Requires-Dist: scipy>=1.11
Requires-Dist: xarray>=2023.1
Requires-Dist: matplotlib>=3.8
Provides-Extra: llm
Requires-Dist: openai>=1.0; extra == "llm"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# tergite-chipcal

**Calibrate a simulated superconducting-qubit chip, end to end, from first light to CZ gates.**

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="docs/leaderboard-2q1c-dark.svg">
  <img alt="tergite-chipcal 2q1c leaderboard: chips calibrated with 95 % CI for every entry, beside the physics ceiling" src="docs/leaderboard-2q1c-light.svg">
</picture>

The [leaderboard](LEADERBOARD.md) on the 2q1c tier. Generated from the submissions by `python scripts/leaderboard.py render`.

tergite-chipcal is a multi-turn environment for LLM agents and RL, built on a physics simulator of fixed-frequency
transmons joined by flux-tunable couplers. An episode hands the agent an uncharacterised chip. The agent must
first find every qubit's readout resonator and transition frequencies, then calibrate a CZ gate on every coupler.
Its tools are the measurements an experimentalist would use: spectroscopy, parametrization maps, chevrons, Ramsey
phase scans and randomized benchmarking. Each measurement costs simulated lab time, and the result comes back as
finite-shot data and a plot.

The score is a final randomized benchmark of the gates the agent leaves committed. The only way to score well is
to build a good CZ gate.

> **Physics model v0.1, not validated against hardware.** See [docs/physics.md](docs/physics.md) for what is
> modelled and what is simplified. Built with the help of AI coding assistants.

**It needs a vision-language model.** After each measurement the agent receives a plot of the data as an image.
For a text-only model, pass `--text-only` (or `--env.taskset.visual false` with `vf-eval`); a text
analysis of the same data then replaces the plot. To see exactly what a model receives, export it without a
model ([below](#see-what-the-model-sees)).

**What makes it different**
- **Procedural, as big and as hard as you want.** Every seed is a new chip. Beyond the three benchmark tiers,
  any name like `12q-extreme` is a procedural tier: up to 64 qubits, as a grid on multiplexed feedlines, at
  three difficulty presets ([below](#procedural-chips)). The training distribution never runs out.
- **Solvable by construction.** A privileged oracle certifies that every coupler of every benchmark chip admits a
  CZ fidelity of at least 0.96 (0.975 on 2q1c, where it searches four CZ routes). Each chip ships with its
  ceiling, and results are reported against it. The ceiling is a lower bound ([docs/scoring.md](docs/scoring.md)).
- **A verifiable reward.** Hidden device parameters never reach the agent, its own benchmarks do not count, and
  degenerate policies score 0 ([docs/scoring.md](docs/scoring.md)).
- **An open, checkable leaderboard.** Entries are pull requests carrying every episode's actions; the simulator
  is deterministic, so CI replays them to confirm the scores ([LEADERBOARD.md](LEADERBOARD.md)).
- **A real calibration workflow.** The measurement nodes and the CZ calibration chain follow the
  [tergite-autocalibration](https://github.com/tergite/tergite-autocalibration) repository. The simulator started
  from the pulse-level simulator in [tergite-backend](https://github.com/tergite/tergite-backend); its Hamiltonian
  was extended to three-level transmons in a qubit-coupler-qubit system.

| Tier | Chip | Couplers | Turn cap |
|---|---|---|---|
| `2q1c` | 2 qubits | 1 | 150 |
| `3q2c` | 3 qubits | 2 | 250 |
| `5q4c` | 5 qubits | 4 | 400 |
| `<n>q-<difficulty>` | 2–64 qubits: a chain up to 5, a grid beyond | chain n − 1; 2×5 grid 13 | 50 + 100 per coupler |

## Install

```bash
pip install tergite-chipcal              # numpy, scipy, xarray, matplotlib
pip install "tergite-chipcal[llm]"       # + openai, for running a model
```

The distribution is `tergite-chipcal`; the Python package is imported as `chipcal`. The scripts in `scripts/` and the
frozen chip files in `data/` come with a clone of this repository (`pip install -e ".[llm,test]"`); the chips are
also on Hugging Face as [tergite/tergite-chipcal](https://huggingface.co/datasets/tergite/tergite-chipcal).

## Run a model

Serve a vision-language model behind any OpenAI-compatible endpoint (for example vLLM), then:

```bash
python -m chipcal.run --tier 2q1c --seed 3000000 --out runs/demo \
    --base-url http://127.0.0.1:8000/v1 --model Qwen/Qwen3.8-27B
python -m chipcal.run ... --text-only        # a text-only model: text analysis instead of plots
```

`runs/demo/transcript.json` holds every turn, `runs/demo/run.json` holds the score, and `runs/demo/vision/`
holds every plot the model was shown.

To run on your own machine instead, [docs/local-ollama.md](docs/local-ollama.md) serves Qwen3.8 with vision
through Ollama and starts an episode against it.

This runner sends the model the system prompt and one self-contained observation per turn. The observation
carries the committed configuration, a measurement notebook and the session history. Actions are JSON in
text, with guided decoding against the action schema when the server supports `response_format`.

### Prime Intellect Environments Hub / verifiers

`environments/tergite_chipcal_env` is a verifiers (v1) environment. The environment plays the user's side of the
conversation: the first user turn is the full observation, and later turns are compact updates plus the plot
of the latest measurement.

```bash
prime env install tergite/tergite-chipcal-env       # from the Hub; or: pip install -e environments/tergite_chipcal_env
vf-eval tergite-chipcal-env -m <model> --env.taskset.tier 2q1c --env.taskset.n-chips 30
```

The reward is `chip_score`, the score below. The metrics also report the score / ceiling, the true minimum
fidelity, success, discovery accuracy, invalid-action rate, parse-failure rate and lab time. On the test split of
a named tier the tasks are the frozen benchmark chips.

### See what the model sees

`scripts/export_observations.py` plays an episode with the scripted calibration routine, or replays a recorded
transcript, and writes the model's input turn by turn without a model or a GPU: `system_prompt.txt`, one
`turn_NNN.txt` per turn and the PNG attached to it.

```bash
python scripts/export_observations.py --tier 2q1c --seed 3000000 --out runs/seen
python scripts/export_observations.py --tier 8q-hard --seed 1000042 --max-turns 40 --out runs/seen-8q
python scripts/export_observations.py --replay runs/demo/transcript.json --tier 2q1c --seed 3000000 --out runs/replay
```

## Procedural chips

The three benchmark tiers are three points on a dial. A tier name `<n>q-<difficulty>` turns the dial: n qubits
(2 to 64) from the same physical prior, at one of three presets. Up to 5 qubits the chip is a chain. Beyond, it is a
grid: each row is one readout feedline of at most 5 qubits, couplers join neighbours along each row and between
rows, and the qubit frequencies alternate as a checkerboard so every coupled pair is detuned. `10q-hard` is a
2×5 grid with 13 couplers.

| Preset | Qubit–coupler g | Weak links | Flux crosstalk (nearest neighbour) | Readout error | T1 | Min CZ detuning |
|---|---|---|---|---|---|---|
| `nominal` | 27–72 MHz | – | 0.5–1 % | 1–5 % | 15–110 µs | 100 MHz |
| `hard` | 20–50 MHz | 25 % redrawn at 12–20 MHz | 1–2 % | 3–8 % | 15–60 µs | 80 MHz |
| `extreme` | 15–40 MHz | 50 % redrawn at 9–15 MHz | 2–4 % | 5–12 % | 10–40 µs | 60 MHz |

Weak couplings narrow and slow the CZ window, so a gate fights decoherence. Stronger crosstalk means re-biasing one
coupler detunes its neighbours. Worse readout and shorter T1 blur every measurement. Readout is multiplexed on
feedlines of at most 5 qubits, each with its own readout LO, so discovery stays a realistic resonator-assignment
problem at any size. A procedural tier allows 50 turns plus 100 per coupler, and 2 h of lab time per coupler.

A procedural tier name works wherever a tier name does:

```bash
python -m chipcal.run --tier 12q-hard --seed 1000042 --out runs/12q --base-url ... --model ...
vf-eval tergite-chipcal-env -m <model> --env.taskset.tier 8q-extreme --env.taskset.split train
python scripts/generate_chips.py --tier 8q-hard --n 50 --out chips          # 50 chips, full parameters
python scripts/generate_chips.py --tier 6q-hard --n 10 --min-ceiling 0.96 --workers 32 --out chips   # certified
python scripts/evaluate.py --policy scripted --tier 8q-hard --data chips --n 10 --out results/8q
```

Harder presets can produce chips whose physics allows no 0.95 gate. `--min-ceiling` runs the privileged oracle on
every coupler (about 25 CPU-minutes each) and keeps only chips that can be calibrated, as the benchmark does.

> **Experimental:** `hard` and `extreme` chips above 10 qubits. How many of them can be calibrated, and how the
> scripted routine copes with them, is not yet characterised. Each coupler is simulated in its own
> qubit-coupler-qubit cell, so a large chip has no spectator-qubit physics beyond flux crosstalk and frequency
> dressing ([docs/physics.md](docs/physics.md)). Exploration and reports are welcome.

## The task

**Observation.** Each turn is a text block plus, after a measurement, a PNG plot of the measured data. The
text block contains:
- turn and lab-time budget;
- the chip status;
- the committed configuration of every coupler, with all six fields shown;
- the discovery state (design frequencies, local-oscillator bands, committed frequencies);
- the measurement limits;
- the last event;
- a notebook of empirical fits.

Hidden device parameters never appear.

**Actions.** One JSON object per turn:

```json
{"configure_lo": {"channel": "readout", "frequency_hz": 6.8e9}}
{"qubit": "q0", "node": "resonator_spectroscopy", "sweeps": {"frequencies": [6.8e9, 4.5e8, 401]}, "shots": 512}
{"qubit": "q0", "commit_frequency": {"transition": "f01", "frequency_hz": 4.19e9}}
{"coupler": "c0", "node": "cz_chevron", "sweeps": {"cz_pulse_frequencies": [2.1e8, 8e6, 21], "cz_pulse_durations": [2.2e-7, 4e-7, 26], "cz_pulse_amplitude": 0.5}, "shots": 128}
{"coupler": "c0", "commit": {"param": "cz_pulse_duration", "value": 2.4e-7}}
{"coupler": "c0", "benchmark": true}
{"stop": true}
```

Sweeps are `[center, full_span, point_count]` in SI units. A value in the wrong unit (for example 220 ns written
as 2.2e2 or 2.2e8 instead of 2.2e-7) is rejected with the expected unit stated. Other out-of-range values are
clamped, and the agent is told so. Invalid actions are shown back to the agent and cost a turn, with no score penalty.

The measurement nodes and committed quantities follow the vocabulary of the open-source tergite-autocalibration
tool:
- discovery: `resonator_spectroscopy`, `qubit_01_spectroscopy`, `qubit_12_spectroscopy`;
- coupler: `coupler_dc_spectroscopy`, `cz_parametrization`, `cz_chevron`, `cz_calibration`, `cz_local_phases`;
- single-qubit: `qubit_spectroscopy`, `qubit_t1`, `qubit_ramsey`, `readout_calibration`;
- `benchmark` (interleaved RB).

The prompt states the task, the score, the grammar, the units and what each node does. It contains no
calibration strategy.

**Score.** When the episode ends (stop, turn cap or lab-time budget), the environment runs one final
interleaved randomized benchmark (21 random sequences, 1000 shots) of every coupler's final committed gate, at
the final bias currents:

    score = min over couplers of F_RB,   F_RB = the fitted fidelity of that final benchmark

See [docs/scoring.md](docs/scoring.md).

## Benchmark v0.2

`data/v0.2/` freezes the evaluation chips. For each tier it holds the first 100 test seeds whose every coupler
admits a CZ fidelity of at least 0.96, as certified by a privileged oracle that searches each coupler's bias and
pulse (`chipcal.baselines.oracle`). Every chip is stored with its full hidden parameters, its per-coupler ceilings
and a checksum. Check it with `python -m chipcal.splits verify data/v0.2`. Training should draw seeds from the
train split (`chipcal.tiers.SPLITS`).

v0.2 keeps the chips of v0.1 and recomputes the 2q1c ceilings with a full search: both CZ routes (|11⟩ ↔ |20⟩ and
|11⟩ ↔ |02⟩), their half tones, the coupler's whole flux range (qubit–coupler hybridization at most 2 %) and the
environment's full pulse range. Every 2q1c chip admits a gate of at least 0.975 (median 0.992). 3q2c and 5q4c keep
the v0.1 search for now. Episodes run on v0.1 are episodes on the same chips; `data/v0.1/` stays published.

So the 0.95 calibration bar is reachable on every benchmark chip. **Entries are ranked by calibration rate**: the
fraction of chips whose every final gate reaches F ≥ 0.95. The mean score is reported beside it, along with
**score / ceiling**: each final gate against the best gate the oracle found for its coupler. The ceiling is a lower
bound on what the physics allows, and a policy can exceed it ([docs/scoring.md](docs/scoring.md)).

Reported results are for the **2q1c** tier: 2 qubits and 1 coupler, starting from full discovery. The 3q2c
and 5q4c tiers ship as harder settings with the same score.

| Policy (2q1c) | Chips × samples | Calibrated (every final F ≥ 0.95), 95 % CI | Min final-RB F, mean (95 % CI) | Score / ceiling | Parse failures / turn |
|---|---|---|---|---|---|
| [Gemma 4 31B + calibration playbook](leaderboard/submissions/2026-10-30-gemma-4-31b-it-playbook) (guided)<sup>§</sup> | 100 × 1 | **64 / 100** (54–73 %) | 0.821 (0.765–0.874) | 0.828 | 0.000 |
| Scripted calibration routine | 100 × 1 | **44 / 100** (35–54 %) | 0.853 (0.807–0.892) | 0.860 | – |
| [Gemma 4 31B](leaderboard/submissions/2026-10-29-gemma-4-31b-it) (base of Ising 1.5), no strategy prompt<sup>‡</sup> | 10 × 1 | **2 / 10** (6–51 %) | 0.437 (0.221–0.653) | 0.440 | 0.000 |
| [Qwen3.8-27B](leaderboard/submissions/2026-10-23-qwen3.8-27b-pilot), no strategy prompt<sup>†</sup> | 10 × 1 | **0 / 10** (0–28 %) | 0.315 (0.250–0.445) | 0.318 | 0.006 |
| [NVIDIA Ising Calibration 1.5](leaderboard/submissions/2026-10-29-ising-calibration-1.5) (31B), no strategy prompt, score pending: no reasoning tokens produced<sup>‡</sup> | 10 × 1 | **0 / 10** (0–28 %) | 0.000 (0.000–0.000) | 0.000 | 0.000 |
| Discovery, then a blind default gate | 100 × 1 | **0 / 100** (0–4 %) | 0.255 (0.250–0.266) | 0.257 | – |
| Random valid actions | 100 × 1 | **0 / 100** (0–4 %) | 0.000 (0.000–0.000) | 0.000 | – |
| Stop immediately | 100 × 1 | **0 / 100** (0–4 %) | 0.000 (0.000–0.000) | 0.000 | – |
| *Physics ceiling (privileged oracle, full search; a lower bound)* | *100* | *100 / 100* | *median 0.992 (0.975–0.997)* | *1* | – |

Every row runs on all 100 chips except three models, which ran on the first 10: Qwen3.8-27B, Gemma 4 31B without
the playbook, and Ising Calibration 1.5. The
[leaderboard](LEADERBOARD.md) holds the verified entries; [leaderboard/README.md](leaderboard/README.md) explains
how to submit one.
Every chip can be calibrated, yet the best entry calibrates 64 of 100 and the scripted routine 44: the gap to the
ceiling is the agent's, not the physics'. The two rankings disagree on purpose: the playbook entry calibrates 20
more chips but has the lower mean, because its misses are broken gates (0 or 0.25) where the scripted routine
leaves mediocre ones ([docs/scoring.md](docs/scoring.md)). The scripted routine reads only its own measurements; its search ranges were tuned on
chips of this simulator's distribution.

`python scripts/evaluate.py --summarize results/...` regenerates the table from the episode logs.

<sup>†</sup> **Note on the Qwen row.** The model's score can be raised substantially by putting a calibration guideline
in the system prompt, i.e. the physics and the order of the calibration chain, pasted in as extra knowledge.
The rows marked "no strategy prompt" measure the raw model's ability to calibrate from the task description
alone; the guided row (§) shows what such a prompt does. To run your own ablation, pass a text file with
`--prompt-addendum` to `scripts/evaluate.py`.
Every turn of the run (prompt state, model output including its thinking, action and environment response) is
on Hugging Face ([transcripts](https://huggingface.co/datasets/tergite/tergite-chipcal-runs/tree/main/2q1c/2026-10-23-qwen3.8-27b-pilot)).
Its first 8 chips ran on pre-release code and the last 2 on v0.1.1; all its actions, in the linked leaderboard
folder, replay to the recorded scores on v0.1.1.

<sup>‡</sup> **Note on the Ising Calibration 1.5 row: the score is pending.** The model produced no reasoning tokens,
and we will rerun it if a version or setting that reasons becomes available. It ran in the same harness as
Qwen, with thinking switched on and a 4096-token thinking budget (vision on, temperature 0.2 as on its model card,
[`nvidia/Ising-Calibration-1.5-31B-BF16`](https://huggingface.co/nvidia/Ising-Calibration-1.5-31B-BF16)), but on
every turn its thought channel was empty and it answered at once. This is the model, not the harness: served
identically, its base model Gemma 4 31B thinks at length on the same prompts, and Ising Calibration 1.5 closes the
thought channel at once even when the channel is opened for it. Run on the same 10 chips with
identical settings, the base Gemma 4 31B, which thinks, completed discovery on 9 of 10 chips (discovery
0.98), scored 0.437 and calibrated 2 of 10; Ising Calibration 1.5 reached discovery 0.05 and scored 0 (91 % of its
actions repeated a local-oscillator setting; it sent stop on 5 chips and ran into the turn cap on the other 5). In our runs, thinking is important for a decent
score.
Every turn of both runs (prompt state, model output including any thinking, action and environment response) is
on Hugging Face: [Gemma 4 31B](https://huggingface.co/datasets/tergite/tergite-chipcal-runs/tree/main/2q1c/2026-10-29-gemma-4-31b-it), [Ising Calibration 1.5](https://huggingface.co/datasets/tergite/tergite-chipcal-runs/tree/main/2q1c/2026-10-29-ising-calibration-1.5).
Their actions, in the linked leaderboard folders, replay to the recorded scores.

<sup>§</sup> **Note on the guided row.** The same model and settings as the raw Gemma 4 31B row, with the
maintainers' calibration playbook appended to the system prompt: an 11 kB experimentalist strategy prompt covering
the physics of each calibration stage, the order of the calibration chain and decision rules for when evidence is
ambiguous. On the 10 chips where both ran, it lifts Gemma 4 31B from 2 to 8 calibrated chips (mean 0.437 to 0.945);
on all 100 chips it calibrates 64. The playbook itself is not published; its sha256 is in the entry's `meta.json`,
and the model's thinking, which refers to it, is in the
[transcripts](https://huggingface.co/datasets/tergite/tergite-chipcal-runs/tree/main/2q1c/2026-10-30-gemma-4-31b-it-playbook).
Most misses are long episodes: all 16 broken gates (score 0 or 0.25) come from runs that used the whole 150-turn
budget. One never completed a gate; the other 15 were still changing theirs in the last turns, so the final
benchmark found it half-edited, often after a better gate had been benchmarked a few turns earlier. Other misses are charge-sensitive gates that the
final benchmark found in a different offset-charge state from the one they were tuned in
([docs/scoring.md](docs/scoring.md)).


## Physics

See [docs/physics.md](docs/physics.md) for what is modelled and simplified, and
[docs/parameters.md](docs/parameters.md) for every sampled range and its published source.
[docs/examples.md](docs/examples.md) walks through one successful calibration, turn by turn.

## Related work

This environment was inspired by NVIDIA's work on AI for quantum calibration: the QCalEval benchmark
(S. Cao et al., "QCalEval: Benchmarking Vision-Language Models for Quantum Calibration Plot Understanding",
[arXiv:2604.25884](https://arxiv.org/abs/2604.25884), 2026; [dataset](https://huggingface.co/datasets/nvidia/QCalEval))
and the NVIDIA Ising Calibration models
([Ising Calibration 1.5](https://huggingface.co/nvidia/Ising-Calibration-1.5-31B-BF16)). QCalEval asks a model to
interpret a single calibration plot; tergite-chipcal asks it to run the whole calibration of a chip, choosing each
measurement and acting on what it sees. No code, data or prompts from QCalEval or the Ising Calibration models are
used here.

## Development

Tergite is developed by a core group of collaborators. [Chalmers Next Labs AB (CNL)](https://chalmersnextlabs.se/) takes on the
role of managing and maintaining this project.

We are grateful for the collaboration of:

- [Chalmers Next Labs AB](https://chalmersnextlabs.se/) – WACQT Quantum Technology Testbed
- Chalmers University of Technology, MC2 –
  [Quantum Technology Laboratory (QTL)](https://www.chalmers.se/en/departments/mc2/research/quantum-technology/)
- Chalmers University of Technology, MC2 – [Applied Quantum Physics Laboratory (AQP)](https://github.com/aqp-mc2-chalmers)

## Acknowledgements

This project was sponsored by:

-   [Knut and Alice Wallenberg Foundation](https://kaw.wallenberg.org/en) under the [Wallenberg Center for Quantum Technology (WACQT)](https://www.chalmers.se/en/centres/wacqt/) project at [Chalmers University of Technology](https://www.chalmers.se)

## License

Apache-2.0. See [LICENSE](LICENSE).

Model and product names (such as NVIDIA Ising Calibration, Gemma and Qwen) belong to their respective owners. They
are used only to identify the work and the models referred to; no affiliation or endorsement is implied.
