Repository navigation
Add parameter observers notified of every get and set - #8684
Open
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 4 commits into
Open
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 4 commits into
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 4 commits into
Conversation
Add qcodes.parameters.add_parameter_observer, remove_parameter_observer and the observe_parameters context manager. An observer is called with a ParameterAccess after every get and set of every parameter, describing the parameter, value, raw value, start time, duration and any exception. A set that ramps in steps is reported once per step. Any number of observers can be registered, independently of on_set_callback and global_on_set_callback. This makes it possible to record all instrument communication made by a piece of code without changing it or the drivers it uses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Jens Hedegaard Nielsen (jenshnielsen)
requested a review
from a team
as a code owner
October 28, 2026 09:46
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8684 +/- ##
==========================================
+ Coverage 75.02% 75.12% +0.09%
==========================================
Files 307 308 +1
Lines 32511 32639 +128
==========================================
+ Hits 24392 24519 +127
- Misses 8119 8120 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Show how to record the parameter accesses of a block of code with observe_parameters, what a ParameterAccess contains, that ramped sets are reported per step and failed accesses with their exception, how to see what a measurement did to the instruments, and how to register an observer for longer with add_parameter_observer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Jens Hedegaard Nielsen (jenshnielsen)
force-pushed
the
jenshnielsen/parameter_observers
branch
from
October 28, 2026 10:24
0b8570b to
ddba642
Compare
Aaron Smull (asmull)
approved these changes
Oct 28, 2026
Contributor
|
If you're worried about making this too general and abusable, one thing you could do is for now restrict the observer to be a concrete type that just appends to a list. Or maybe that and logging, to avoid the full general callback-like behavior. |
Replace the parameter observer API (add_parameter_observer and friends) with recording that can only store what happened, so that it cannot be used as a callback, for example to set one parameter in reaction to another: - record_parameter_accesses() appends each access to a plain list (subclasses are refused, so append cannot be overridden); log_parameter_accesses() logs them to the qcodes.parameters.parameter_access logger instead. No user code runs while a parameter is accessed. - A ParameterAccess holds data only: the names of the parameter and its root instrument, the value, raw value, unit, timing and a description of any error, but not the parameter, instrument or exception. - Recording is local to the context it was started in (thread or asyncio task), held in a ContextVar, and can be nested. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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.
Add qcodes.parameters.add_parameter_observer, remove_parameter_observer and the observe_parameters context manager. An observer is called with a ParameterAccess after every get and set of every parameter, describing the parameter, value, raw value, start time, duration and any exception. A set that ramps in steps is reported once per step. Any number of observers can be registered, independently of on_set_callback and global_on_set_callback.
This makes it possible to record all instrument communication made by a piece of code without changing it or the drivers it uses.