Giter Site home page Giter Site logo

ylikx / forpy Goto Github PK

View Code? Open in Web Editor NEW
206.0 206.0 52.0 1.48 MB

Forpy - use Python from Fortran

License: GNU Lesser General Public License v3.0

Fortran 78.53% Python 20.68% Makefile 0.53% C++ 0.26%
fortran fortran-library fortran2003 interoperability language-bindings numpy python

forpy's People

Contributors

awvwgk avatar mgovoni-devel avatar robertrueger avatar ylikx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forpy's Issues

Support for tensorflow and fortran 90?

Currently I am running an atmospheric model which was written by Fortran 90. In some subroutines I made some innovations using python (mainly tensorflow). Now I need to implement this python code into Fortran, so is there any wrapper to do this? just calling python within a Fortran subroutine?
I knew that your forpy could do this. But I am suspecting could it help me to import tensorflow into Fortran?

Here is the pseudo code of my basic thoughts:

SUBROUTINE demo(INPUTS, OUTPUTS)
! Definition of INPUTS
REAL, DIMENSION(:,:,:,:), INTENT(IN) :: PINPUTS
REAL, DIMENSION(:,:,:,:), INTENT(IN) :: POUTPUTS

PINPUTS = INPUTS

! using some python wrappers
POUTPUTS = python_wrapper(PINPUTS)

OUTPUTS = POUTPUTS
END SUBROUTINE demo

And in the python script "python_wrapper.py", I need to do:

import tensorflow as tf

# read saved model "model_saved";
# get the variables "OUTPUTS" passed from demo.f90;

prediction = model_saved.predict(OUTPUTS)

# then pass this variable "prediction" back to Fortran subroutine demo.f90;
# so that the "prediction" will be used for following calculation of the atmospheric model

And with forpy, can we simply the process and do the following in the demo.f90?

SUBROUTINE demo_sim(INPUTS, OUTPUTS)
! Definition of INPUTS
REAL, DIMENSION(:,:,:,:), INTENT(IN) :: PINPUTS
REAL, DIMENSION(:,:,:,:), INTENT(IN) :: POUTPUTS

PINPUTS = INPUTS

! using forpy to import the tf model saved in my computer
python_model = forpy(./saved_model)
POUTPUTS = python_wrapper(PINPUTS)

OUTPUTS = POUTPUTS
END SUBROUTINE demo_sim

Or just in the demo.f90, can forpy do the wrapper things?

One more thing, the subroutine demo or. demo_sim needs to be called in other subroutine (for example, outer.f90) of the atmospheric model. So how can I use this subroutine? I see that in your readme file I need to write something like

# Python 3.8 and higher
gfortran -c forpy_mod.F90
gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags --embed

So do I still need to write the above commands in the outer.f90?

Thanks a lot!

Compiler optimization related issues when Fortran array is indirectly modified by ndarray or pointer to ndarray data

When a Fortran array is modified indirectly by a ndarray or a pointer to ndarray data, compiler optimizations can cause that an outdated value is obtained from a Fortran array buffer that backs a ndarray.
The same issue occurs with MPI libraries when used in Fortran, see the discussion in Problems with Code Movement and Register Optimization [1].

For example:

program test
use forpy_mod
implicit none

integer ierror
ierror = forpy_initialize()
call sub
call forpy_finalize

CONTAINS

subroutine sub()
integer ierror
integer :: array(1)
integer, pointer, dimension(:) :: ptr
type(ndarray) :: nd_arr
integer b

array(1) = 5

ierror = ndarray_create(nd_arr, array)
ierror = nd_arr%get_data(ptr)

b = array(1)
ptr(1) = 9
! compiler assumes that array(1) has not changed 
! through ptr and might optimize the following line away
b = array(1) 

! when compiled with ifort -O1, prints the old array(1) value "5"
write(*,*) "should print 9: ", b
call nd_arr%destroy
end subroutine

end program

This example gives a wrong result with ifort 19 and -O1 or higher. gfortran 5.4.0 gives the correct result.

Solutions (see also [1]):

  1. Add the asynchronous attribute to the declaration of array:
integer, asynchronous :: array(1)
  1. use the volatile attribute, however [1] argues that this is slow
  2. turn off compiler optimizations
  3. no problem, if Fortran array is not modified directly or indirectly
  4. use a special "barrier" function with the Fortran buffer as argument, such that the compiler has to assume that the buffer could have been updated

Adding the target attribute also works in this example, but according to [1] this does not solve issues with code movement optimizations.

[1] MPI: A Message-Passing Interface Standard Version 3.1, https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node427.htm#Node427

Time measurements / wallclock time failure

Hi,
I tried to measure the performance of matrix multiplication of Numpy's np.matmul() embedded with Forpy in Fortran vs. Fortrans intrinsic matmul(). As this is aimed at a parallel environment I was initially using a wallclock based timer. But apparently wallclock based timing fails to capture the time consumption of embedded Python and display underestimated runtimes.
Cpu time based approaches seem to give valid results (in a non parallel test case).

cpu time vs. wallclock time

Do you have an idea, why the wallclock timer does not work here?

This is work in progress, but if you are interested in source code:
https://github.com/suessspeise/matmul_benchmark

Python function returning a list results in an empty list when converting to Forpy list

Hi,

most probably I'm missing something important, any light you can shed on this will be most welcomed.

A simple Python function:

def return_list:
    return [ 0, 1, 2 ]

I'm trying to wrap this function using Forpy. Excerpts of code, since module import and all preliminary operations work as expected, tested with functions that return simple data types as integers:

type(list) :: arr
type(object) :: out 
integer :: c

ierror = call_py(out, mymodule, "return_list")

