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

Fix Ci for latest mypy #89

Merged
merged 2 commits into from
Oct 16, 2023
Merged

Fix Ci for latest mypy #89

merged 2 commits into from
Oct 16, 2023

Conversation

woodsp-ibm
Copy link
Member

@woodsp-ibm woodsp-ibm commented Oct 13, 2023

Summary

CI is failing here with the latest mypy (1.6.0). The issue seems to be around override in initial_point setter/getter.

In looking the base class defines the type as an optional numpy array. Yet we change things up to Sequence[float] in derived classes and then have to ignore the arg to minimize/optimize as that takes a POINT (union of numpy array or float). Given the initial point needs to line up with what is passed to optimizer, and scipy mimimize states it takes a numpy array (although internally it does as asarray() on whats passed) I have changed the type hints all over to np.ndarray from Sequence. QAOA initial_point was already a numpy array and that had an ignore in order to call the parent SamplingVQE that takes a Sequence.
As such I felt this was clearer/cleaner. People pass numpy arrays, or lists which will work.

For VQD what we have as initial_point is more initial_points which is somewhat at odds with it being a variational algo as that defines just an initial point really. I did not alter anything - I think this has been observed before, and arguably things ought to be improved at some point. And I will point out that type difference in the derived class, while mypy 1.6.0 does not object, mypy 1.,5..1 does which is presumably why those ignores were there elsewhere too.

qiskit_algorithms/eigensolvers/vqd.py:170: note:      Superclass:
qiskit_algorithms/eigensolvers/vqd.py:170: note:          Optional[ndarray[Any, Any]]
qiskit_algorithms/eigensolvers/vqd.py:170: note:      Subclass:
qiskit_algorithms/eigensolvers/vqd.py:170: note:          Union[ndarray[Any, Any], list[ndarray[Any, Any]], None]

Now I could have just left it ndarray but since the text talks about list of points I felt it was better to be explicit here and that things are different.

Since its only a change to typehints I did not do a reno. Users code, if it worked before should continue to work.

Details and comments

Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Thanks Steve for taking care of this. It is a bit counter-intuitive that in an attempt to generalize our type-hints using Sequence, we ended up omitting the type that is most generally used (np.ndarray), but I think that this is a coherent fix.

@ElePT ElePT merged commit 54796fb into qiskit-community:main Oct 16, 2023
13 checks passed
@woodsp-ibm woodsp-ibm deleted the mypy_fixes branch October 16, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants