Giter Club home page Giter Club logo

Comments (4)

ChrisRackauckas avatar ChrisRackauckas commented on August 25, 2024

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.

from modelingtoolkit.jl.

sdwfrost avatar sdwfrost commented on August 25, 2024

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 ...

from modelingtoolkit.jl.

ChrisRackauckas avatar ChrisRackauckas commented on August 25, 2024

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.

from modelingtoolkit.jl.

sdwfrost avatar sdwfrost commented on August 25, 2024

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)

from modelingtoolkit.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.