ierror = list_create(arr, out)

ierror = arr%len(c)

and c happens to be -1, which I interprete as an empty list. What I'm doing wrong?

Thanks a lot.

test_ndarray fails in anaconda

I am getting some errors when running tests in linux with anaconda.

I solved the lto-wrapper error by updating the conda base environment. However, I get the following error

./test_ndarray
/home/user/miniconda3/lib/python3.7/site-packages/numpy/init.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Initialisation of forpy failed!!! Can not test. Errorcode = 2

mkl-service is installed and importing numpy in a script works.

in a not updated conda environment with a version of numpy that does not use mkl-service, I need to use -fno-lto to solve the lto-wrapper problem. However I still get the error:

./test_ndarray
Initialisation of forpy failed!!! Can not test. Errorcode = 2

None of the previous tests fails in both cases.

Configuration on Windows with Intel visual fortran complier

Hello, I’m trying to call some python modules of anaconda from FORTRAN program on Windows OS and intel visual fortran complier integrated in VS IDE. I tested the examples of forpy on linux with ifort which worked well but raised errors on Windows. The complier cannot recongnize the function used in forpy.f90 like '_Py_Initialize'. I didn't find the manual about configuration on Windows. Can you provide some detailed sugguestions about this situation? Many thanks!

forpy / python-script crashes when python multiprocesing is used

In #10 it has been mentioned

Regarding parallelism:
Multiprocessing (e.g. with MPI) should not be a problem as each process can have its own Python interpreter.

I have an application where the python program uses multiprocessing:

from multiprocessing import Pool, cpu_count
...
       n = min(ipar, cpu_count(), len(obj_list))
        with Pool(n) as pool:
            func = partial(prepare_map_plot, dict=dict,
                           gconf=gconf, fconf=fconf)
            pool.map(func, obj_list)

Note that I call (from fortran) forpy_initialize only once as suggested in #10.

Running the fortran program with forpy calling the python script terminates without any error message.
The same python script runs, if I use it off-line (thus not principle error in the python script).
Not my question is: Should that in principle work (and the issue might be related with my python installation or Linux Cluster)
and could somebody provide me a simple example (test case) involving a short fortran program and a corresponding
python script with multiprocessing? (Note: numpy needs to be included/used).

How to release the GIL

I am interested in calling a fortran function that uses some fortran libraries from python. However doing so locks the GIL in the python function call. Can Forpy release the GIL just like in F2PY?

Issue with forpy_initialize()

Hi,

First off, I’d like to thank you for the effort put into developing and maintaining this awesome software.

I’ve successfully compiled Forpy using ifort and ran the example codes without any issues. However, I encountered a problem when integrating Forpy into a climate model. When I call forpy_initialize(), the following fatal Python error occurs:

Fatal Python error: init_sys_streams: <stdin> is a directory, cannot continue
Python runtime state: core initialized
Current thread 0x0000150c85981f40 (most recent call first):
<no Python frame>

This error halts the model’s execution, and I am unsure how to proceed with debugging. I’m using the Python 3.11 library.

Any assistance or guidance on this matter would be immensely appreciated. Thank you once again for the great work on this software!

set python lib path

I try the example on windows with intel compiler, it only works when I put the compiled executable in the path where python.exe located, otherwise it throws the error that py initinlizer can not find python modules.

So I wonder how to set python lib path in the fortran part. Many thanks!

Py_finalize and segmentation fault - Running multiple routines

Calling a forpy subroutine multiple times results in a segmentation fault. This happens when the second instance of calling forpy_initialize() occurs.

Based on discussion here: #1
Is this related to requiring multiple interpreters / threading support?

Or, also related to operation of py_finalize?

Bugs and caveats: The destruction of modules and objects in modules is done in random order; this may cause destructors (__del__() methods) to fail when they depend on other objects (even functions) or modules. Dynamically loaded extension modules loaded by Python are not unloaded. Small amounts of memory allocated by the Python interpreter may not be freed (if you find a leak, please report it). Memory tied up in circular references between objects is not freed. Some memory allocated by extension modules may not be freed. Some extensions may not work properly if their initialization routine is called more than once; this can happen if an application calls Py_Initialize() and Py_Finalize() more than once.

Any help appreciated.

Segmentation fault error when calling ndarray_create

Hello,

I want to use forpy for a small fortran application on a cluster. Before developing this application, 6-8 months ago, I first tested forpy with the python feature I wanted to use in my application. Everything went fine, but now that I try to use forpy in my application, I get a segmentation fault error when I use "ndarray_create". Here is the backtrace of the error:

=================================
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
libifcoremt.so.5 00002B36FFF844A9 for__signal_handl Unknown Unknown
libpthread-2.17.s 00002B36FF179630 Unknown Unknown Unknown
libpython3.7m.so. 00002B36FF53295A PyObject_GetAttr Unknown Unknown
srda 000000000041DEED forpy_mod_mp_obje 4306 forpy_mod.f90
srda 0000000000434FFC forpy_mod_mp_call 6972 forpy_mod.f90
srda 0000000000436FF7 forpy_mod_mp_ndar 9969 forpy_mod.f90
srda 00000000004413B2 forpy_mod_mp_ndar 9494 forpy_mod.f90
srda 00000000004B5CB4 m_interpolation_m 71 m_interpolation.f90
srda 00000000004E8B5D m_data_assimilati 194 m_data_assimilation.f90
srda 00000000004EC1AB MAIN__ 88 master_data_assimilation.f90
srda 0000000000414BF2 Unknown Unknown Unknown
libc-2.17.so 00002B3702088545 __libc_start_main Unknown Unknown
srda 0000000000414B09 Unknown Unknown Unknown


