[wip] Feature/measure v2 scan nd#8117
Open
jenshnielsen wants to merge 5 commits into
Open
Conversation
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 <[email protected]>
Co-authored-by: Copilot <[email protected]>
Introduces scan_nd(*sweeps, measured=[...]) for nested multi-dimensional scans, the highest-value gap vs dond/do2d/doNd. Sweeps are outermost-first ordered; at each innermost setpoint the plan reads all measured parameters and emits one dataset row. Per-sweep delay and get_after_set are honored. Cleanup contract extends scan_1d's: on exit (success, error, or cancel) every swept parameter is set to 0.0, in outer-to-inner order, with the engine dispatching each cleanup Set before publishing RunStopped. scan_1d is refactored as a thin delegate to scan_nd (single-sweep case). get_after_set support — deferred from the tracer bullet — is now honored in both, inserting a Read of the swept parameter immediately after Set so the dataset row reflects the actual instrument readback. The convenience entrypoint qc.measure_v2.scan(*sweeps, measure=[...]) now accepts any number of sweeps and dispatches accordingly. The previous NotImplementedError for multi-sweep usage is removed. 20 new tests across L1 (message-stream), L2 (engine + MemorySink), and L3 (engine + SqliteSink) levels. All 70 measure_v2 tests pass. Co-authored-by: Copilot <[email protected]>
Walks through qcodes.measure_v2 end-to-end with executable examples: 1. Setup (temp database, software-only parameters) 2. Simple 1D blocking scan via qc.measure_v2.scan() 3. Non-blocking submission with wait=False; peeking partial data 4. Cancellation with verified cleanup (g ramps back to 0) 5. 2D scan via scan_nd 6. Writing a custom plan-builder (bisection search) with try/finally 7. Custom sinks: MemorySink for inspection, plain-function sink for live progress 8. Unit-testing plan-builders without an engine (drive_plan helper) 9. Caveats and v1 backlog All cells executed; the cancel-safety guarantee and bisection convergence are demonstrated with real output values in the saved notebook. Co-authored-by: Copilot <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8117 +/- ##
==========================================
- Coverage 70.80% 70.42% -0.38%
==========================================
Files 302 312 +10
Lines 31911 32490 +579
==========================================
+ Hits 22593 22882 +289
- Misses 9318 9608 +290 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add @overload signatures to qc.measure_v2.scan() so wait=True returns DataSetProtocol | None and wait=False returns RunHandle. - Narrow Future[Any] -> Future[DataSetProtocol | None] for RunHandle.dataset and _Submission.dataset_future. Callers no longer need to cast to access .cache. - Type all test fixtures as Generator[T, None, None] (they yield, not return). - Move type-only application imports (e.g., ParameterBase) into TYPE_CHECKING blocks in test files. - Tutorial notebook: add type annotations throughout the code cells (function signatures, key variable annotations), and place type-only imports under TYPE_CHECKING. Notebook still executes end-to-end. pyright clean on src/qcodes/measure_v2 + tests/measure_v2 (0 errors). All 70 tests pass. prek hooks pass. Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.