Skip to content

[wip] Add experimental qcodes.measure_v2 package (tracer bullet) - #8116

Open
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 2 commits into
microsoft:mainfrom
jenshnielsen:feature/measure-v2-tracer
Open

[wip] Add experimental qcodes.measure_v2 package (tracer bullet)#8116
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 2 commits into
microsoft:mainfrom
jenshnielsen:feature/measure-v2-tracer

Conversation

@jenshnielsen

Copy link
Copy Markdown
Collaborator

Introduce a parallel, async-capable measurement API for QCoDeS that decouples plan description from execution. Plans are Python generators yielding typed messages (Set, Read, Sleep, Emit, OpenRun, CloseRun); a MeasurementEngine drives them on a dedicated worker thread and publishes events (RunStarted, RowEmitted, RunStopped) to pluggable sinks via a publisher thread with a bounded queue.

Key properties of the tracer-bullet implementation:

  • Non-blocking submission via engine.submit(...) returning a RunHandle with futures for the dataset and final result.
  • Cancellation via it.throw(CancelRequested) at the next yield point; plan try/finally blocks always run for safe cleanup. scan_1d guarantees a ramp-to-zero of the swept parameter on any exit path.
  • Cancel flag re-checked between .send() and dispatch to prevent one extra Set/Read leaking to hardware after cancellation.
  • handle.wait() returning guarantees data is durably committed: the publisher thread completes futures only after all sinks have processed RunStopped.
  • SqliteSink reuses existing DataSaver/Measurement infrastructure; opens its own SQLite connection on the publisher thread to satisfy check_same_thread=True. ~50 lines of integration code.
  • MemorySink for tests and lightweight in-memory consumption.

Public surface:

import qcodes as qc ds = qc.measure_v2.scan(LinSweep(g, 0, 1, 11), measure=[i])

Advanced users construct an explicit MeasurementEngine and submit plans built via run(...) + plan-builders (scan_1d, or custom generators).

Tracer scope is deliberately small: 1D scans of scalar parameters with the default SQLite sink. Multi-dim scans, Call/Describe messages, parallel reads via underlying_instrument grouping, queueing, pause/resume, live-plot/progress sinks, and a dond shim are P0-P2 for the v1 release. See src/qcodes/measure_v2/DESIGN.md for the full architecture.

50 tests across L1 (message-stream), L2 (engine + MemorySink), and L3 (engine + SqliteSink) levels. All three end-to-end acceptance scenarios pass.

Introduce a parallel, async-capable measurement API for QCoDeS that
decouples plan description from execution. Plans are Python generators
yielding typed messages (Set, Read, Sleep, Emit, OpenRun, CloseRun); a
MeasurementEngine drives them on a dedicated worker thread and publishes
events (RunStarted, RowEmitted, RunStopped) to pluggable sinks via a
publisher thread with a bounded queue.
Key properties of the tracer-bullet implementation:
- Non-blocking submission via engine.submit(...) returning a RunHandle
with futures for the dataset and final result.
- Cancellation via it.throw(CancelRequested) at the next yield point;
plan try/finally blocks always run for safe cleanup. scan_1d
guarantees a ramp-to-zero of the swept parameter on any exit path.
- Cancel flag re-checked between .send() and dispatch to prevent one
extra Set/Read leaking to hardware after cancellation.
- handle.wait() returning guarantees data is durably committed: the
publisher thread completes futures only after all sinks have
processed RunStopped.
- SqliteSink reuses existing DataSaver/Measurement infrastructure;
opens its own SQLite connection on the publisher thread to satisfy
check_same_thread=True. ~50 lines of integration code.
- MemorySink for tests and lightweight in-memory consumption.
Public surface:
import qcodes as qc
ds = qc.measure_v2.scan(LinSweep(g, 0, 1, 11), measure=[i])
Advanced users construct an explicit MeasurementEngine and submit plans
built via run(...) + plan-builders (scan_1d, or custom generators).
Tracer scope is deliberately small: 1D scans of scalar parameters with
the default SQLite sink. Multi-dim scans, Call/Describe messages,
parallel reads via underlying_instrument grouping, queueing, pause/resume,
live-plot/progress sinks, and a dond shim are P0-P2 for the v1 release.
See src/qcodes/measure_v2/DESIGN.md for the full architecture.
50 tests across L1 (message-stream), L2 (engine + MemorySink), and
L3 (engine + SqliteSink) levels. All three end-to-end acceptance
scenarios pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecovBot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.83045% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.41%. Comparing base (0a13dca) to head (c09ad89).
⚠️ Report is 477 commits behind head on main.

Files with missing linesPatch %Lines
src/qcodes/measure_v2/engine.py88.59%35 Missing ⚠️
src/qcodes/measure_v2/convenience.py71.87%9 Missing ⚠️
src/qcodes/measure_v2/sinks/sqlite.py87.14%9 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #8116 +/- ##
==========================================
- Coverage 70.80% 70.41% -0.39% 
==========================================
Files 302 312 +10 Lines 31911 32474 +563 ==========================================
+ Hits 22593 22865 +272 - Misses 9318 9609 +291 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@jenshnielsen