And the fortran code that uses forpy is the following -- the number on the left are the line numbers:

38 subroutine downscaling(psil, psih, nxl, nxh)
39
40 use forpy_mod
41
42 implicit none
43
44 ! Input variables
45 integer, intent(in) :: nxl, nxh
46 real(8), dimension(nxl,nxl), intent(in) :: psil
47
48 ! Output variables
49 real(8), dimension(nxh,nxh), intent(out) :: psih
50
51 ! Local variables
52 integer :: ierror
53 real(8), dimension(:,:), pointer :: psihh
54
55 ! Forpy variables
56 type(tuple) :: args
57 type(module_py) :: mymodule, mytools
58 type(object) :: return_value
59 type(list) :: paths
60 type(ndarray) :: arr
61 type(ndarray) :: return_arr
62 character(len=:), allocatable :: return_string
63
64 ierror = forpy_initialize()
65
66 ! Instead of setting the environment variable PYTHONPATH,
67 ! we can add the current directory "." to sys.path
68 ierror = get_sys_path(paths)
69 ierror = paths%append(".")
70
71 ierror = ndarray_create(arr, psil)
72
73 ierror = tuple_create(args,1)
74 ierror = args%setitem(0,arr)
75
76 ierror = import_py(mymodule,"super_resolution_interface")
77 ierror = call_py(return_value, mymodule, "super_resolution_interface", args)
78
79 ierror = cast(return_arr, return_value)
80
81 ierror = return_arr%get_data(psihh, order='A')
82
83 psih(:,:) = psihh(:,:)
84
85 end subroutine downscaling

As the backtrace of the error shows, the problem in my code arises at line 71:

ierror = ndarray_create(arr, psil)

Any help would be really much appreciated.

A nice way to use forpy+matplotlib on Windows

Here an easy way to get going on a Windows machine if you like to work in the WSL environment.
Assuming you have installed WSL Ubuntu:

sudo apt install python3-pip
pip3 install python-config
pip3 install matplotlib
sudo apt install python3-tk

Install VcXsrv from https://sourceforge.net/projects/vcxsrv
Add "export DISPLAY=localhost:0.0" to ~/.bashrc

Restart your bash Window and it should work. You have to launch VcXsrv if it is not running.

This information was gathered from this post:
https://stackoverflow.com/questions/43397162/show-matplotlib-plots-in-ubuntu-windows-subsystem-for-linux

I feel that WSL is a good way to use Windows since Visual Studio Code allows a remote connection to open a folder. But to each his own.

How to use a Fortran function as argument to a Python method?

Suppose I have written a function in Fortran depending on some parameters I want to fit to data with scipy.optimize.curve_fit. How do I use this function as argument to a Python method?

I tried setitem with the function name and casting it to a Python object, but neither work in this case.

`UserWarning: mkl-service package failed to import ` in the import example

Hi,

I tried to do the example about import in https://github.com/ylikx/forpy#import-a-python-module-in-fortran

By gfortran -c forpy_mod.F90
and gfortran py-import.f90 forpy_mod.o python3-config --ldflags --embed -fno-lto -static-libgfortran (I named the file as py-import.f90 )

then run a.out, I got

/home/user/intel/oneapi/intelpython/latest/envs/idp-2/lib/python3.8/site-packages/numpy/__init__.py:159: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fd9f1b886aa
#1  0x7fd9f1b87fb5
#2  0x7fd9f14f620f
#3  0x7fd9f1a4e17e
#4  0x7fd9f1afd2a4
#5  0x7fd9f1ae1f08
#6  0x7fd9f1ae2137
#7  0x7fd9f14d70b2
#8  0x7fd9f1ae1ddd
#9  0xffffffffffffffff
Segmentation fault (core dumped)

My python 3.8.11 is from https://software.intel.com/en-us/python-distribution and https://www.intel.com/content/www/us/en/developer/articles/technical/using-intel-distribution-for-python-with-anaconda.html, not sure if intel-python has any issue with forpy

Change ndarray_create default to create a copy of the array that is passed?

