-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Global option to stop automatic distribution #12440
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
|
Is this intended to be a stopgap? I think we should aim to completely remove it (no options). |
certik
left a comment
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.
The changes seem simple enough that I think this can be merged now.
I agree that we should simply not distribute at all, this was a mistake to introduce. But in the meantime this PR should help.
|
Note: In SymEngine we do not distribute automatically, which is the correct way. |
|
If it's a stopgap we should not add public API for it, as we'd then have to maintain it even after we change the default. |
|
How would we make this a private API? |
|
I am talking about the |
|
So if we remove it from there, it's ok?
Sent from my mobile phone.
…On Mar 28, 2017 7:18 PM, "Aaron Meurer" ***@***.***> wrote:
I am talking about the distributed context manager, which has been added
to *init*.py here.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12440 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABQWPjZ1iKNKUrN8wFTIvl2Hwwtrlhgks5rqbFTgaJpZM4Mr3gp>
.
|
|
I've added this option because this is a major change. There are hundreds of doctests and unit tests failing when I change the default. For downstream projects, this may be the case also. |
|
I wouldn't distribute -1 either. We can make the default not to distribute, and then provide this decorator for downstream projects so that they can keep the old behavior as a temporary workaround until they implement proper fixes. |
|
Wow, there are 410 tests failing when I switch the default. https://travis-ci.org/isuruf/sympy/jobs/216195057 |
|
Thanks @isuruf for working on this! |
|
@asmeurer how do you want to proceed? Do you want to merge this (after making the decorator not a public API), and then work on the failures. Or perhaps we can do the switch, provide a decorator for old behavior, and then use that decorator as a temporary workaround for failing tests, that way everything should pass, and then we work on it, one by one. This is a big change, so I would like some direction from you which way it should be done. |
|
If the context manager is necessary to do the change piecemeal then that's fine. I'm only worried about supporting both distribution and nondistribution long after the change is completely done. In general, we should avoid having global options, especially in the core, as they provide different code paths that remain mostly untested. And I don't think we want the whole test suite to pass with both But maybe this is not a huge deal. We can
The deprecation is unnecessary if this all happens before a release, but that seems unlikely. |
|
And I agree not to distribute anything, even |
How does this justify removing usage of distributive law in flatten? Looks like a very special case. @isuruf, what will be your next step? Are you planing to eventually fix all tests and switch to distributive=False? If so, I doubt that this context manager will help in such slow migration: supporting codebase where part of code runs in context distributive(False) and another part not - will be nightmare. Disclaimer: my lazy attempts to fix referenced issue were motivated by another reasons, not performance. For instance, to allow default Mul.flatten be generic enough to handle more common cases of algebras, where distributivity doesn't holds. E.g. interval arithmetic. |
Take a simple example like There might be other reasons not to do this though. We are not distributing
True. I added the context manager to provide the user with an option. Now I realized that SymPy has the assumption that the expression is distributed all over the place and very complicated examples fail when you switch. As to my next step, I'm not sure. I didn't expect examples like #12440 (comment) to fail. |
|
That's why automatic evaluation is bad. You end up with code all over the place that implicitly relies on it, and stops working or even gives wrong results if you try to remove it. I had the same thing years ago when I removed the For this issue, it's actually pretty easy in SymPy right now to get an expression that isn't distributed. Lots of functions like
So do you still think the context manager is useful? Or is it too hard to isolate code where it can safely be turned off? |
I still think it will be useful until we switch. SymPy users who only does stuff like arithmetic, differentiation, matrix operations and codegen will find it useful.
For the examples I mentioned, it's easy to isolate where the problem is. ( |
|
I think there may already be some helper functions in the core for creating undistributed products. |
|
Probably, you want distribute |
It assumed that the Expr is commutative, but now it is explicitly added.
|
I've removed |
|
Can you add a note to the docstring that it will likely go away once automatic distribution is removed entirely. Other than that I am +1 |
|
Fixed |
|
Thanks @isuruf ! |
Partial fix for #4596
Here's a small benchmark from the issue
with the output,
For this code, when add*number is not distributed with the global option, op count is 488, whereas if it was distributed, op count is 3133. Simplify with both options give the same op count of 417.
Here's some code from the docs where it says, "Because there can be a significant amount of simplification that can be done when multiple differentiations are performed, results will be automatically simplified ..."
Here's with no automatic distribution,
Note that here the increase in the opcount for
simplify=Trueis probably because a bug with simplify.Thanks to @skirpichev, for figuring out where changes were necessary.