-
Notifications
You must be signed in to change notification settings - Fork 30
SympyWriter #2923
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
Comments
Besides I think the .AND. should be replaced by and to be understandable by sympy for sympification. |
Yes, I just realised that I have only very rudimentary support for boolean implemented (ok, that might actually not even be rudimentary ... only
Then I can run the following test:
So basically, the Of course, it needs a proper fix (there is already code that rewrites intrinsics, so I can add the same for binary operations). I'll try to fix this up in the next couple of days. |
@hbrunie , when do you need this? Also, do you need to convert the logical expressions back to Fortran, or are you ok with just testing the results using sympy (which has its own true/false)? |
@hiker this is not a hurry. I have implemented a draft (non robust) version in our own psyclone fork for the moment. |
@hbrunie , I have created a new branch: https://github.com/stfc/PSyclone/tree/2923_support_boolean_in_sympy |
I just realised that you want to evaluate the PSyIR expression, and as such you need to get back from SymPy to PSyIR. Looking at it, that is not that trivial, since logical sympy expression do not directly translate back to Fortran (the Sympy Reader basically converts the SymPy expression to a string, and then parses it with the Fortran parser). While I am certain that this can be done, I do wonder if we would actually need that support. Can't you evaluate the result in SymPy, e.g.:
I.e. you provide the values in the |
I believe I found a way to convert logical expressions back to PSyIR. While I still think that evaluation in SymPy might be better, this should give you both options. |
Your example works now as follows:
Notice that I converted the 2nd element of expressions to SymPy booleans (not string). The first assert is the sympy test, the second after converting back to PSyIR. It needs more testing :) |
Hi @hiker , I have tried with these expressions:
@pytest.mark.parametrize("expressions", [(".true. .and. .false.", False),
|
Can you try again with the latest version? I forgot to push the latest changes that support converting back to PSyIR - and as a side effect I had to replaced |
Thank you! these 2 commits make all the tests pass. I will clean the MR #2869 , are you ok if it will contain your commits on this issue? (I merged 2923_support_boolean_in_sympy into mine) |
I think it would be easier for the reviewer if this were a standalone PRs (smaller scope). I'll try to submit that tomorrow, I just need to check if I need additional tests for covering the individual files. |
I have #2997 ready (I've added your example as test, and also fixed coverage). I still need to run CI, but will wait till Monday to submit this PR |
Hi @hiker , am I missing something here on the way to use SympyWriter?
I wanted to use it that way:
but I managed to show this could not work because of that behavior:
This test throws this error:
You can find all the code in that branch / MR #2869
The text was updated successfully, but these errors were encountered: