Skip to content

performance #55

@rvignolo

Description

@rvignolo

Is there any way we can improve the performance when using a Python function for an ODEProblem?

I know that I can use something like:

jul_f = de.eval("""
function f(du,u,p,t)
  x, y, z = u
  sigma, rho, beta = p
  du[1] = sigma * (y - x)
  du[2] = x * (rho - z) - y
  du[3] = x * y - beta * z
end""")

u0 = [1.0,0.0,0.0]
tspan = (0., 100.)
p = [10.0,28.0,2.66]
prob = de.ODEProblem(jul_f, u0, tspan, p)
sol = de.solve(prob,saveat=t,abstol=1e-8,reltol=1e-8)

instead of

def f(du,u,p,t):
    x, y, z = u
    sigma, rho, beta = p
    du[0] = sigma * (y - x)
    du[1] = x * (rho - z) - y
    du[2] = x * y - beta * z

u0 = [1.0,0.0,0.0]
tspan = (0., 100.)
p = [10.0,28.0,2.66]
prob = de.ODEProblem(f, u0, tspan, p)
sol = de.solve(prob,saveat=t,abstol=1e-8,reltol=1e-8)

but I cannot translate my function to Julia code (it is way more complicated than this example and it relies in many Python objects and auxiliary functions).
Maybe what is making the code run slow is that PyCall.jl needs to convert python objects to julia objects and vice versa. So... is there any way I can let Julia or Python know the types of du, u and t.

Thanks! If there is no easy way to hack this it is fine, but I just wanted to know if I could make my code run faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions