-
Notifications
You must be signed in to change notification settings - Fork 317
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
Parameter.__getitem__ behavior #6080
Comments
It should indeed be deprecated see #5036
We are not planning to introduce any sweep functionality into the parameter to use with qcodes.dataset but parameters can be sweep by passing them to LinSweep and friends. This choice is made since
I however, agree that it would be great to have better validation in register_parameter to error early if setpoints is a ParameterBase subclass. A pr for that is most welcome. |
Ah, apologies for not searching for an existing issue. I don't actually use the functionality, so I'm all for keeping I can open up a PR for validation in |
@thangleiter I think we should reopen since we have only resolved this partially? Do you agree |
I guess it makes sense to keep it open for bookkeeping. The last of the examples above is indeed not fixed by #6084. |
Thinking a bit more about this my proposed solution is.
|
Parameter
s can be indexed to returnSweepFixedValues
. This is a handy shortcut if you know it exists and use it correctly. However, it can lead to extremely unpredictable behavior when parameters are used in the wrong context, for example if aParameter
is passed to a function that expects an Iterable.The function might try to convert the Iterable to a list and calls
list(param)
, which runs forever if the parameter's validator passes all positive integers. In my opinion, this is very unhandy behavior and not worth the syntactic sugar of writingparam[:10]
instead of having a method that achieves the same thing without the unintended consequences of makingParameter
iterable.An example, where the unassuming user passes a Parameter instead of a sequence of parameters as setpoints to
Measurement.register_parameter
:For
ParameterWithSetpoints
,register_parameter
ends up trying to convert the argument to a list:In this case, it would even be cumbersome to check in
_register_parameter_with_setpoints()
ifsetpoints
is the correct type, i.e., , becauseiter(setpoints)
works even if setpoints is aParameter
! (*Well,Parameter
is not an instance ofSequence
, so not too cumbersome.)Also runs forever:
My proposal is therefore to deprecate
Parameter.__getitem__
and instead introduce a method likeParameter.sweep(keys: int | slice)
or even mirrorxarray
and call itParameter.iloc
or something.The text was updated successfully, but these errors were encountered: