Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to evaluate ODEProblems by pyabc's julia interface #638

Open
MG-dkfz opened this issue May 15, 2024 · 1 comment
Open

Unable to evaluate ODEProblems by pyabc's julia interface #638

MG-dkfz opened this issue May 15, 2024 · 1 comment
Labels

Comments

@MG-dkfz
Copy link

MG-dkfz commented May 15, 2024

Bug description
I was testing pyabc for models defined in Julia, and I was able to reproduce the example of the SIR model, i.e., using Gillespie's algorithm. That is, I could pre-compile the Julia code, evaluate the model from python, and then follow the remaining steps in the notebook to perform parameter inference. As a next step, I modified the SIR example into an ODE problem (see minimal example below). While I can pre-compile the Julia code and import the model function into python, I get a RuntimeError when I call the model from python (if I call the model function from Julia, everything is fine). This error has something to do with PyCall, and might therefore not be directly linked to pyabc. But I was wondering if there is some way to evaluate ODE models in Julia when using pyabc.

Expected behavior
Being able to work with ODE models in Julia when using pyabc.

To reproduce
In Julia:

# SIR.jl

module SIR

using DifferentialEquations

function sir_model!(du, u, p, t)
    r1, r2 = p
    du[1] = -r1 * u[1] * u[2]
    du[2] = (r1 * u[1] - r2) * u[2]
    du[3] = r2 * u[2]
end

# ground truth parameter
p = (0.0001, 0.01)
# initial state
u0 = [999, 1, 0]
# time span
tspan = (0.0, 250.0)

"""
Simulate model for parameters `10.0.^par`.
"""
function model(par)
    p = 10.0.^((par["p1"], par["p2"]))
    prob = ODEProblem(sir_model!, u0, tspan, p)
    sol = solve(prob, saveat=2.5)
    return Dict("t"=>sol.t, "u"=>sol.u)
end

end  # module

In Python:

from julia.api import Julia
jl = Julia(compiled_modules=False)
from pyabc.external.julia import Julia

jl = Julia(module_name="SIR", source_file="SIR.jl")

model = jl.model()
model({"p1": -4.0, "p2": -2.0}) # <- this throws a RuntimeError 

Environment
Python:
python 3.12,
pyabc 0.12.13,
julia 0.6.2

Julia:
Julia 1.9.3
DifferentialEquations 7.11.0
PyCall 1.96.4

@MG-dkfz MG-dkfz added the bug label May 15, 2024
@stephanmg
Copy link
Collaborator

stephanmg commented May 24, 2024

@MG-dkfz could you please provide the actual error message?

Update: Fails for me with TypeError: __init__() got an unexpected keyword argument 'compiled_modules'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants