You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Yes, it should be possible to do this with forpy. I think writing a python module to create a simple interface to tensorflow that is suited to your problem is a good approach. While you could import tensorflow and setup all the tensorflow stuff in Fortran in forpy, this would need a lot of boilerplate code.
I have not used tensorflow with forpy myself, but other people have: #21 (comment)
It should also not be a problem to use the subroutine demo in several places in your code, I'd just recommend to do the initialisation of forpy (forpy_initialize) outside of the subroutine, e.g. in the beginning of your program.
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:
And in the python script "python_wrapper.py", I need to do:
And with
forpy
, can we simply the process and do the following in thedemo.f90
?Or just in the
demo.f90
, canforpy
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 likeSo do I still need to write the above commands in the
outer.f90
?Thanks a lot!
The text was updated successfully, but these errors were encountered: