-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
ENH: drop validation of transformations in parse_expr to save time when called in intensive loops #23804
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
ENH: drop validation of transformations in parse_expr to save time when called in intensive loops #23804
Conversation
|
✅ 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.12. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
|
Do you only use the built-in transformations? I wonder if a quick |
|
No we don't, we use a custom transformation defined here |
|
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) Full benchmark results can be found as artifacts in GitHub Actions |
|
Other possibilities:
|
|
I guess the purpose is to help with user defined transformations. It doesn't need to be done with the ones in SymPy. For your custom one, I support adding the ability to define assumptions to SymPy's own symbol transformer (that's useful regardless of performance). |
This looks very hard because most of its cost is from
That would be my preferred solution actually, but I didn't think it would be received well !
Wouldn't that affect the meaning of |
|
'all' would still do what it does now with my suggestion. I am suggesting to add a custom transformer like For the validation, there should be an internal list of all the transformers created by the sympy parser code, which it can skip validation for. This list would include any transformers created by the symbol_with_assumptions transformer. I'm also fine with removing validation. It was added in 4839dbe by @smichr, so we should see if he has any comments. I would prefer both of these options to adding a new keyword argument. I don't think it's worth polluting the user options for something like this. We should either be faster about how we do it, or not do it at all. |
It is checking args count and whether it is callable. If either of those don't apply, the transformer will fail on its own so it seems like the validation could be removed. |
b19e276 to
80793fa
Compare
|
thank you @smichr ! I just repurposed the PR (changed the title and commit history) to drop validation altogether |
…en called in intensive loops
80793fa to
023dd24
Compare
|
(pushed again to fix flake8 issues) |
|
@asmeurer @oscarbenjamin @smichr is there anything I should do here ? I apologize for pinging you after just a couple days of inactivity, I am not familiar with the typical triaging timescales for sympy. |
|
I don't know this code so well but this looks good to me. |
References to other Issues or PRs
None.
Brief description of what is fixed or changed
I noticed that validation of transformations takes about half of
parse_exprruntime (specificallysympy.core.function.arityis very expensive)In unyt, this function is called in an intensive loop (several thousands calls) at import time, with hard coded transformations, see
https://github.com/yt-project/unyt/blob/577fd554f3171b85589690f4e563bad30a84340c/unyt/_parsing.py#L92-L95
In the end, this builds up to a few 0.1s wasted every single time unyt is imported. For reference, it's on par with the import time of numpy.
So I propose allowing to skip validation as an opt-out.
Other comments
I'm hoping this small patch is an acceptable solution for this external problem.
If not, I'll be happy to discuss and work on other possible solutions with you.
Release Notes
parse_expr, for performance purposes.