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

Bump Numpy #7033

Open
MIWdlB opened this issue Mar 4, 2025 · 5 comments
Open

Bump Numpy #7033

MIWdlB opened this issue Mar 4, 2025 · 5 comments
Assignees
Labels
enhancement ✨ New feature or request

Comments

@MIWdlB
Copy link

MIWdlB commented Mar 4, 2025

Feature details

Pinning numpy to <2.1 is now becoming restrictive. What's the issue that stops this from being <3?

Implementation

No response

How important would you say this feature is?

3: Very important! Blocking work.

Additional information

No response

@MIWdlB MIWdlB added the enhancement ✨ New feature or request label Mar 4, 2025
@mudit2812 mudit2812 mentioned this issue Mar 4, 2025
10 tasks
@josh146
Copy link
Member

josh146 commented Mar 4, 2025

Thanks for opening this issue @MIWdlB! Our team is looking into this now, but there might be a pathway for removing our NumPy pinning for certain workflows.

However, this becomes a bit more complicated if you are using JAX with PennyLane. Currently, are you using Catalyst and/or JAX for anything?

@CatalinaAlbornoz
Copy link
Contributor

Hi @MIWdlB , I just wanted to give you an update on this.

We're evaluating options at the moment. We have PR #7039 open to try to unpin NumPy. Since this may not be a trivial change we may need to wait a bit before this gets merged into master. However you can follow the PR to see if we have any updates there.
Note that we do have it in our roadmap to support newer versions of NumPy, it may just take some time in case other things break with the change.

@MIWdlB
Copy link
Author

MIWdlB commented Mar 11, 2025

Thanks for the update, I've had to remove penny lane from my own repos for the time being. I'll keep an eye on the PR and add it back in when the time comes.

If there's jobs along the way that I can help out on I'd be happy to ☺️

@CatalinaAlbornoz
Copy link
Contributor

Oh that's unfortunate. Hopefully we'll be able to unpin it soon. We'll keep you updated and let you know if we can use your help! At the very least we can use your help flagging any issues once the change is done 😄

@JerryChen97 JerryChen97 self-assigned this Mar 17, 2025
JerryChen97 added a commit that referenced this issue Mar 18, 2025
## Context:
Previously, PennyLane pinned NumPy to version `numpy<2.1` (see the
[first
commit](449ae04)
of this PR). This restriction created compatibility challenges for users
building their own projects with PennyLane as a dependency, as reported
in #7033.

We've determined there are no fundamental blockers preventing PennyLane
from supporting newer NumPy versions - only historical integration
issues, particularly with TensorFlow, that have caused cascading CI
problems and potential ecosystem compatibility concerns.

With NumPy 1.26's end-of-support approaching in September 2025
([reference](https://endoflife.date/numpy)), it's critical we thoroughly
investigate and address these obstacles. This PR aims to explore
unpinning NumPy, document issues encountered, implement fixes, and
adjust our CI pipeline accordingly.
![Screenshot from 2025-03-18
10-37-25](https://github.com/user-attachments/assets/acee26ae-2a38-4642-879c-09ae5c4b1a5a)

Besides, we can check the NEP 29 Drop Schedule:
https://numpy.org/neps/nep-0029-deprecation_policy.html

## Description of the Change:
This PR follows a systematic approach:

1. Initially unpinning NumPy~1.26 but setting `>= 2.0.1` to ensure the
main environment uses NumPy 2
2. Documenting and analyzing all issues encountered with NumPy 2
compatibility
3. Methodically resolving each identified issue
4. Fully unpinning NumPy to allow maximum flexibility
5. Updating CI workflows as needed to accommodate version differences
6. Adding demonstrations showing PennyLane works safely with projects
requiring NumPy 2

Specific changes include:
- [x] Updated `tensorflow` to version `2.18` for NumPy 2 compatibility
across multiple files:
  - `.github/workflows/interface-dependency-versions.yml`
  - `docker/interfaces/install-interface-gpu.sh`
  - `docker/interfaces/install-interface.sh`
  - `requirements.txt`
  - `doc/requirements.txt`
  - `setup.py`
- [x] Updated `jax` and `jaxlib` to `0.4.28` for NumPy 2 compatibility
in `doc/requirements.txt`
- [x] Pinned `ml_dtypes` for compatibility in `requirements.txt` and
`setup.py`
- [x] Added conditional xfail decorator for `KerasLayer` tests that
won't pass with NumPy 2 (pending deprecation)
- [x] Added conditional xfail for `qchem` tests requiring `openfermion`
based on NumPy version

Extra manual test:
- [x] Locally installation of `numpy-2.2` works without conflicts with
PL
 - [x] Ci tests with other affected packages in PL ecosys passed:
- [x] lightning:
PennyLaneAI/pennylane-lightning#1095
- [x] pennylane-cirq:
PennyLaneAI/pennylane-cirq#211
- [x] pennylane-qiskit:
PennyLaneAI/pennylane-qiskit#622
 

## Benefits:
- Identified and resolved root causes of NumPy 2.x CI failures
- Users can now use PennyLane with NumPy 2.x environments without
compatibility issues
- Improved future maintainability by removing artificial version
constraints
- Better aligned with the Python ecosystem's forward progress

## Remaining Challenges:
We encountered several issues that warrant further investigation, though
not crucially important for now:
- Sphinx documentation generation succeeded with NumPy 1.x but fails
with NumPy 2.x despite no obvious connection, since the documentation
building should have their own dependencies in principle, as
`doc/requirements.txt` exists. However, this was reflected possibly
resulting from that there used to be some spaghetti between main
requiremnts and doc/requirements.
- Inconsistent test results between CI environment and local development
environment when using NumPy 2 + TensorFlow 2.18 + Keras 3. Basically,
if one tested Keras on their local machine, they should see ~half~ one
third of them to fail; however in our CI, actually only one of them
fails; this is also why the xfail macro was defined by not widely used
in the affected test file. This phenomenon could be caused by some
special environment variables in workflow setup, s.t. eventually the
actual Keras used is still Keras2.

## Related GitHub Issues:
[sc-85628]

---------

Co-authored-by: JerryChen97 <chenys13@outlook.com>
@CatalinaAlbornoz
Copy link
Contributor

Hi @MIWdlB , our team was able to remove the NumPy pin!
You can see PR #7039 for more details.

This change is available in the Master version of PennyLane, and will be available in the next stable release of PennyLane.

It would help a lot if you could try using the master version of PennyLane and let us know of any issues you encounter!

Thanks again for opening this issue and enjoy using PennyLane!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants