Open sdwfrost opened 6 months ago
Good to have this documented but I don't expect someone to fix it any time soon. Looks deep in RCall. Not sure how JuliaCall fixes it.
On the surface, it looks like it's just because the types from Symbolics.jl aren't wrapped (in this case, Num
). I thought that it would work OOTB as diffeqr
works ...
I thought it too would work the same way as diffeqr, so I'm a bit puzzled as to why RCall doesn't auto-wrap the same.
This code doesn't throw an error, but it gets stuck on modelingtoolkitize
. I'm not sure whether I'm wrapping wrong, or whether ModelingToolkit is just having a really hard time:
using OrdinaryDiffEq
using ModelingToolkit
using Symbolics
using RCall
RCall.sexp(::Type{RCall.Sxp}, x::Num) = RCall.sexp(x.val)
RCall.sexpclass(::Num) = RCall.Sxp
RCall.sexp(::Type{RCall.Sxp}, x::Term{Real, Base.ImmutableDict{DataType, Any}}) = RCall.sexp(eval(x))
RCall.sexpclass(::Term{Real, Base.ImmutableDict{DataType, Any}}) = RCall.Sxp
R"""
sir_ode_r <- function(u,p,t){
S <- u[1]
I <- u[2]
R <- u[3]
N <- S+I+R
beta <- p[1]
cee <- p[2]
gamma <- p[3]
dS <- -beta*cee*I/N*S
dI <- beta*cee*I/N*S - gamma*I
dR <- gamma*I
return(c(dS,dI,dR))
}
"""
function sir_ode_jl(u,p,t)
robj = rcall(:sir_ode_r, u, p, t)
return convert(Array,robj)
end
Ī“t = 0.1
tmax = 40.0
tspan = (0.0,tmax)
u0 = [990.0,10.0,0.0] # S,I,R
p = [0.05,10.0,0.25] # Ī²,c,Ī³
prob = ODEProblem{false}(sir_ode_jl, u0, tspan, p)
@named sys = modelingtoolkitize(prob)
Describe the bug š
I am trying to convert an ODEProblem that uses R code for the vector field to Julia using
modelingtoolkitize
. However, this throws an error due tono method matching sexpclass(::Num)
.Expected behavior
The function should return an
ODESystem
.Minimal Reproducible Example š
Error & Stacktrace ā ļø
Environment (please complete the following information):
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
The PythonCall version of this code works as expected.