-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add type hint for predefined driven control #102
Conversation
"rabi_rotation angle must be either pi, pi/2 or pi/4", | ||
{"rabi_rotation": rabi_rotation}, | ||
) | ||
if rabi_rotation is not 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.
Note that this only fixes the type checking, but still has a bug when rabi_rotation
is None
. That is, theta_3
and phi_3
will not be defined if rabi_rotation
is None
(which can be fixed by moving them to the if
branch, but the there is still an issue with duration
). Same bugs below.
In the tests, rabi_rotation
was always provided and therefore missed this corner case.
Seems there are two options:
- handle the
None
case. It seems whenrabi_rotation
isNone
,duration
will also beNone
. However, I can't see the point of having such driven controls. - does not allow 'rabi_rotation` to be optional (preferred)
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.
Sorry, I missed this comment
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.
NP, this is the same issue as you commented above. Now should be fixed with making rabi_rotation required.
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.
Does it even make sense for the parameter to be optional? I would have thought we should just make it required (or, at the very least, make it optional with an explicit default). That would probably make the type checking a bit easier.
phi_p = _get_transformed_rabi_rotation_wimperis(rabi_rotation) | ||
|
||
rabi_rotations = [rabi_rotation, np.pi, 2 * np.pi, np.pi] | ||
if rabi_rotation is not 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.
Any idea why the type checker isn't picking up that line 302 could fail if rabi_rotation
is None
, since phi_p
won't get defined?
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.
Not sure. I was quite surprised to see such an obvious error just passes mypy checking.
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.
Crazy stuff.
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.
indeed....
Seems we have an agreement here, I'll just make it required. Making |
Make |
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.
LGTM, just a trivial request
rabi_rotation : float | ||
The total polar angle to be performed by the pulse. | ||
Defined in polar coordinates. | ||
maximum_rabi_rate : float | ||
Defined in polar coordinates. Defaults to 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.
Remove the comment about defaulting to 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.
done
Private methods like
_new_***
allowrabi_rotation
to be optional but they all call_predefined_common_attributes
which does not allowrabi_rotation
to beNone
.Some refactoring is done to make sure the code pass type checking.
Edit: note that this is only to fix the type issue, but does not fix the bug when user doesn't explicitly set
rabi_rotation
.