Skip to content

Conversation

samantha-ho
Copy link
Contributor

@samantha-ho samantha-ho commented Jul 29, 2025

In the Measurement.register_parameter and DataSaver.add_result methods, the explicit Parameter type is used to register and unpack implicit dependencies for the ParameterWithSetpoints. This pattern requires that new sub-classes with different internal dependencies or inferences must exist within Qcodes and these method must be modified to handle them on a case-by-case basis.

In order to support more complicated parameter interdependencies at higher-level abstractions, this PR modifies register_parameter and add_result to use new ParameterBase interfaces to perform registration and unpacking. New subclasses will then be able to use these new interfaces to register and unpack more complicated patterns.

In detail:
ParameterBase now defines new properties and methods:

  • depends_on is an order-preserving set, ParameterSet, of other ParameterBase objects it depends_on. These will be automatically added to the InterDependencies dependency tree upon registration. (Similar to the behavior of setpoints with ParameterWithSetpoints)
  • is_controlled_by is a set of parameters which use the inferred_from or basis relationship
  • has_control_of is a set with the reverse direction of the is_controlled_by relationship, used to find related parameters during registration
  • param_spec is a new property that returns the ParamSpecBase of a parameter. It infers the paramtype from the associated Validators and defaults to "numeric"
  • paramtype is used by param_spec and its setter ensures that a Parameter's validators match its data representation in SQLite

Measurement.register_parameter has been refactored to add a new _self_register_parameter method:

  • It automatically adds dependency and inference links in the InterDependencies based on the associated ParameterBase properties
  • Recursively calls itself on parameter objects defined as dependencies, inferences, and reverse-inferences to ensure that all related parameters are registered
  • Adds parameters to the private _registered_parameters attribute. This is then passed to the DataSaver via the Runner
  • Setting paramtype kwarg to register_parameter now modifies the Validator of the Parameter to match

DataSaver.add_result has also been refactored:

  • Now allows results added via ParameterBase objects to "unpack" themselves (ie, to include related values)
  • Duplicate results are compared for approximate equality. An error is raised if multiple values are added for a parameter that do not match (implicit vs. explicit argument to add_result).
  • BREAKING CHANGE: Previously, a ParameterWithSetpoints whose setpoints values were explicitly added in add_result would use the explicit version. Now, an error is raised if the explicit values are not within some tolerance of the internal values (as with other duplication).

samantha-ho and others added 24 commits April 2, 2025 14:34
Bugfix: _numeric_values_are_equal uses the ref_array.dtype
Lookup Paramspecs from Interdeps instead of generated from Parameters
@samantha-ho samantha-ho changed the title Samanthaho/self registering parameters Allow Parameter subclasses to define and unpack their own implicit dependencies and inferences Aug 13, 2025
@samantha-ho samantha-ho marked this pull request as ready for review September 8, 2025 20:07
@samantha-ho samantha-ho requested a review from a team as a code owner September 8, 2025 20:07
Copy link
Collaborator

@jenshnielsen jenshnielsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! This is a very nice improvement. Only left a few very minor suggestions

@samantha-ho samantha-ho added this pull request to the merge queue Sep 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 26, 2025
Sign up for free to 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.

2 participants