Stream: general
Topic: Cython
Ufuk Turuncoglu (Jun 16 2021 at 06:40):
I am trying to create a Python wrapper for Fortan code using Cython but i need help to split the Cython module to pxd and pyx files and sharing it with another module. I just wonder that is there anybody in the list that has Cython experience and willing to help me to pass couple of issue in the prototype application.
Anderson Banihirwe (Jun 16 2021 at 15:28):
Ccing @Austin Kootz, @Orhan Eroglu - -The resident experts for interfacing Python with Fortran -- in case they are able to help :slight_smile:
Austin Kootz (Jun 16 2021 at 16:03):
@Ufuk Turuncoglu I would strongly reccomend using numpy's f2py
package to compile your fortran into an importable python shared object file.
Austin Kootz (Jun 16 2021 at 16:04):
I'm open to scheduling a one-one tutorial on how to do that.
Ufuk Turuncoglu (Jun 16 2021 at 16:41):
Thanks for your help and suggestion @Austin Kootz. Actually, my simple project has lots of user defined data types which i know it is not supported by f2py. There is an extension of f2py, which is called as f90wrap, to support user defined Fortran data types but it seems it is not working in my case (maybe it is lack of my experience) and seems hiding all the details to make customizations. So, my limited experience directed to me a Cython. I know you need to do lots of things manually but it allow you to make customization and full control. Anyway, let me know what do you think?
Austin Kootz (Jun 16 2021 at 16:46):
Frankly we found Cython solutions unworkable. In fact we replaced our cython based stack to f2py last year, and it took us only about 10% as long to re implement everything compared to the first cython implementation.
Austin Kootz (Jun 16 2021 at 16:47):
I would strongly suggest re-working the user-defined data types into types that are supported by f2py, and then using it.
Ufuk Turuncoglu (Jun 16 2021 at 16:59):
@Austin Kootz the user defined types are not part of the code that i developed and they are coming from an external library. Also, the functions that i am trying to expose to Python also coming from that external library. So, i have no control on those parts. I am just trying to create a wrapper around it. Do you think still i could use it f2py?
Ufuk Turuncoglu (Jun 16 2021 at 17:00):
@Austin Kootz Maybe we could meet in your free time and i could try to explain what i am plaing to do it.
Austin Kootz (Jun 16 2021 at 17:04):
Just give me some nouns so I can look at the code for a minute. What's the external library that you are trying to expose?
Ufuk Turuncoglu (Jun 16 2021 at 17:07):
It is ESMF (https://github.com/esmf-org/esmf) and i am trying to write followng sample code in Python (https://github.com/esmf-org/nuopc-app-prototypes/tree/develop/SingleModelProto). At this point i am just aiming driver.F90
file. My initial implementation is in here https://github.com/uturuncoglu/SingleModelProtoPy but this does not have all the code that i have. i did not push my recent development but this could give you an idea.
Austin Kootz (Jun 16 2021 at 17:13):
ESMF is already available in python's conda package manager, and has a python interface here: https://github.com/esmf-org/esmf/blob/develop/src/addon/ESMPy/README.md
Austin Kootz (Jun 16 2021 at 17:15):
Driver.py should be easy to use with f2py
Austin Kootz (Jun 16 2021 at 17:16):
Are you on darwin(macos) or linux?
Ufuk Turuncoglu (Jun 16 2021 at 17:19):
Yes, i know and i am also workin as a part of ESMF team. the ESMPy is very limited capabilityit does not provide what i need. It just have loose connection with ESMF for just regridding etc. and there is no way to call core ESMF functions from Python using ESMPy. For example, if you look at ESMF_Init call (https://github.com/esmf-org/esmf/blob/develop/src/Superstructure/ESMFMod/src/ESMF_Init.F90) it uses couple of user defined types that might be defined in the Python layer. Anyway, i am still learning but if you think that it could be done with f2py, then i could chnage my approach and go with f2py.
Ufuk Turuncoglu (Jun 16 2021 at 17:21):
I prefer to use Linux. I had previously issue with MPI implementation under MacOS. The code also need to run in parallel. So, all those functions defined in ESMF side are collective operations that ESMPy does not support it as we need.
Austin Kootz (Jun 16 2021 at 17:38):
Linux is good, f2py works great on that platform. you'll want to make sure you have numpy >=1.20.2 and gfortran_linux-64 installed from the conda-forge channel in your conda environment.
Ufuk Turuncoglu (Jun 16 2021 at 17:39):
I am doing my development on Cheyenne and i could install all the requiremsnts to my user with pip.
Austin Kootz (Jun 16 2021 at 17:40):
on cheyenne, you can also use conda.
Austin Kootz (Jun 16 2021 at 17:41):
https://docs.conda.io/en/latest/miniconda.html#linux-installers
Ufuk Turuncoglu (Jun 16 2021 at 17:41):
sure. if you have time this week we could discuss about it. i am not sure how initial desing will look like.
Austin Kootz (Jun 16 2021 at 17:41):
And I would strongly advise using conda so as to have far more control and separation for your various python environements.
Austin Kootz (Jun 16 2021 at 17:42):
3:30 MDT tomorrow works for me.
Ufuk Turuncoglu (Jun 16 2021 at 17:43):
okay. that is good idea. btw, i am scheduling a call for that time.
Ufuk Turuncoglu (Jun 16 2021 at 17:43):
thanks for your help
Ufuk Turuncoglu (Jun 16 2021 at 17:45):
I have just sent it, if you did not get invitation just let me know
Last updated: Jan 30 2022 at 12:01 UTC