I'm trying to call Julia scripts with Python to get some better speeds on functions I need to call a huge number of times (for some Monte Carlo type analyses). I've sucessfully installed and run Julia scripts in python via:
from julia import Main as JuliaMain # julia().<something> --> is deprecated, use Main instead
# julia.install() # use when running for the first time
script_julia = JuliaMain.include('juliascript.jl')
in addition to ensuring that PyCall is configured correctly in the Julia runtime.
Please correct me if I am wrong, but with my current understanding, this will compile any functions inside juliascript.jl
in the sense that Julia will figure out what the return type is and go through whatever motions it does when you call and/or define a function for the first time.
Consider that the defined function in juliascript.jl
is something like:
function f(x,y)
z = x + y
return z
end
If I call this function with x = JuliaMain.eval("f(1, 3)")
, will the speed of this function reflect a Julia function called more than once, or is it effectively being "recompiled" each time?
Furthermore, how can I call these defined functions without having to convert my request to a string to do so? I know from the docs that you can set and get variables directly, but this seems quite clumsy, and I was hoping there was a more elegant way, such as something in the format of JuliaMain.f(x, y)
or JuliaMain.runfunction.f(x, y)
, etc.