-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Fix common block handling in f2py #22657
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
This looks like it really is all there is to it? Can you just copy the failing example from the issue as a test? |
It did fix the issue, but then I noticed some of the other parts of the code depend on hard-coded values of this counter (e.g. generating wrapper files), so incrementing the counter probably introduces additional bugs. Will take a closer look soon. |
A better fix would be to change the variable names so the |
@charris this bug is present from |
ping @pearu or anyone else from the f2py team for a review |
Thank you for this PR! I did a crude check of this PR on my setup. Crude means: I did not install this version of numpy, but I used my existing numpy installation 1.23.5 and replaced the folder f2py with the one from this PR. I used this workaround successfully before, using the f2py folder from numpy 1.19.5, which allows me to compile our project. Unfortunately, this patch here does not seem fix everything. It definitely fails less, but I still get an error on one of our fortran codes:
Sorry, I cannot give a minimal reproducer, the fortran codes which we wrap are very complex and I am not an expert. If you want to try it out yourself, you can get the code from git@github.com:impy-project/chromo.git. Compile with |
close/reopen |
I would like to test this PR locally on chromo, but when I try to check this branch out locally, I get this error
I am not sure how this fix. Edit: Nevermind, I got it to work. I cloned numpy again from scratch. |
Firstly, I am extremely grateful to @HaoZeke for trying to figure this out. We are testing this PR over here in our project impy-project/chromo#127 Unfortunately the latest version still does not work on the module |
@HDembinski @afedynitch could you test this? @HaoZeke I think a rebase will fix the test failure on azure. |
We are currently testing it, much thanks to @HaoZeke Side-comment: considering how complex the crackfortran code is, it may be a good target for a rewrite using a formal parser. I personally had only good experiences with the lark library in Python, which allows you to specify the rules in EBNF notation. Lark can generate a standalone parser in Python from this spec, so client code does not even need the lark library as a dependency. I just leave this here as a note. |
@HDembinski Any success? I'd like to get this in before the 1.25 release if it works. |
@charris In most cases, this seems to work. We identified a problem that happens only on Windows, whereas the same code parses well on mac and linux, and was parsing fine on pre-1.20 on Windows. Also, we have seem some changes to the interface that were easy to fix but we were wondering if they are intentional, such as a difference the interpretation of character* arrays. Except that Windows problem, which I believe is a bug, the other issues are not a problem for us but may break some backward compatibility. |
@HaoZeke Ping. @HDembinski Would it be helpful to put this in as is? |
@afedynitch is currently handling this so I don't have the full overview. As far as I understand, we may be able to deal with it on our end by making code changes, but it is still a regression: the code we had is parsed in a different way and that requires adaptations in both the legacy Fortran and in the Python code. |
Yes, the present version solves most of our problems. But the windows issue might be a bug that you wouldn't want to put in, I guess. Maybe this is some sort of encoding issue, but it wasn't there with previous versions. Better if @HaoZeke can look at it shortly once more. UPDATE: @charris It doesn't work on Windows. Most codes are missing the common block wrappers in -f2pywrappers.f |
Sounds like there are still some problems. @HaoZeke Could you revisit this? |
@pearu Thoughts? |
@HaoZeke Could you relate to the comment that
|
The change in interpretation was part of #19388 and is also related to #24008 which should be fixed by #24299. These are however separate from the common block handling and shouldn't be covered here. |
Thanks @HaoZeke |
Thanks @HaoZeke for fixing the issue! Indeed, you were right about the Windows bug being unrelated. It is cause by f2py --include-paths not picking up the colon separators for the multiple include paths required by our code. I filed it separately #24533 . |
On a different note... is this fix going to be backported? |
I think that would be a good idea, @charris ? |
It was backported yesterday. |
@HDembinski could you try building `numpy` with numpy/numpy#22657 and running this branch? It should pass. Closes #117. --------- Co-authored-by: Hans Dembinski <hans.dembinski@gmail.com> Co-authored-by: afedynitch <afedynitch@gmail.com> Co-authored-by: Anton Prosekin <ayprosekin@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Closes #22648.
The issue is that some part of the parser updates the
groupcounter
when it shouldn't.EDIT: The actual issue can be traced to e6dab4f where the parser was updated to include the Fortran 2008 block construct, which is used in several other places in the file and caused the issue.