-
Notifications
You must be signed in to change notification settings - Fork 17
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
Make Sweeper
pydantic Model
and introduce range
#1014
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 0.2 #1014 +/- ##
==========================================
+ Coverage 51.77% 51.86% +0.08%
==========================================
Files 58 58
Lines 2760 2765 +5
==========================================
+ Hits 1429 1434 +5
Misses 1331 1331
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
481c45e
to
4756d54
Compare
4756d54
to
5205f97
Compare
@alecandido I changed Currently from tests only |
The example in the issue was Pydantic-based. But only because I'm personally leaning towards it, it's perfectly fine to use The two motivations I see for using Pydantic are:
None of the two strict applies to the
Regarding About the docs, I'd suggest you taking a look at: Lines 21 to 24 in c180cd9
Pydantic is a perfectly valid Python compiled extension, but Sphinx is going deeper below the surface than what Python strictly guarantees, apparently (indeed, in the past, I remember to have whitelisted even NumPy or other compiled extensions - maybe there were better solutions, but it was relevant that the issue was raised). Pydantic has the added "benefit" that the BaseModel is made for subclassing. Importing the offending modules in conf.py seems to solve the issue (for unknown reasons related to the inner machinery of Sphinx)
|
src/qibolab/sweeper.py
Outdated
channels: Optional[list] = None | ||
type: Optional[SweeperType] = SweeperType.ABSOLUTE | ||
values: Optional[npt.NDArray] = None | ||
linspace: Optional[tuple[float, float, float]] = None |
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.
linspace: Optional[tuple[float, float, float]] = None | |
range: Optional[tuple[float, float, float]] = None |
?
@andrea-pasquale, @Edoardo-Pedicillo: any advice for a better name than those two?
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.
What are values
and linspace
in this case?
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.
Two different ways to define the sweeper values. values
is an array containing all the points, same as in 0.1. range
will be a tuple with three elements (start, stop, step)
and the values will be defined as np.arange(start, stop, step)
. Only one of them should be given when initializing the Sweeper
. If both are given it will raise an error.
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.
Changed in 2726f27.
I forgot to say above that the idea is that range
should be used whenever possible, as it is expected to be more efficient for most instruments. It should also be sufficient for most qibocal routines. values
is still there for special cases where non-equidistant points need to be swept for some reason.
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.
Thanks for clarifying, I would say that range
is fine.
5205f97
to
231cf10
Compare
SweeperType
Sweeper
pydantic Model
and introduce range
This should now also be ready. @alecandido what do you think about populating the actual Note that drivers can still check if a |
Possible, it's called With
We could find a better word. But there is some value in keeping a single way to access, because it would be less confusing.
This should not even happen: if a driver is capable of using (properly) the array, it should directly aim for that. And it will always be available. |
src/qibolab/sweeper.py
Outdated
if self.range is None and self.values is None: | ||
raise ValueError("Either 'range' or 'values' needs to be provided.") | ||
|
||
return self |
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 model_post_init
is only one option, and it's the one to be used when:
This is useful if you want to do some validation that requires the entire model to be initialized.
https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_post_init
And most likely this is our case.
However, even "after"
validators can do a very similar job, and, e.g., you can assign Sweeper.values
here (if None
), right after having checked that the two of them are not provided simultaneously.
Thanks @alecandido. I made the change and dropped the |
Actually, it seems that I cannot change |
b964a2f
to
916ba02
Compare
950a633
to
adbcb38
Compare
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.
I made some changes myself, to slightly simplify qibolab.sweeper
. Please, check them before merging.
Other than that, this is good to go.
Thanks @alecandido, looks good to me. I will merge when the CI passes. |
As discussed in #540 this drops the
SweeperType
from the interface.QM is not updated, but since it never supported
SweeperType
before, it will still be working same as before. Following the discussion in #540, I need to change all sweepers to behave asABSOLUTE
. I will do this in another PR.