-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
WIP fix codegen #14079
WIP fix codegen #14079
Conversation
I guess this should have a test added for the new capability? |
@bjodah the codegen utilities code will be remove after your PR will be merged ? Is that the idea ? |
No, not in the foreseeable future, first |
Ok. For now, I have something which works for pyLBM (http://pylbm.readthedocs.io/en/develop/) but with an old version of sympy and I would like all the stuff I added to be in sympy to not have multiple versions and restart from the beginning. I have to improve the packaging of pyLBM and for that I will need to have a dependency of a release of sympy with a working codegen. |
I also have a lot of numerical examples which can improve the idea of using sympy to build numerical codes and be able to have a robust codegen for multiple languages. |
I have no comments on the changes here, but as a general comment, it would be useful for the codegen ast nodes to be able to specify how they should be interpreted as the rhs of an assignment. I guess this has to be done at the printer level, since different languages do different things. For a CodeBlock you probably want to assign the last line. For Forgive me if we already discussed this before, I can't remember. |
I'm not sure I understand what you mean. The assignment is not necessary after the last line of a CodeBlock. For example, you can have
where The best solution for me is to ask to the user to declare the result variables as The other problem that I encountered was the index variables in a For loop: they must be local variables which is not the case for now. I can also fix that. For me, ast should be like an intermediate representation (like LLVM does) where it is easy to add any printing language class on it. |
@gouarin you are right that we have quite a bit of degree of freedom to assume things in codegen.
in this case I believe inferring x and y being arrays is taking those assumptions one step too far. |
@bjodah my example was not a good one. I will modify codegen with the assumption that a user must write if he want a Then, I will let you tell me what do you think about this modifications. |
ping @bjodah. |
What is the status on this PR? It is labeled as WIP, so maybe still there. |
I didn't have time to finish this PR but I need it for my package. There is
a lot of work to be done for the autowrap module.
I plan to finish it before the end of this year.
Le dim. 7 oct. 2018 à 13:48, Jason K. Moore <notifications@github.com> a
écrit :
… What is the status on this PR? It is labeled as WIP, so maybe still there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14079 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHKaFdRzB1yNJWzKIdo76GOcmGDjRBCpks5uieoRgaJpZM4R4nVH>
.
|
@gouarin Thanks for the update. We will leave it open. |
✅ Hi, I am the SymPy bot (v160). 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.7. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
|
I think the improvement of codegen is done for me. Before I go further, I have some questions
https://github.com/sympy/sympy/blob/master/sympy/utilities/autowrap.py#L504-L507 because we loose the flexibility that we could have with codegen to add other wrappers. I have no idea at this time to have a better format.
and I will probably add Pythran and Numba wrappers since I started to put NumPy wrapper. Do I add these benchmarks in SymPy repo or do you prefer that I create a new one ? I made a lot of changes so tell me also if it's ok for you. I think we can do a lot of things now with codegen. |
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 left some comments on things that stood out to me. In general I think it's fine to refactor these modules heavily given that we don't break users code, i.e. we shouldn't modify existing tests (I hope that the test suite has sufficient coverage but that's another issue).
@@ -571,7 +571,7 @@ def test_ccode_Assignment(): | |||
|
|||
def test_ccode_For(): | |||
f = For(x, Range(0, 10, 2), [aug_assign(y, '*', x)]) | |||
assert ccode(f) == ("for (x = 0; x < 10; x += 2) {\n" | |||
assert ccode(f) == ("for (int x = 0; x < 10; x += 2) {\n" |
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.
This is a breaking change (in general we shouldn't change existing tests, they are not only there to ensure correctness, but also to guarantee a stable API for end users). Besides, I don't think that generating code for For
should not imply declaration of the loop variable in C (it's not even valid C89, which is still what e.g. msvc targets and what most embedded systems use). You'll have to generate the declaration and initialization outside the printer...
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.
this is still a breaking change...
def autowrap(expr, language=None, backend='f2py', tempdir=None, args=None, | ||
flags=None, verbose=False, helpers=None, code_gen=None, **kwargs): | ||
def autowrap(expr_or_routines, language=None, backend='f2py', tempdir=None, args=None, | ||
flags=None, verbose=False, helpers=None, code_gen=None, user_local_vars=None, settings={}, **kwargs): |
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.
we should not use mutable default values keyword arguments (they are essentially global variables in python, unfortunately). You can set de default to None
and then upon first access use the idiom settings or {}
.
I know that this PR begins to be huge and probably difficult to review. All I have done here, I use it in a real application https://github.com/pylbm/pylbm where the numerical code is generated by codegen. Tell me how we can make progress to add these features in SymPy. We can merge (when you will be agree) and open an other PR that will split the codegen files. I can also illustrate what I have done with some examples. |
You're not really just splitting files here (which is what I thought you were asking about on gitter), you're moving whole submodules. That might be ok, but I'd rather review such changes in a separate PR. I don't know what @asmeurer thinks though. |
- support other Matrix types
- save settings for routines printer - get a unique _get_statements_and_outputs
🟠Hi, I am the SymPy bot (v160). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it. This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75. The following commits add new files:
If these files were added/deleted on purpose, you can ignore this message. |
I finally decided to take a new start and split this PR into smallest to facilitate the review. I plan to make the following PR
|
This PR is a fix and improvement of codegen.
This short example shows the issue for the recursion of For
The output is
The problem is that For expression has a CodeBlock (list of statements) which can contain important information for output parameters and return values.
So, the idea is to inspect output parameters and result values recursively and not to see a routine as a result but as a list of statements where you can have results, input, output, input/output.
Now, the main issue is to change the sympy expression where you have a result parameter like in this expression
The idea would be to replace
x*y
byAssignment(result.name, x*y)
. In that way, all the work done for printing in a target language should be the same.I don't know how to do this correctly because each method
subs
,replace
, ... returns a copy and we need to change tuple element of CodeBlock for example.If you have some ideas ...