-
Notifications
You must be signed in to change notification settings - Fork 368
Add support for Python 3.13 #836
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
Conversation
FYI: Qiskit 1.3.0 milestone, due by November 21, 2024 |
Un-drafting this PR ahead of the RC expected release date of Qiskit 1.3 (7 Nov 2024). The due date for the official release remains 21 Nov, which is when we expect to sync Python 3.13 support for Qiskit ML too. |
# Conflicts: # .github/workflows/main.yml # releasenotes/notes/py38_end_of_support-fa1fdea6ea02b502.yaml
This PR has to be put on hold until #863 is resolved. |
Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Thanks very much @woodsp-ibm! I added the |
I see my eq change failed with mypy - as there are so many mypy issues now in qiskit algorithms I had disabled it there as an interim solution so I had not seen that. Presumably if the object instance type is checked why would it not return False if its another type in this case rather than NotImplemented as the suggestion. |
Note that mypy requires this construct # Under Python 3.13 the auto-generated equal fails with an error around
# using numpy all or any. See https://github.com/qiskit-community/qiskit-algorithms/pull/225
# for further information. Hence, this custom function was added. The __eq__
# method is supposed to accept any object. If you update the version of
# mypy you're using, it'll print out a note recommending this code structure.
def __eq__(self, other: object) -> bool:
if not isinstance(other, OptimizerState):
# If we return NotImplemented, Python will automatically try
# running other.__eq__(self), in case 'other' knows what to do with
# Person objects.
return NotImplemented
return (
(
self.x == other.x
if isinstance(self.x, float)
else (self.x.shape == other.x.shape and (self.x == other.x).all())
)
and self.fun == other.fun
and self.jac == other.jac
and self.nfev == other.nfev
and self.njev == other.njev
and self.nit == other.nit
) and # See parent class for a comment on having a custom equals. I needed this
# too as it does not appear to use super by default and without this failed
# the exact same way. Note it does not include learning rate as that field
# is not included in the compare as pre the field decorator. The __eq__
# method is supposed to accept any object. If you update the version of
# mypy you're using, it'll print out a note recommending this code
# structure.
def __eq__(self, other: object) -> bool:
if not isinstance(other, GradientDescentState):
# If we return NotImplemented, Python will automatically try
# running other.__eq__(self), in case 'other' knows what to do with
# Person objects.
return NotImplemented
return super().__eq__(other) and self.stepsize == other.stepsize You might find these useful for Algorithms too. |
Thanks yes. I had already made a mental note to update algs with whatever worked here. |
I am not sure why mypy is complaining now since that ternary was to do something different for float type such that it does not do the shape check etc |
Yeah I'm confused by mypy. It's basically forcing to
|
Is that mypy output from your local machine? Otherwise, as far as I can see, there is just the one issue its flagging in CI here - maybe locally you are not using the same versions as CI is. |
For the mypy shape failure it seems my ternary expression had issues on closer inspection. I.e the first part said if both are float but it could then end up in the else where just one was a float, which evidently wont have shape. So it became a bit more complex and I updated the algs with the other mypy issue as well as fixing the shape aspect here qiskit-community/qiskit-algorithms#226 (it was failing with the mypy issue the same way locally but now passes locally with mypy for me though as I mentioned its disabled at present in algs since thats using a newer version of numpy - locally I still have a 2.0.2) |
It worked with the fix in Algorithms! |
Pull Request Test Coverage Report for Build 14001256542Details
💛 - Coveralls |
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.
Just needs the branch rules updated then to remove the required 3.12 jobs no longer run and make the 3.13 ones, that superseded them, required,
Thanks for approving the PR @woodsp-ibm! If I remember correctly, I cannot change the rules myself because only qiskit community members have those privileges. If this is still the case, could you please help with that? |
@edoaltamura Ok I updated the rules for the main branch here. I will note in looking @smens has admin rights here in this repo and therefore should be able to do such a change too, |
This reverts commit 75e2109.
This update introduces support for Python 3.13, scheduled for final release on 7 October 2024.
Closes #825
Closes OkuyanBoga#45