So far ndarray_create creates a wrapper of the Fortran array that is passed to the function and uses the Fortran array as memory buffer for the numpy ndarray. This has the advantage that ndarray creation is fast and saves memory.
However, there are many caveats (see Working with arrays) for the user:

  • subtle bugs related to compiler optimization might occur (see issue #3),
  • the user must make sure that the buffer is valid as long as the ndarray exists (tricky when one wants to return a ndarray from a subroutine),
  • make sure that no temporary array is passed to the ndarray_create

Especially for new or casual users this is not ideal. Solutions to this issue could be:

  1. Let ndarray_create make a copy of the passed array. Offer previous functionality by providing a new function ndarray_create_nocopy for users who want efficiency
    Advantages: safer for the reasons stated above, list_create(a_list, some_object) etc. also create copies, the safe alternative would be default (could pass temporaries, no need to manage lifetime of buffer), option for efficiency for experienced users
    Disadvantages: existing code that relies on changes to the Fortran array affecting the ndarray and vice versa breaks, existing code runs slower/uses more memory due to additional copies

  2. OR: keep the existing ndarray_create, introduce ndarray_create_copy with the safer behaviour
    Advantages: no api change, existing code works as usual (but might be affected by issue #3)
    Disadvantages: not as intuitive, unsafe variant is default, list_create etc. creates copy but ndarray_create does not

Comments on this issue to let me know, what you prefer

Is it valid to use the same tuple by setting different values repeatedly?

In this code, I am trying to call Numpy np.sin(x) and np.cos(x) for different
value of x. Here, I am re-using the args variable by overwriting its content. Is this a valid approach, or do we need to re-initialize args by calling args % destroy every time setitem() is called?

type(module_py) :: np
type(tuple) :: args
type(object) :: ret
integer :: ierr
real(8) :: x

ierr = import_py( np, "numpy" )
ierr = tuple_create( args, 1 )   !! args = (*,) (1-tuple)
ierr = args % setitem( 0, 1.0d0 / 3.0d0 )   !! args[ 0 ] = 1.0 / 3.0
ierr = call_py( ret, np, "sin", args= args )   !! ret = np.sin( *args )
ierr = print_py( ret )

ierr = args % setitem( 0, 1.0d0 / 5.0d0 )   !! args[ 0 ] = 1.0 / 5.0
! ierr = args % setitem( 0, 100 )  !! this also works
ierr = call_py( ret, np, "cos", args= args )   !! ret = np.cos( *args )
ierr = print_py( ret )

(Also, I am wondering where is the best platform to ask this kind of question... e.g., Github issues, StackOverflow, Fortran Discourse, or comp.lang.fortran?)

Arch Linux and Python

In order to run the basic example in arch linux it is necessary do add the flag -lpython3.8. Assuming you are using bash, the command should be:
gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags` -lpython3.8

Print

So far I see that python print statements are flushed only when forpy is finalized.
Is there a way to flush the output when the python module is invoked? Unfortunately we cannot init/finalize multiple times.

Transposed arrays

When I create an array in Python, then pass it to Fortran as a return value, it is transposed in the process. This does not happen with arrays created in Fortran and then handed over to Python. Seemingly Forpy converts arrays properly and this particular use case might have been overseen.

This is how i created the array in Python

[...]
  nrow = random.randint(1,6)
  ncol = random.randint(1,6)
  array = np.random.rand(ncol,nrow).transpose()
  optional_array = {"ncols":ncol, "nrows": nrow, "data":array}
  kwargs["optional_array"] = optional_array
return kwargs

ifort linking error on linux machine

Dear Elias,
thanks for your valuable and useful project!

I would like to use forpy in my code in order to use some machine learning algorithm. My code is compiled with ifort.
So, while compiling and linking forpy with gfortran is ok, when I try with ifort it is a bit more problematic and I cannot successfully link it. I tried to disable lto also in ifort with -fno-fat-lto-objects but I still get an error:

In particular when I run:

ifort intro_to_forpy.F90 forpy_mod.o python3-config --ldflags

ld: /home/lk/intel/oneapi/intelpython/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a(posixmodule.o): in function os_forkpty': (.text.unlikely+0x2307): undefined reference to forkpty'
ld: /home/lk/intel/oneapi/intelpython/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a(posixmodule.o): in function os_openpty': (.text.unlikely+0x25e2): undefined reference to openpty'

Have you encountered such issue?

Thank you,
Lorenzo

PGI error

When I compile with PGI, I get the following error:

PGF90-S-0188-Argument number 1 to pyunicode_decodeutf8: type mismatch (forpy_mod.F90: 2173)
0 inform, 0 warnings, 1 severes, 0 fatal for forpy_initialize_unicode

Support for tensorflow or keras?

Hi I want to use forpy to import tensorflow or keras in one program. The code of fortran90 simply follows:

program keras_demo
    use forpy_mod
    implicit none
    
    integer :: ierror
    type(module_py) :: tensorflow

    ierror = forpy_initialize()
    ierror = import_py(tensorflow, "tensorflow")

    write(*,*) "tensorflow imported return value ", ierror
    call tensorflow%destroy
    call forpy_finalize
  
  end program

Then I run the command gfortran -c forpy_mod.F90 and gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags --embed` . The ./a.out shows tensorflow imported return value -1. When I run gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags` , it returns a long error message which ends with

ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status 

In your code it was said that the value of ierror should be 0 if the import py_module is successful. And I also checked the python version on my machine. In my VS Code terminal, I ran following codes and got returned messages as following:

$~ python --version
Python 2.7.16

$~ which python
/usr/bin/python

$~ which python-config
/usr/bin/python-config

$~ python-config --ldflags
 -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -framework CoreFoundation

$~ ls /usr/lib/libpython*
/usr/lib/libpython.dylib        /usr/lib/libpython2.7.dylib

But when I tried the same commands in terminal of my own Mac, it returned a different message:

$~ python --version
Python 3.7.10

$~ which python
/Users/xushan/opt/anaconda3/bin/python

$~ which python-config
/usr/bin/python-config

$~ python-config --ldflags
 -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -framework CoreFoundation

$~ ls /usr/lib/libpython*
/usr/lib/libpython.dylib        /usr/lib/libpython2.7.dylib

For the keras path, it's

from tensorflow import keras
keras.__path__
['/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorflow/keras']

import tensorflow as tf
tf.__path__
['/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorflow',
 '/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/api/_v2',
 '/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorboard/summary/_tf',
 '/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorflow',
 '/Users/xushan/opt/anaconda3/lib/python3.7/site-packages/tensorflow/_api/v2']

So does that mean my tensorflow is installed on my anoconda and forpy is not able to import it? I guess I need to do something to specify the python version? Thanks!

(btw, if I want to write something in fortran using your forpy to from keras.models import load_model, how can I write that? do I need to firstly import tensorflow in fortran90 subroutine, then import models, finally import load_model? is there any way to simply it? Thanks!)

Matplotlib Example Fails - sys.argv

I have built matplotlib example using Code Blocks and MinGW64 on Windows 10. This generates below error. Other provided examples build and run without issue.

Traceback (most recent call last): File "C:\Program Files\Python37\lib\site-packages\matplotlib\pyplot.py", line 2761, in plot return gca().plot( File "C:\Program Files\Python37\lib\site-packages\matplotlib\pyplot.py", line 879, in gca return gcf().gca(**kwargs) File "C:\Program Files\Python37\lib\site-packages\matplotlib\pyplot.py", line 611, in gcf return figure() File "C:\Program Files\Python37\lib\site-packages\matplotlib\pyplot.py", line 546, in figure **kwargs) File "C:\Program Files\Python37\lib\site-packages\matplotlib\backend_bases.py", line 3337, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig) File "C:\Program Files\Python37\lib\site-packages\matplotlib\backends\_backend_tk.py", line 876, in new_figure_manager_given_figure window = tk.Tk(className="matplotlib") File "C:\Program Files\Python37\Lib\tkinter\__init__.py", line 2018, in __init__ baseName = os.path.basename(sys.argv[0]) IndexError: list index out of range

I believe this is related to tkinter expecting sys.argv as detailed here:

matplotlib/matplotlib#14382

Could anyone advise how best to resolve this when using forpy?

Python 2: one reference leaks in ndarray_create

In Python 2, the memoryview + numpy.asarray combination for ndarray_create leads to one leaking reference. I am working on a rewrite using old-style Python 2 buffers.
With Python 3 it's fine though.

problem running example "intro_to_forpy.F90"

Hello,
I am a Fortran beginner and would like to use forpy for some plotting using matplotlib and later pyvista.

I tried your first and easiest example:

gfortran -c forpy_mod.F90
gfortran intro_to_forpy.F90 forpy_mod.o python3-config --ldflags --embed

And a file a.out was created.
When I call ./a.out I get this error message:

./a.out: error while loading shared libraries: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

Do you have an idea what to do next?
Best regards,
Jonas

Question about named argument

I'm not sure if it's possible to name an argument. For example, in the imshow matplotlib call there are named arguments that are optional. Is it possible to name an argument without adding other optional arguments? I don't see how to do this with tuple. These are not kwargs but it would be nice if dictionaries could be used for arguments.

Create a 2d Fortran matrix from a 2d numpy array

I could create a 1d Fortran matrix from a 1d numpy array using:

ierror = numpy_array%get_data(fortran_matrix)

but, when I try to do the same for a 2d matrix I get an ierror = -1 with no result returned.
Is there another function for doing this?

Building with Python 3.8 (or higher?)

In Python 3.8 python3-config --ldflags does not contain the flag to link with libpython anymore.
Use python3-config --ldflags --embed instead.

For example:

gfortran -c forpy_mod.F90
gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags --embed`

Error was shown when build command was employed

I use the last version of Geany IDE with sync to the last version of Anaconda.
I build my code in Windows 7 64-bit.
When I typed the build command:

# Python 3.8 and higher
gfortran -c forpy_mod.F90
gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags --embed`

, it showed errors:

gfortran: error: `python3-config: No such file or directory
gfortran: error: unrecognized command line option '--ldflags'
gfortran: error: unrecognized command line option '--embed`'
Compilation failed.

I want to know how this error appeared and how can I solve it?

Problem with matplotlib

Hello,
I get the following error with the matplotlib example:

Traceback (most recent call last):
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2811, in plot
return gca().plot(
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 935, in gca
return gcf().gca(**kwargs)
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 578, in gcf
return figure()
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 525, in figure
**kwargs)
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3218, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "/home/abest/.local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 1008, in new_figure_manager_given_figure
window = Tk.Tk(className="matplotlib")
File "/usr/lib64/python3.7/tkinter/init.py", line 2018, in init
baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range

After searching a little online, I have found that a workaround is this:
ierror = run_string("import sys;sys.argv.append('')");

Perhaps you could add that code to forpy_initialize.

Values transferred with np.copy() do not reach Fortran

I am trying to perform a simple matrix multiplication in embedded Python. This works just fine with return values. With in place operation on pointer arrays (ndarray_create_nocopy()) the results of computation done in Python do not necessarily end up in the Fortran representation of the array.

I do this on the Fortran side:

e = ndarray_create_nocopy(nd_A, A)
e = ndarray_create_nocopy(nd_B, B)
e = ndarray_create_nocopy(nd_C, C)
e = tuple_create(args,3)
e = args%setitem(0,nd_A)
e = args%setitem(1,nd_B)
e = args%setitem(2,nd_C)
e = call_py(receive_obj, wrapper, "matmul_copy", args)

With this Python function being called:

def matmul_copy(a, b, c, *args, **kwargs):
    d = np.matmul(a, b)
    c = np.copy(d) # or d.copy()

On the Python side, both c and d show the expected values. On the fortran side c will just consist of zero values. A element wise copy of the array solves, the problem (but is substantially slower).
As mentioned above, this is not a pressing issue, as it will work with return values. Nevertheless: could you help me understand this behaviour?

Matplotlib Example Fails

I'm attempting to run the Matplotlib Example using forpy installed on an iMacPro running Mac OS X Mojave (ver. 10.14.5) under the Anaconda distribution for Python 3.7.

Building the example (see the attached file Example1.F90.txt) was successful, but running a.out results with:

(base) Samuels-Mac-Pro:Matplotlib_example user$ touch *.F90
(base) Samuels-Mac-Pro:Matplotlib_example user$ gfortran -c forpy_mod.F90
(base) Samuels-Mac-Pro:Matplotlib_example user$ gfortran Example1.F90 forpy_mod.o python3-config --ldflags
(base) Samuels-Mac-Pro:Matplotlib_example user$ ./a.out
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001099ea5c0 (most recent call first):

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0 0x106edb39d
#1 0x106eda82b
#2 0x7fff59843b5c
Abort trap: 6
(base) Samuels-Mac-Pro:Matplotlib_example user$

Any suggestions?

Example1.F90.txt

Anaconda and Ubuntu 20.04: libgfortran.so.4 not found

The problem

Using Ubuntu's gfortran 9 together with Anaconda can lead to the following error:

./a.out: error while loading shared libraries: libgfortran.so.4: cannot open shared object file: No such file or directory

This is because gfortran 9 wrongly links with the libgfortran installed in the conda environment, which is libgfortran.so.4 instead of libgfortran.so.5 that is used by gfortran 9.

Possible solutions

  1. Use Anaconda's gfortran (version 7): install with conda install gfortran_linux-64. Anaconda's compiler tools use some non-standard names for the compiler executables: you have to use x86_64-conda_cos6-linux-gnu-gfortran instead of gfortran. Use the -fno-lto option in the linking step, otherwise the linking step hangs.
  2. OR: install Ubuntu's gfortran-7 with sudo apt install gfortran-7 and use that.
  3. OR: use gfortran 9 and statically link libgfortran with the option -static-libgfortran in the linking step.
  4. OR: use gfortran 9 and temporarily rename conda's <path to anaconda>/lib/libgfortran.so to something else (similar to suggestion in igraph/rigraph#275 (comment))

Probably not a good idea: Installing gfortran-7 or libgfortran4 and using gfortran 9 also seems to solve the problem for simple examples. However then the older libgfortran.so.4 is used instead of libgfortran.so.5

Segmentation Fault when working with arrays

Hello,
I'm having the following error when trying to run the Working with arrays examples. Specifically when using the functions: "ndarray_create", "ndarray_create_nocopy".
Do you know what might be causing this? I'm using Gfortran and Python3. Your examples with the tuples and dictionaries work well.
Thank you!
Regards,
Andrea

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x7f4541cf031a
#1 0x7f4541cef503
#2 0x7f4541922f1f
#3 0x7f45422c18ea
#4 0x55e3e0ec13b4
#5 0x55e3e0ebc437
#6 0x55e3e0ead2ed
#7 0x55e3e0ead715
#8 0x55e3e0eaf5f0
#9 0x55e3e0eb8e13
#10 0x55e3e0ea8f5a
#11 0x55e3e0ea8f9b
#12 0x7f4541905b96
#13 0x55e3e0ea8da9
#14 0xffffffffffffffff
Segmentation fault (core dumped)

The 'sklearn' PyPI package is deprecated, use 'scikit-learn'

Collecting sklearn (from forpy)
Using cached sklearn-0.0.post7.tar.gz (3.6 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
rather than 'sklearn' for pip commands.

  Here is how to fix this error in the main use cases:
  - use 'pip install scikit-learn' rather than 'pip install sklearn'
  - replace 'sklearn' by 'scikit-learn' in your pip requirements files
    (requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
  - if the 'sklearn' package is used by one of your dependencies,
    it would be great if you take some time to track which package uses
    'sklearn' instead of 'scikit-learn' and report it to their issue tracker
  - as a last resort, set the environment variable
    SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error

  More information is available at
  https://github.com/scikit-learn/sklearn-pypi-package

  If the previous advice does not cover your use case, feel free to report it at
  https://github.com/scikit-learn/sklearn-pypi-package/issues/new
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

(base) C:\Users\20204318>pip install scikit-learn
Requirement already satisfied: scikit-learn in c:\users\20204318\anaconda3\lib\site-packages (1.2.2)
Requirement already satisfied: numpy>=1.17.3 in c:\users\20204318\anaconda3\lib\site-packages (from scikit-learn) (1.25.0)
Requirement already satisfied: scipy>=1.3.2 in c:\users\20204318\anaconda3\lib\site-packages (from scikit-learn) (1.10.1)
Requirement already satisfied: joblib>=1.1.1 in c:\users\20204318\anaconda3\lib\site-packages (from scikit-learn) (1.2.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\20204318\anaconda3\lib\site-packages (from scikit-learn) (2.2.0)

Is there any way to call ABAQUS Python in ABAQUS UMAT?

I'm doing multiscale computation, so I need to call microscale ABAQUS Python in ABAQUS UMAT. And UMAT is usually written in Fortran, however, ABAQUS Python is a modified Python which could not be regarded as normal Python interpretor, the standard calling might not work well.
Is there any way to fix this problem?

Timing

Hello,
thank you very much for this valuable project!
I have a general question about timing. Have you done any time profiling of the different function calls?
I'm quite sensible to the topic because I plan to use forpy to call ML/NN within intensive Fortran sections.

Kind regards,
Lorenzo Campoli

'ld: symbol(s) not found for architecture x86_64' Problem with compiling the intro_to_forpy.F90 example on MacOS

I'm using the following gfortran:
GNU Fortran (Homebrew GCC 11.3.0_1) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My python version is 3.9.12 and package manager is conda.

Upon compiling the program with: gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto python3-config --ldflags
I get the following error:

$ gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto `python3-config --ldflags`
Undefined symbols for architecture x86_64:
  "_PyBool_FromLong", referenced from:
      ___forpy_mod_MOD_forpy_initialize_bool in forpy_mod.o
  "_PyBuffer_FillContiguousStrides", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
  "_PyBuffer_IsContiguous", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyBuffer_Release", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyBytes_AsString", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
  "_PyBytes_FromStringAndSize", referenced from:
      ___forpy_mod_MOD_box_value_char_1d_as_bytestr in forpy_mod.o
      ___forpy_mod_MOD_box_value_chars_as_bytestr in forpy_mod.o
  "_PyComplex_AsCComplex", referenced from:
      ___forpy_mod_MOD_unbox_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real32 in forpy_mod.o
  "_PyComplex_FromDoubles", referenced from:
      ___forpy_mod_MOD_box_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_box_value_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_complex in forpy_mod.o
  "_PyDict_Clear", referenced from:
      ___forpy_mod_MOD_dict_clear in forpy_mod.o
  "_PyDict_Copy", referenced from:
      ___forpy_mod_MOD_dict_copy in forpy_mod.o
  "_PyDict_GetItemString", referenced from:
      ___forpy_mod_MOD_print_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyDict_Items", referenced from:
      ___forpy_mod_MOD_dict_items in forpy_mod.o
  "_PyDict_Keys", referenced from:
      ___forpy_mod_MOD_dict_keys in forpy_mod.o
  "_PyDict_New", referenced from:
      ___forpy_mod_MOD_dict_create in forpy_mod.o
  "_PyDict_Values", referenced from:
      ___forpy_mod_MOD_dict_values in forpy_mod.o
  "_PyErr_Clear", referenced from:
      ___forpy_mod_MOD_err_clear in forpy_mod.o
      ___forpy_mod_MOD_is_ndarray in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyErr_GivenExceptionMatches", referenced from:
      ___forpy_mod_MOD_exception_matches in forpy_mod.o
  "_PyErr_Occurred", referenced from:
      ___forpy_mod_MOD_have_exception in forpy_mod.o
      ___forpy_mod_MOD_err_print in forpy_mod.o
      ___forpy_mod_MOD_exception_matches in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real32 in forpy_mod.o
      ...
  "_PyErr_Print", referenced from:
      ___forpy_mod_MOD_err_print in forpy_mod.o
  "_PyErr_SetString", referenced from:
      ___forpy_mod_MOD_raise_exception in forpy_mod.o
  "_PyEval_GetBuiltins", referenced from:
      ___forpy_mod_MOD_print_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyFloat_AsDouble", referenced from:
      ___forpy_mod_MOD_unbox_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real32 in forpy_mod.o
  "_PyFloat_FromDouble", referenced from:
      ___forpy_mod_MOD_box_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_box_value_real32 in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_float in forpy_mod.o
  "_PyImport_ImportModule", referenced from:
      ___forpy_mod_MOD_import_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_numpy in forpy_mod.o
  "_PyList_Append", referenced from:
      ___forpy_mod_MOD_list_append_chars in forpy_mod.o
      ___forpy_mod_MOD_list_append_char_1d in forpy_mod.o
      ___forpy_mod_MOD_list_append_logical in forpy_mod.o
      ___forpy_mod_MOD_list_append_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_list_append_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_list_append_real64 in forpy_mod.o
      ___forpy_mod_MOD_list_append_real32 in forpy_mod.o
      ...
  "_PyList_Insert", referenced from:
      ___forpy_mod_MOD_list_insert_int64 in forpy_mod.o
      ___forpy_mod_MOD_list_insert_int32 in forpy_mod.o
  "_PyList_New", referenced from:
      ___forpy_mod_MOD_list_create_empty in forpy_mod.o
  "_PyList_Reverse", referenced from:
      ___forpy_mod_MOD_list_reverse in forpy_mod.o
  "_PyList_Sort", referenced from:
      ___forpy_mod_MOD_list_sort in forpy_mod.o
  "_PyLong_AsLongLongAndOverflow", referenced from:
      ___forpy_mod_MOD_unbox_value_int64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_int32 in forpy_mod.o
  "_PyLong_FromLongLong", referenced from:
      ___forpy_mod_MOD_box_value_int64_as_long in forpy_mod.o
      ___forpy_mod_MOD_box_value_int32_as_long in forpy_mod.o
  "_PyMapping_HasKey", referenced from:
      ___forpy_mod_MOD_mapping_contains in forpy_mod.o
  "_PyMemoryView_FromBuffer", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
  "_PyModule_AddObject", referenced from:
      ___forpy_mod_MOD_pythonmodule_add_object in forpy_mod.o
  "_PyModule_Create2", referenced from:
      ___forpy_mod_MOD_pythonmodule_init in forpy_mod.o
  "_PyObject_Call", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_call_py_object in forpy_mod.o
  "_PyObject_DelItem", referenced from:
      ___forpy_mod_MOD_mapping_delitem_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_int64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_int32 in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_object in forpy_mod.o
  "_PyObject_GetAttr", referenced from:
      ___forpy_mod_MOD_object_getattribute in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_numpy in forpy_mod.o
  "_PyObject_GetBuffer", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyObject_GetItem", referenced from:
      ___forpy_mod_MOD_dict_get_helper2 in forpy_mod.o
      ___forpy_mod_MOD_dict_get_helper in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_complex_real32 in forpy_mod.o
      ...
  "_PyObject_IsInstance", referenced from:
      ___forpy_mod_MOD_is_ndarray in forpy_mod.o
  "_PyObject_IsTrue", referenced from:
      ___forpy_mod_MOD_unbox_value_logical in forpy_mod.o
  "_PyObject_Length", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_len_int64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_len_int32 in forpy_mod.o
      ___forpy_mod_MOD_sequence_len_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_len_int32 in forpy_mod.o
  "_PyObject_SetAttr", referenced from:
      ___forpy_mod_MOD_object_delattr in forpy_mod.o
      ___forpy_mod_MOD_object_setattr in forpy_mod.o
  "_PyObject_SetItem", referenced from:
      ___forpy_mod_MOD_dict_get_helper in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_real64 in forpy_mod.o
      ...
  "_PyObject_Str", referenced from:
      ___forpy_mod_MOD_cast_nonstrict_to_chars in forpy_mod.o
      ___forpy_mod_MOD_str_create_object in forpy_mod.o
  "_PyRun_SimpleString", referenced from:
      ___forpy_mod_MOD_run_string in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_sys_argv in forpy_mod.o
  "_PySequence_Concat", referenced from:
      ___forpy_mod_MOD_tuple_add in forpy_mod.o
      ___forpy_mod_MOD_list_add in forpy_mod.o
  "_PySequence_Contains", referenced from:
      ___forpy_mod_MOD_sequence_contains in forpy_mod.o
  "_PySequence_Count", referenced from:
      ___forpy_mod_MOD_sequence_count_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_count_int32 in forpy_mod.o
  "_PySequence_DelItem", referenced from:
      ___forpy_mod_MOD_list_delitem_int64 in forpy_mod.o
      ___forpy_mod_MOD_list_delitem_int32 in forpy_mod.o
  "_PySequence_GetItem", referenced from:
      ___forpy_mod_MOD_sequence_getitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_real64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_real32 in forpy_mod.o
      ...
  "_PySequence_Index", referenced from:
      ___forpy_mod_MOD_sequence_index_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_index_int32 in forpy_mod.o
  "_PySequence_List", referenced from:
      ___forpy_mod_MOD_list_create_object in forpy_mod.o
  "_PySequence_SetItem", referenced from:
      ___forpy_mod_MOD_mutablesequence_setitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_real64 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_real32 in forpy_mod.o
      ...
  "_PySequence_Tuple", referenced from:
      ___forpy_mod_MOD_tuple_create_object in forpy_mod.o
  "_PySys_GetObject", referenced from:
      ___forpy_mod_MOD_get_sys_path in forpy_mod.o
  "_PyTuple_New", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_tuple_create_int64 in forpy_mod.o
      ___forpy_mod_MOD_tuple_create_int32 in forpy_mod.o
  "_PyTuple_SetItem", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_object in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int32_object in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_complex_real64 in forpy_mod.o
      ...
  "_PyType_IsSubtype", referenced from:
      ___forpy_mod_MOD_is_unicode in forpy_mod.o
      ___forpy_mod_MOD_is_bool in forpy_mod.o
      ___forpy_mod_MOD_is_complex in forpy_mod.o
      ___forpy_mod_MOD_is_float in forpy_mod.o
  "_PyUnicode_AsUTF8AndSize", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
  "_PyUnicode_DecodeUTF8", referenced from:
      ___forpy_mod_MOD_box_value_char_1d_as_unicodestr in forpy_mod.o
      ___forpy_mod_MOD_box_value_chars_as_unicodestr in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_unicode in forpy_mod.o
  "_Py_DecRef", referenced from:
      ___forpy_mod_MOD_cast_nonstrict_to_chars in forpy_mod.o
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_complex_real32 in forpy_mod.o
      ...
  "_Py_Finalize", referenced from:
      ___forpy_mod_MOD_forpy_finalize in forpy_mod.o
  "_Py_IncRef", referenced from:
      ___forpy_mod_MOD_unsafe_cast_from_c_ptr in forpy_mod.o
      ___forpy_mod_MOD_pythonmodule_add_object in forpy_mod.o
      ___forpy_mod_MOD_assign_py_nonetype in forpy_mod.o
      ___forpy_mod_MOD_assign_py_module_py in forpy_mod.o
      ___forpy_mod_MOD_assign_py_type_py in forpy_mod.o
      ___forpy_mod_MOD_assign_py_ndarray in forpy_mod.o
      ___forpy_mod_MOD_assign_py_dict in forpy_mod.o
      ...
  "_Py_Initialize", referenced from:
      ___forpy_mod_MOD_forpy_initialize in forpy_mod.o
  "_Py_IsInitialized", referenced from:
      ___forpy_mod_MOD_forpy_initialize in forpy_mod.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Could you please help?

Thanking you

Best regards
Sankalp Jena

multiple initialize/finalize?

Is it possible to have multiple initialize/finalize statements?
It would be nice to confine forpy to given regions.

`/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x24): undefined reference to `main'`

Hi,

I tried to follow https://github.com/ylikx/forpy. gfortran -c forpy_mod.F90 gives me

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_run_string':
forpy_mod.F90:(.text+0x892): undefined reference to `PyRun_SimpleString'
/usr/bin/ld: forpy_mod.F90:(.text+0x8e9): undefined reference to `PyRun_SimpleString'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_get_sys_path':
forpy_mod.F90:(.text+0x92e): undefined reference to `PySys_GetObject'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_print_py':
forpy_mod.F90:(.text+0x990): undefined reference to `PyEval_GetBuiltins'
/usr/bin/ld: forpy_mod.F90:(.text+0x9bd): undefined reference to `PyDict_GetItemString'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_unsafe_cast_from_c_ptr':
forpy_mod.F90:(.text+0xbcb): undefined reference to `Py_IncRef'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_pythonmodule_add_object':
forpy_mod.F90:(.text+0x166e): undefined reference to `Py_IncRef'
/usr/bin/ld: forpy_mod.F90:(.text+0x16d8): undefined reference to `PyModule_AddObject'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_pythonmodule_init':
forpy_mod.F90:(.text+0x1bb7): undefined reference to `PyModule_Create2'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_raise_exception':
forpy_mod.F90:(.text+0x1c5f): undefined reference to `PyErr_SetString'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_have_exception':
forpy_mod.F90:(.text+0x1c7c): undefined reference to `PyErr_Occurred'
/usr/bin/ld: /tmp/ccyRLHly.o: in function `__forpy_mod_MOD_err_print':

I tried gfortran 9 and 11, both get these kinds of messages. Does forpy have any dependence? Thank you very much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.