SciML / diffeqpy

Solving differential equations in Python using DifferentialEquations.jl and the SciML Scientific Machine Learning organization
MIT License
531 stars 39 forks source link

No method array2py(NoiseGrid or NoiseFunction) #96

Closed vitusbenson closed 11 months ago

vitusbenson commented 2 years ago

I am changing the issue. It seems to me that "NoiseGrid" and "NoiseFunction from https://diffeq.sciml.ai/stable/features/noise_process/#noise_process do not work in diffeqpy.

MWE:

from julia import Main
Main.eval(
    """
    using Distributions
    using DifferentialEquations
    dt = 0.001
    t = range(0, stop = 1, step = dt)
    Wg = rand(Levy(0, dt*1e-11), length(t))
    W = NoiseGrid(t,Wg)
    """)

throws the error:

JuliaError: Exception 'MethodError: no method matching array2py(::NoiseGrid{Float64,0,Float64,Float64,Nothing,Nothing,false}, ::Int64, ::CartesianIndex{1})
Closest candidates are:
  array2py(::AbstractArray{var"#s76",N} where var"#s76", ::Integer, !Matched::CartesianIndex{N}) where N at /Users/testuser/.julia/packages/PyCall/3fwVL/src/conversions.jl:316
  array2py(::AbstractArray) at /Users/testuser/.julia/packages/PyCall/3fwVL/src/conversions.jl:332'

This is using Julia 1.5.4, DifferentialEquations v6.18.0, PyCall v1.92.5, Python 3.9.7, pyjulia 0.5.7, diffeqpy 1.2.0.

ChrisRackauckas commented 2 years ago

See https://diffeq.sciml.ai/stable/tutorials/jump_diffusion/

vitusbenson commented 2 years ago

Updated the Issue, appreciate any help from more advanced Julia users :-)

ChrisRackauckas commented 2 years ago

https://github.com/SciML/SciMLBase.jl/blob/master/src/SciMLBase.jl#L365

DiffEqNoiseProcess is an abstract array which must trigger something in PyCall to want to transform it into an array. @stevengj is there some way to tell it to use the non-array dispatch to make it build a generic object in Python matching the NoiseProcess?

ChrisRackauckas commented 11 months ago

Abstract noice processes work on v2.0

from diffeqpy import de

D = 1.0
W = de.WienerProcess(0.0,2*D)

def f(u,p,t):
    return 1.01*u

def g(u,p,t):
    return 0.87*u

u0 = 0.5
tspan = (0.0,1.0)
prob = de.SDEProblem(f,g,u0,tspan, noise=W)
sol = de.solve(prob)