-
Notifications
You must be signed in to change notification settings - Fork 595
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
Pennylane is compatible with numpy 2.0 #6061
Conversation
Hello. You may have forgotten to update the changelog!
|
…aN to np.nan" This reverts commit b3ab335. Reverting changes from numpy formating and NAN
revert changes from numpy printing settings
attempt to use the legacy printing option
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6061 +/- ##
==========================================
- Coverage 99.59% 99.58% -0.01%
==========================================
Files 443 443
Lines 42255 42255
==========================================
- Hits 42082 42078 -4
- Misses 173 177 +4 ☔ View full report in Codecov by Sentry. |
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.
Is this PR only fixing tests?
np.sign
is compatible with PennyLaneThere 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.
Thanks @EmilianoG-byte for all of the work
A few questions from my side:
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.
Looks good, I left a few comments and suggestions.
Update: now, Codecov project complains since it detects a -0.07% coverage compared to the commit associated with this PR. As specified in the PR itself, Code cov failures are in default.qubit.legacy and QubitDevice, so can be ignored. |
… is already in `setup.py`
…o compatible-np-2.0
**Context:** We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0. **Description of the Change:** We can distinguish the changes into 3 main categories: *Changes to workflows* - None in the final version *Changes to requirements and setup files* - Unpin the Numpy version in `setup.py` (now we also allow Numpy 2.0). - Update `requirements-ci.txt` to include Scipy 1.13 (this adds support for Numpy 2.0). - Pin Numpy in `requirements-ci.txt` to 2.0. *Changes to the source code* - Change `np.NaN` to `np.nan`. - Use legacy printing representation in tests, contrary to the new numpy representation of scalars, e.g. np.float64(3.0) rather than just 3.0. - Update probabilities warning to be case insensitive and check for a partial match, since this warning was changed in Numpy 2.0. - Check the datatype of np.exp from the Global phase only for Numpy 1.x, since this gets promoted to complex128 in Numpy 2.x. https://numpy.org/neps/nep-0050-scalar-promotion.html#schema-of-the-new-proposed-promotion-rules. **Benefits:** Make Pennylane compatible with Numpy 2.0. **Possible Drawbacks:** - We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR. - We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be `tensorflow` and `openfermionpyscf` (notice that `tensorflow` is required in some code sections like qcut). In particular, `openfermionpyscf` causes an error: ``` AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead. ``` in the qchem tests. The attribute `np.string_` is not used in the PL source code, so it is a problem with the package itself. [sc-61399] [sc-66548] --------- Co-authored-by: PietropaoloFrisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
**Context:** We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0. **Description of the Change:** We can distinguish the changes into 3 main categories: *Changes to workflows* - None in the final version *Changes to requirements and setup files* - Unpin the Numpy version in `setup.py` (now we also allow Numpy 2.0). - Update `requirements-ci.txt` to include Scipy 1.13 (this adds support for Numpy 2.0). - Pin Numpy in `requirements-ci.txt` to 2.0. *Changes to the source code* - Change `np.NaN` to `np.nan`. - Use legacy printing representation in tests, contrary to the new numpy representation of scalars, e.g. np.float64(3.0) rather than just 3.0. - Update probabilities warning to be case insensitive and check for a partial match, since this warning was changed in Numpy 2.0. - Check the datatype of np.exp from the Global phase only for Numpy 1.x, since this gets promoted to complex128 in Numpy 2.x. https://numpy.org/neps/nep-0050-scalar-promotion.html#schema-of-the-new-proposed-promotion-rules. **Benefits:** Make Pennylane compatible with Numpy 2.0. **Possible Drawbacks:** - We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR. - We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be `tensorflow` and `openfermionpyscf` (notice that `tensorflow` is required in some code sections like qcut). In particular, `openfermionpyscf` causes an error: ``` AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead. ``` in the qchem tests. The attribute `np.string_` is not used in the PL source code, so it is a problem with the package itself. [sc-61399] [sc-66548] --------- Co-authored-by: PietropaoloFrisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
**Context:** As part of the effort to make PL compatible with Numpy 2.0 (see #6061), we need to upgrade JAX to 0.4.26+ since such a version introduced the support for Numpy 2.0. We opted for JAX 0.4.28 since it is the same version used by Catalyst. **Description of the Change:** As above. **Benefits:** PL is compatible with Numpy 2.0 and Jax 0.4.28. **Possible Drawbacks:** - From JAX 0.4.27, in `jax.jit`, passing invalid static_argnums or static_argnames now leads to an error rather than a warning. In PL, this breaks every test where we set `shots` in the `QNode` call with `static_argnames=["shots"]`. At this stage, we decided to mark such tests with `pytest.xfail` to allow the upgrade. **Related GitHub Issues:** None. **Related Shortcut Stories**: [sc-61389] --------- Co-authored-by: dwierichs <david.wierichs@xanadu.ai>
**Context:** We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0. **Description of the Change:** We can distinguish the changes into 3 main categories: *Changes to workflows* - None in the final version *Changes to requirements and setup files* - Unpin the Numpy version in `setup.py` (now we also allow Numpy 2.0). - Update `requirements-ci.txt` to include Scipy 1.13 (this adds support for Numpy 2.0). - Pin Numpy in `requirements-ci.txt` to 2.0. *Changes to the source code* - Change `np.NaN` to `np.nan`. - Use legacy printing representation in tests, contrary to the new numpy representation of scalars, e.g. np.float64(3.0) rather than just 3.0. - Update probabilities warning to be case insensitive and check for a partial match, since this warning was changed in Numpy 2.0. - Check the datatype of np.exp from the Global phase only for Numpy 1.x, since this gets promoted to complex128 in Numpy 2.x. https://numpy.org/neps/nep-0050-scalar-promotion.html#schema-of-the-new-proposed-promotion-rules. **Benefits:** Make Pennylane compatible with Numpy 2.0. **Possible Drawbacks:** - We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR. - We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be `tensorflow` and `openfermionpyscf` (notice that `tensorflow` is required in some code sections like qcut). In particular, `openfermionpyscf` causes an error: ``` AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead. ``` in the qchem tests. The attribute `np.string_` is not used in the PL source code, so it is a problem with the package itself. [sc-61399] [sc-66548] --------- Co-authored-by: PietropaoloFrisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
**Context:** As part of the effort to make PL compatible with Numpy 2.0 (see #6061), we need to upgrade JAX to 0.4.26+ since such a version introduced the support for Numpy 2.0. We opted for JAX 0.4.28 since it is the same version used by Catalyst. **Description of the Change:** As above. **Benefits:** PL is compatible with Numpy 2.0 and Jax 0.4.28. **Possible Drawbacks:** - From JAX 0.4.27, in `jax.jit`, passing invalid static_argnums or static_argnames now leads to an error rather than a warning. In PL, this breaks every test where we set `shots` in the `QNode` call with `static_argnames=["shots"]`. At this stage, we decided to mark such tests with `pytest.xfail` to allow the upgrade. **Related GitHub Issues:** None. **Related Shortcut Stories**: [sc-61389] --------- Co-authored-by: dwierichs <david.wierichs@xanadu.ai>
**Context:** After [Pennylane support numpy 2.0](PennyLaneAI/pennylane#6061), catalyst needs to add this support. **Description of the Change:** 1. Bump pennylane version to include the numpy 2.0 support 2. Since programs built using numpy 1.x would not readily work with numpy 2.0, we upgraded reuirements.txt to install numpy2.0. The reason is that wrapper.cpp uses the numpy C-API that should be built using numpy 2.x. 3. pyblind11 dependency was upgraded to 2.12.0 which adds support to numpy 2.0 4. scipy dependency includes 1.13 which adds support for numpy 2.0 5. removed optax dependancy from requirements (it was a TODO and unrelated to numpy but would cause CI delay) **Benefits:** Adds support for numpy 2.0 **Related GitHub Issues:** [sc-61401]
**Context:** In #6061, we started using by default NumPy 2 (instead of NumPy 1) on the CI to test every PR targeting the master branch. Some jobs (for example, those requiring `tensorflow`) still automatically downgrade to NumPy 1.26 since not all interfaces are supported at the current stage. This PR aims to create another workflow to test some jobs with NumPy 1.26 (those that don't automatically downgrade to NumPy 1 during the day). Such a workflow should run at night to ensure PennyLane is still compatible with NumPy 1.26. **We'll keep this workflow only temporarily** (probably a quarter, but this still has to be established). After that, we'll get rid of it. Finally, It has been verified (see [here](https://github.com/PennyLaneAI/pennylane/actions/runs/10927439038)) that the tests introduced with this PR are green. This has been verified a second time (see [here](https://github.com/PennyLaneAI/pennylane/actions/runs/10946347640) before merging this PR into master). **Description of the Change:** As above. **Benefits:** We ensure that PennyLane is still compatible with NumPy 1.26. **Possible Drawbacks:** - This issue was discovered accidentally (and potentially fixed) during this PR. The `TestSinglePrecision` class in the `test_jax_jit_qnode.py` file contains tests that change the JAX precision with `jax.config.update("jax_enable_x64", False)`. When running the jax tests using multiple workers, we can face race conditions if some workers change jax configuration, because other workers in other test classes downgrade to a single precision causing numerous failures. To avoid this, we add [--dist=loadscope](https://pytest-xdist.readthedocs.io/en/latest/distribution.html) as additional pytest arg for jax tests, grouping tests by module for test functions and by class for test methods. - The new workflow is it is to a large extent a (very simplified) copy of `interface-unit-tests.yml`. This is against the principle of avoiding code duplication whenever possible. Still, this is just a temporary workflow that lasts for a few months at most (and runs only at night), and it may be convenient to disentangle it as much as possible from the usual test interface. **Related GitHub Issues:** None. **Related Shortcut Stories:** [sc-73744]
**Context:** We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0. **Description of the Change:** We can distinguish the changes into 3 main categories: *Changes to workflows* - None in the final version *Changes to requirements and setup files* - Unpin the Numpy version in `setup.py` (now we also allow Numpy 2.0). - Update `requirements-ci.txt` to include Scipy 1.13 (this adds support for Numpy 2.0). - Pin Numpy in `requirements-ci.txt` to 2.0. *Changes to the source code* - Change `np.NaN` to `np.nan`. - Use legacy printing representation in tests, contrary to the new numpy representation of scalars, e.g. np.float64(3.0) rather than just 3.0. - Update probabilities warning to be case insensitive and check for a partial match, since this warning was changed in Numpy 2.0. - Check the datatype of np.exp from the Global phase only for Numpy 1.x, since this gets promoted to complex128 in Numpy 2.x. https://numpy.org/neps/nep-0050-scalar-promotion.html#schema-of-the-new-proposed-promotion-rules. **Benefits:** Make Pennylane compatible with Numpy 2.0. **Possible Drawbacks:** - We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR. - We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be `tensorflow` and `openfermionpyscf` (notice that `tensorflow` is required in some code sections like qcut). In particular, `openfermionpyscf` causes an error: ``` AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead. ``` in the qchem tests. The attribute `np.string_` is not used in the PL source code, so it is a problem with the package itself. [sc-61399] [sc-66548] --------- Co-authored-by: PietropaoloFrisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
**Context:** As part of the effort to make PL compatible with Numpy 2.0 (see #6061), we need to upgrade JAX to 0.4.26+ since such a version introduced the support for Numpy 2.0. We opted for JAX 0.4.28 since it is the same version used by Catalyst. **Description of the Change:** As above. **Benefits:** PL is compatible with Numpy 2.0 and Jax 0.4.28. **Possible Drawbacks:** - From JAX 0.4.27, in `jax.jit`, passing invalid static_argnums or static_argnames now leads to an error rather than a warning. In PL, this breaks every test where we set `shots` in the `QNode` call with `static_argnames=["shots"]`. At this stage, we decided to mark such tests with `pytest.xfail` to allow the upgrade. **Related GitHub Issues:** None. **Related Shortcut Stories**: [sc-61389] --------- Co-authored-by: dwierichs <david.wierichs@xanadu.ai>
**Context:** In #6061, we started using by default NumPy 2 (instead of NumPy 1) on the CI to test every PR targeting the master branch. Some jobs (for example, those requiring `tensorflow`) still automatically downgrade to NumPy 1.26 since not all interfaces are supported at the current stage. This PR aims to create another workflow to test some jobs with NumPy 1.26 (those that don't automatically downgrade to NumPy 1 during the day). Such a workflow should run at night to ensure PennyLane is still compatible with NumPy 1.26. **We'll keep this workflow only temporarily** (probably a quarter, but this still has to be established). After that, we'll get rid of it. Finally, It has been verified (see [here](https://github.com/PennyLaneAI/pennylane/actions/runs/10927439038)) that the tests introduced with this PR are green. This has been verified a second time (see [here](https://github.com/PennyLaneAI/pennylane/actions/runs/10946347640) before merging this PR into master). **Description of the Change:** As above. **Benefits:** We ensure that PennyLane is still compatible with NumPy 1.26. **Possible Drawbacks:** - This issue was discovered accidentally (and potentially fixed) during this PR. The `TestSinglePrecision` class in the `test_jax_jit_qnode.py` file contains tests that change the JAX precision with `jax.config.update("jax_enable_x64", False)`. When running the jax tests using multiple workers, we can face race conditions if some workers change jax configuration, because other workers in other test classes downgrade to a single precision causing numerous failures. To avoid this, we add [--dist=loadscope](https://pytest-xdist.readthedocs.io/en/latest/distribution.html) as additional pytest arg for jax tests, grouping tests by module for test functions and by class for test methods. - The new workflow is it is to a large extent a (very simplified) copy of `interface-unit-tests.yml`. This is against the principle of avoiding code duplication whenever possible. Still, this is just a temporary workflow that lasts for a few months at most (and runs only at night), and it may be convenient to disentangle it as much as possible from the usual test interface. **Related GitHub Issues:** None. **Related Shortcut Stories:** [sc-73744]
Context:
We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0.
Description of the Change:
We can distinguish the changes into 3 main categories:
Changes to workflows
Changes to requirements and setup files
setup.py
(now we also allow Numpy 2.0).requirements-ci.txt
to include Scipy 1.13 (this adds support for Numpy 2.0).Changes to the source code
np.NaN
tonp.nan
.Benefits:
Make Pennylane compatible with Numpy 2.0.
Possible Drawbacks:
We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR.
We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be
tensorflow
andopenfermionpyscf
(notice thattensorflow
is required in some code sections like qcut). In particular,openfermionpyscf
causes an error:in the qchem tests. The attribute
np.string_
is not used in the PL source code, so it is a problem with the package itself.[sc-61399]
[sc-66548]