-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add convenience methods to DelegateParameter #6832
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6832 +/- ##
==========================================
+ Coverage 69.37% 69.39% +0.01%
==========================================
Files 341 341
Lines 31381 31399 +18
==========================================
+ Hits 21771 21789 +18
Misses 9610 9610 ☔ View full report in Codecov by Sentry. |
8925230
to
23591b1
Compare
1c17998
to
3b110ea
Compare
meas.register_parameter(delegate_param, setpoints=(x_param,)) | ||
assert len(meas.parameters) == 2 | ||
assert meas.parameters["delegate"].type == "complex" | ||
assert meas.parameters["x"].type == "numeric" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets also add a test for delegate of delegate of complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A -> B -> C -> None
Add source to C
verify that A has the correct validator.
delegate_param.source.vals = None | ||
|
||
assert delegate_param.validators == (some_other_validator,) | ||
assert delegate_param.vals == some_other_validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extend to 2 delegate parameters too
This will ensure that when the validator is used to find the datatype of a parameter it can be detected correctly
0ea345c
to
d3d58bf
Compare
Moved the validators to #6865 will figure out how to integrate the test with the infer module here in a more consistent way |
@@ -0,0 +1,4 @@ | |||
``DelegateParameter`` now includes validators of its source Parameter into its validators. This ensures that a ``DelegateParameter`` | |||
with a non numeric source parameter is registered correctly in a measurement when the ``DelegateParameter`` it self does not | |||
set a validator. Furthermore `DelegateParameter`` has gained ``root_source`` and ``root_delegate`` attributes that makes it easier to get the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set a validator. Furthermore `DelegateParameter`` has gained ``root_source`` and ``root_delegate`` attributes that makes it easier to get the | |
set a validator. Furthermore ``DelegateParameter`` has gained ``root_source`` and ``root_delegate`` attributes that makes it easier to get the |
""" | ||
The root source parameter that this :class:`DelegateParameter` is bound to | ||
or ``None`` if this :class:`DelegateParameter` is unbound. If | ||
the source is it self a DelegateParameter it will recursively return that Parameter's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the source is it self a DelegateParameter it will recursively return that Parameter's | |
the source is it self a :class:`DelegateParameter`, this property will recursively return that Parameter's |
The root source parameter that this :class:`DelegateParameter` is bound to | ||
or ``None`` if this :class:`DelegateParameter` is unbound. If | ||
the source is it self a DelegateParameter it will recursively return that Parameter's | ||
source until a non DelegateParameter is found. For a non DelegateParameter source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source until a non DelegateParameter is found. For a non DelegateParameter source | |
source until a non DelegateParameter is found. If a source of this parameter is not a DelegateParameter, |
source until a non DelegateParameter is found. For a non DelegateParameter source | ||
this behaves the same as ``self.source`` | ||
|
||
:getter: Returns the current source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:getter: Returns the current source. | |
:getter: Returns the current source parameter that's at the end of a chain of DelegateParameters. |
@property | ||
def root_delegate(self) -> DelegateParameter: | ||
""" | ||
If this parameter is part of a chain of DelegateParameters return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this parameter is part of a chain of DelegateParameters return | |
If this parameter is part of a chain of DelegateParameters, return |
def root_delegate(self) -> DelegateParameter: | ||
""" | ||
If this parameter is part of a chain of DelegateParameters return | ||
the first Parameter in the chain that has a non DelegateParameter source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first Parameter in the chain that has a non DelegateParameter source | |
the first Parameter in the chain that has a non DelegateParameter source, |
self.source.validators if self.source is not None else () | ||
) | ||
|
||
return tuple(self._vals) + source_validators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wonder, if it's cleaner (and even possible) to use super here?
return tuple(self._vals) + source_validators | |
return super().validators + source_validators |
DelegateParameter
now includes validators of its source Parameter into its validators. This ensures that aDelegateParameter
with a non numeric source parameter is registered correctly in a measurement when the
DelegateParameter
it self does notset a validator. Furthermore `DelegateParameter
has gained a
root_source`` attribute that makes it easier to get theroot source of a ``DelegateParameter`` that delegates to another ``DelegateParameter``.
Alternative to #6817