-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: f2py in numpy 2.0.1 does not expose variables to Python in modules containing only assignments. #27167
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 G 8000 itHub”, 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
Running into the same issue here. Our CI (which tests against a Fortran reference code) has been broken since NumPy 2.0. |
@HaoZeke Ping. |
Until a fix comes around, you can always add some bogus executable statements to the assignment module. They do not even need to be reachable. Worked fine for me. |
I can't reproduce this on NumPy main, I think this might be fixed:
@P-Kaempf is there any chance you can try again using Numpy 2.1.1? It looks like it's fixed there as well. |
Here is what I did:
==> Upgrading numpy
2.0.1 -> 2.1.1
==> Pouring numpy--2.1.1.arm64_sonoma.bottle.tar.gz
==> Caveats
To run `f2py`, you may need to `brew install ***@***.***`
and
==> Upgrading gcc
14.1.0_2 -> 14.2.0
==> Pouring gcc--14.2.0.arm64_sonoma.bottle.tar.gz
🍺 /opt/homebrew/Cellar/gcc/14.2.0: 1,913 files, 473.4MB
==> Running `brew cleanup gcc`...
then
***@***.*** geo % python
Python 3.12.6 (main, Sep 6 2024, 19:03:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>> import numpy
>> numpy.__version__
'2.1.1'
>>
but still, when running the compiled code, I get:
AttributeError: module 'geo.geoplot' has no attribute 'geoplot_globals'
only when I add this to the geoplot_globals module (which only contains variable declarations otherwise) can this error be avoided:
CONTAINS
SUBROUTINE DUMMY (UNSINN)
INTEGER :: UNSINN
OPEN(UNIT=29, FILE="/Users/peter/Applications/Python/PyVFE/geo/FOR29.txt", STATUS = 'UNKNOWN')
WRITE(29,"(I8)") UNSINN
CLOSE (29)
END SUBROUTINE DUMMY
This is an acceptable workaround. What is a bigger nuisance is that since numpy 2.0 all ASCII characters > 127 are not allowed in comments!
Best Regards,
Peter
… Am 20.09.2024 um 21:20 schrieb Nathan Goldbaum ***@***.***>:
I can't reproduce this on NumPy main, I think this might be fixed:
goldbaum at Nathans-MBP in ~/Documents/f2py-test on main!
± cat test.py
import f_test as f
maxN = f.f_globals.n_max
maxI = f.f_globals.i_max
maxJ = f.f_globals.j_max
goldbaum at Nathans-MBP in ~/Documents/f2py-test on main!
± f2py -c -m f_test F_GLOBALS.f90
Cannot use distutils backend with Python>=3.12, using meson backend instead.
Using meson backend
Will pass --lower to f2py
See https://numpy.org/doc/stable/f2py/buildtools/meson.html
Reading fortran codes...
Reading file 'F_GLOBALS.f90' (format:free)
Post-processing...
Block: f_test
Block: f_globals
Applying post-processing hooks...
character_backward_compatibility_hook
Post-processing (stage 2)...
Block: f_test
Block: unknown_interface
Block: f_globals
Building modules...
Building module "f_test"...
Constructing F90 module support for "f_globals"...
Variables: n_max i_max j_max
Wrote C/API module "f_test" to file "./f_testmodule.c"
Fortran 90 wrappers are saved to "./f_test-f2pywrappers2.f90"
The Meson build system
Version: 1.4.0
Source dir: /private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/tmpkizrdx_4
Build dir: /private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/tmpkizrdx_4/bbdir
Build type: native build
Project name: f_test
Project version: 0.1
Fortran compiler for the host machine: gfortran (gcc 14.2.0 "GNU Fortran (Homebrew GCC 14.2.0) 14.2.0")
Fortran linker for the host machine: gfortran ld64 1053.12
C compiler for the host machine: ccache cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
C linker for the host machine: cc ld64 1053.12
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program /Users/goldbaum/.pyenv/versions/3.12.3/bin/python found: YES (/Users/goldbaum/.pyenv/versions/3.12.3/bin/python)
Found pkg-config: YES (/opt/homebrew/bin/pkg-config) 0.29.2
Run-time dependency python found: YES 3.12
Library quadmath found: YES
Build targets in project: 1
Found ninja-1.11.1.git.kitware.jobserver-1 at /Users/goldbaum/.pyenv/versions/3.12.3/bin/ninja
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /Users/goldbaum/.pyenv/versions/3.12.3/bin/ninja -C /private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/tmpkizrdx_4/bbdir
ninja: Entering directory `/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/tmpkizrdx_4/bbdir'
[6/6] Linking target f_test.cpython-312-darwin.so
goldbaum at Nathans-MBP in ~/Documents/f2py-test on main!
± python test.py
@P-Kaempf <https://github.com/P-Kaempf> is there any chance you can try again using Numpy 2.1.1?
—
Reply to this email directly, view it on GitHub <#27167 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAQ5YLJLBVLJDNWZZDZSWFDZXRYODAVCNFSM6AAAAABMJLFJR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRUGQYTMMRQGA>.
You are receiving this because you were mentioned.
|
Does the example in the issue trigger the bug for you? The output you shared looks like it's about different code. If it doesn't can you share an example I can trigger the issue with? If you are still able to reproduce the issue as described, then either I made a mistake trying to reproduce it, or there's some difference in our environments. For the non-ASCII character thing, please file a separate issue about that so it doesn't get lost, assuming there isn't an open issue already. |
The example is an excerpt from a much longer code file. Indeed, if I run this short example, it works now as advertised. I need to isolate the issue better. I cannot post an example with more than 6300 lines! |
The sample needs some executable added. Here is the minimum viable code for reproducing the issue: Fortran:
Python:
peter@MBP2023 geo % python test.py |
This is fixed by #27695 From the fortran code in #27167 (comment) saved to a file python -m numpy.f2py -c -m fbug fbug.f90 The function works as expected.
I'll leave this open since I want to add a test and a release note for #27695 anyway. EDIT: @P-Kaempf did you open an issue for the ASCII thing suggested by @ngoldbaum? |
Describe the issue:
Take this F90 module:
When compiled with f2py 2.0.1 and included as "f_test" in a Python script, this:
will cause this error message:
Reproduce the code example:
Error message:
Python and NumPy Versions:
Python 3.12.4
numpy 2.0.1
Fortran compiler for the host machine: gfortran (gcc 14.1.0 "GNU Fortran (Homebrew GCC 14.1.0_2) 14.1.0")
Fortran linker for the host machine: gfortran ld64 1053.12
C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
C linker for the host machine: cc ld64 1053.12
Host machine cpu family: aarch64
Host machine cpu: aarch64
Runtime Environment:
Python 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Context for the issue:
Code which ran fine in numpy 1.26 fails to run in numpy 2.0.1.
A simple if ugly workaround is to add some executable code within the module. Only then will it become visible in Python, including all the assigned variables..
The text was updated successfully, but these errors were encountered: