-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[unitaryhack] Start working on mypy errors #8187
Closed
Closed
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
2bde3a2
Start fixing mypy errors
Randl ca78f08
lint
Randl fecd5df
more type fixes, fix import error
Randl b07acd0
more type fixes, fix another import error
Randl ae1987a
additional type fixes
Randl 517011e
lint and additional type fixes
Randl 6a8adf7
more type fixes
Randl 77fd960
lint and type fixes
Randl 39bfeca
add typevar for basepass
Randl 2b6119a
lint andadditional fixes
Randl e98a6a1
more fixes
Randl 0c19518
more type fixes
Randl 680d54f
lint and circular import fixes
Randl 74cdcca
Add more annotations
Randl c3995cd
Return import
Randl 44b401d
Additional fixes
Randl 06a7fa3
Ignore decorated properties (https://github.com/python/mypy/issues/1362)
Randl 27e225c
small fix
Randl aa34e08
Ignore signature where it is already different for pylint
Randl d6c3f96
More fixes
Randl f448848
lint
Randl 7538012
further type fixes
Randl b07fef7
Ignore assiignment to attributes
Randl ed92f01
More type annotations
Randl 26922da
More type annotations
Randl e6e1281
Lint
Randl f78f0c0
floating
Randl 5001146
multiple fixes.
Randl 99b055f
lint
Randl b43dec0
remove circular import
Randl 5f656e0
Fixes after rebase
Randl 4fc7899
Lint
Randl 2b11c74
Lint 2
Randl 34cc559
Fix after rebase
Randl 657fc57
Fix after rebase 2
Randl 0d2f065
Fixes from review
Randl 2d56f46
Fixes from review 2
Randl 505c2ed
Remove asserts
Randl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ def cos_estimate(power, shots): | |
theta = np.mean(theta_ci) | ||
rescaling = 4 if self._rescale else 1 | ||
value = (rescaling * np.sin(theta)) ** 2 | ||
value_ci = [(rescaling * np.sin(x)) ** 2 for x in theta_ci] | ||
value_ci = [(rescaling * np.sin(x)) ** 2 for x in theta_ci] # TODO should be tuple? | ||
|
||
result = FasterAmplitudeEstimationResult() | ||
result.num_oracle_queries = self._num_oracle_calls | ||
|
@@ -261,14 +261,15 @@ class FasterAmplitudeEstimationResult(AmplitudeEstimatorResult): | |
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self._success_probability = None | ||
self._num_steps = None | ||
self._num_first_state_steps = None | ||
self._theta_intervals = None | ||
self._success_probability: Optional[int] = None | ||
self._num_steps: Optional[int] = None | ||
self._num_first_state_steps: Optional[int] = None | ||
self._theta_intervals: Optional[List[List[float]]] = None | ||
|
||
@property | ||
def success_probability(self) -> int: | ||
"""Return the success probability of the algorithm.""" | ||
# TODO: should be float? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check the code to see if the |
||
return self._success_probability | ||
|
||
@success_probability.setter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems to be a common change here. Both algorithms and opflow used to run against mypy in Aqua before they were migrated to Terra here. Since then mypy has not been run here and some code has been added so I would have expected some issues. But mypy always internally figured the type of instance variables based on its usage so unless things were more complicated around the types, where it locked in one aspect and it was used with a different type later, in general this was not needed. @manoelmarques since you dealt more directly with mypy in this area any 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.
I went with error messages, somehow mypy couldn't figure out that it's
Optional[int]
rather thanNoneType
, and thus assignment ofint
to this variable is leading to type errorThere 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 version of mypy are you running with? I know mypy has put out new versions since we ran the code when it was in Aqua. Here for instance is a mypy ini file, for code that was migrated from Aqua, where in the applications repos we run mypy, and is updated from what we used to do in Aqua. For instance we have strict_optional set False, which allows None to be any type. What settings are you running this with. I assume you are doing this all locally since I do not see requirements-dev.txt nor CI updated to run this here yet. Maybe its too soon.
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'm running
mypy 0.970
with following commanddmypy run -- --ignore-missing-imports --no-strict-optional --allow-untyped-globals --allow-redefinition --show-error-codes qiskit
taken from #6905 (comment)I'm indeed doing it locally, since there are still ~1000 mypy errors after this PR (and ~1400 before). Fixing everything in one PR is too much, and even this PR will probably be broken into a couple of smaller ones, as discussed a bit earlier here.