-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Allow numpy to be import under pypy #23461
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
Pypy has evolved greatly, it might be a good idea to remove the import ban.
✅ Hi, I am the SymPy bot (v167). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.11. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
It took more than 20 min to build packages, and gmpy2 is incompatible with pypy. Skip that. |
Symengine should also be skipped. |
14bb564
to
624866b
Compare
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) before after ratio
[77f1d79c] [96ecc0c5]
<sympy-1.10.1^0>
+ 92.2±5ms 177±0.8ms 1.92 sum.TimeSum.time_doit
Full benchmark results can be found as artifacts in GitHub Actions |
The changes here all make sense to me. For the CI, I don't know if it's necessary to have a separate optional dependencies build just for pypy. We can install the optional dependencies that work with pypy in the normal pypy build. The point of the optional dependencies build is to make sure we test everything without any optional dependencies installed in the normal tests, but I don't think that's important to do for pypy specifically. |
I make a separate CI job for this because
Let test cases covered by test1+test2 be set A, test cases covered by test_optional_dependencies.py be set B. I don't know the relationship between set A and B. If B is a subset of A, then we may run A with optional dependencies. If not, we need this new CI job. |
I think it's reasonable to add this as an extra job. |
Adding another job is fine if it makes more sense to do so. Splitting jobs isn't as big of a deal as it used to be because GitHub Actions doesn't seem to have the same sort of parallel jobs limit like Travis used to, although we should still avoid splitting more than necessary because it makes the checks harder to read and because each job has some overhead for setup time. |
I'm going to merge it in order to fix the issue. Feel free to remove the job if it becomes a burden. |
@@ -100,7 +100,7 @@ | |||
"math": (MATH, MATH_DEFAULT, MATH_TRANSLATIONS, ("from math import *",)), | |||
"mpmath": (MPMATH, MPMATH_DEFAULT, MPMATH_TRANSLATIONS, ("from mpmath import *",)), | |||
"numpy": (NUMPY, NUMPY_DEFAULT, NUMPY_TRANSLATIONS, ("import numpy; from numpy import *; from numpy.linalg import *",)), | |||
"scipy": (SCIPY, SCIPY_DEFAULT, SCIPY_TRANSLATIONS, ("import numpy; import scipy; from scipy import *; from scipy.special import *",)), | |||
"scipy": (SCIPY, SCIPY_DEFAULT, SCIPY_TRANSLATIONS, ("import scipy; import numpy; from scipy import *; from scipy.special import *",)), |
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.
Why is this change needed?
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.
See my description for the 2nd commit. If the environment has numpy but doesn't have scipy, test_lambdify.py
produces strange behavior. It's the case for both cpython and pypy.
.github/workflows/runtests.yml
Outdated
# -------------------- Optional dependency tests for pypy ----------------- # | ||
|
||
optional-dependencies-pypy: | ||
needs: code-quality |
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.
Can this be added using matrix:
rather than as a separate listing?
The only difference with the job above is that pip doesn't install quite as many things but we could guard that with a conditional.
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'll read the GitHub Actions doc to see how to achieve that.
@oscarbenjamin Required tests should be changed. |
References to other Issues or PRs
Fixes #14658
Revive #14664
Please review commit by commit (e.g. checkout the first commit, reproduce the result I get, then checkout the next commit). I'll amend and force-push when needed.
The 1st commit removes the import restriction
My local environment is Ubuntu 22.04 x64, pypy3 from apt.
I can't install scipy (build fail), so I test with numpy only.
It is strange since I have no scipy locally, why it tries to import scipy? If I run the
test_integral
only, it gives another error:$ pypy3 -m pytest sympy/utilities/tests/test_lambdify.py::test_integral ... FAILED sympy/utilities/tests/test_lambdify.py::test_integral - NameError: name 'Integral' is not defined
So the previous error is dependent with tests ran before.
The 2nd commit fixes the scipy problem
A test runs before
test_integral
tries to import scipy. At line 149 it executesimport numpy
first, which succeed and updatesnamespace
, which is the global dictSCIPY
.After that,
test_integral
tries to import scipy. As thenamespace
is modified, at line 132 the condition becomesTrue
and the function successfully returns, giving a false conclusion that scipy is available.So this commit re-arranges the order of imports. If scipy is not available,
SCIPY
isn't modified anymore, and tests run consistently.sympy/sympy/utilities/lambdify.py
Lines 132 to 150 in ed4e06e
Now testing
test_lambdify.py
will also lead to the undefinedIntegral
exception.The 3rd commit skips the 2 failing tests when numpy is installed but scipy isn't
The 4th commit test optional dependencies for pypy
gmpy2, symengine, llvmlite and numba cannot be built. Skip them.
The 5th commit fix the test error in the previous PR
Explanation can be found at https://stackoverflow.com/a/7396043.
Release Notes
lambdify
with NumPy while running under PyPy.