Skip to content
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

Merged
merged 5 commits into from
Jul 28, 2020
Merged

Add type hint for predefined driven control #102

merged 5 commits into from
Jul 28, 2020

Conversation

tachikoma-li
Copy link
Member

@tachikoma-li tachikoma-li commented Jul 27, 2020

Private methods like _new_*** allow rabi_rotation to be optional but they all call _predefined_common_attributes which does not allow rabi_rotation to be None.
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.

@tachikoma-li tachikoma-li marked this pull request as ready for review July 27, 2020 09:34
@tachikoma-li tachikoma-li requested review from a team and charmasaur July 27, 2020 09:34
"rabi_rotation angle must be either pi, pi/2 or pi/4",
{"rabi_rotation": rabi_rotation},
)
if rabi_rotation is not None:
Copy link
Member Author

@tachikoma-li tachikoma-li Jul 27, 2020

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:

  1. handle the None case. It seems when rabi_rotation is None, duration will also be None. However, I can't see the point of having such driven controls.
  2. does not allow 'rabi_rotation` to be optional (preferred)

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

@charmasaur charmasaur left a 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:
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

python/mypy#2400

Crazy stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed....

@tachikoma-li
Copy link
Member Author

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.

Seems we have an agreement here, I'll just make it required. Making None as default value does not make sense to me.

@tachikoma-li
Copy link
Member Author

Make rabi_rotation required and set the default value to maximum_rabi_rate as stated in the docstring.

Copy link
Contributor

@charmasaur charmasaur left a 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.
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@tachikoma-li tachikoma-li merged commit 7ff5cab into master Jul 28, 2020
@tachikoma-li tachikoma-li deleted the mypy branch July 28, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants