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

MethodError: no method matching copyto! #48

Closed
Volker-Weissmann opened this issue Jul 3, 2021 · 2 comments
Closed

MethodError: no method matching copyto! #48

Volker-Weissmann opened this issue Jul 3, 2021 · 2 comments

Comments

@Volker-Weissmann
Copy link

Running this code

using SimpleDiffEq
f(u,p,t) = 2u
g(u,p,t) = 1
u0 = 0.5
tspan = (0.0,1.0)
prob = SDEProblem(f,g,u0,tspan)
sol = solve(prob,SimpleEM(),dt=0.25)
g(du,u,p,t) = du .= 2.0 * u
function f(du, u, p, t)
    g(du,u,p,t)
end

using SimpleDiffEq
f(u,p,t) = 2u
g(u,p,t) = 1
u0 = 0.5
tspan = (0.0,1.0)
prob = SDEProblem(f,g,u0,tspan)
sol = solve(prob,SimpleEM(),dt=0.25)
g(du,u,p,t) = du .= 2.0 * u
function f(du, u, p, t)
    g(du,u,p,t)
end

outputs:

ERROR: LoadError: MethodError: no method matching copyto!(::Float64, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Tuple{}, typeof(identity), Tuple{Float64}})
Closest candidates are:
  copyto!(::DiffEqArrayOperator, ::Any) at /home/volker/.julia/packages/SciMLBase/dyqr8/src/operators/basic_operators.jl:112
  copyto!(::Any, ::Base.Broadcast.Broadcasted{var"#s155", Axes, F, Args} where {var"#s155"<:StaticArrays.StaticArrayStyle, Axes, F, Args<:Tuple}) at /home/volker/.julia/packages/StaticArrays/xV8rq/src/broadcast.jl:29
  copyto!(::DiffEqBase.DiffEqBC, ::Base.Broadcast.Broadcasted{var"#s7", Axes, F, Args} where {var"#s7"<:Base.Broadcast.AbstractArrayStyle{0}, Axes, F, Args<:Tuple}) at /home/volker/.julia/packages/DiffEqBase/qntkj/src/diffeqfastbc.jl:42
  ...
Stacktrace:
 [1] materialize!
   @ ./broadcast.jl:894 [inlined]
 [2] materialize!
   @ ./broadcast.jl:891 [inlined]
 [3] g(du::Float64, u::Float64, p::SciMLBase.NullParameters, t::Float64)
   @ Main ~/Sync/DatenVolker/git/sm_with_julia/bug.jl:8
 [4] f(du::Float64, u::Float64, p::SciMLBase.NullParameters, t::Float64)
   @ Main ~/Sync/DatenVolker/git/sm_with_julia/bug.jl:10
 [5] (::SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing})(::Float64, ::Vararg{Any, N} where N)
   @ SciMLBase ~/.julia/packages/SciMLBase/dyqr8/src/scimlfunctions.jl:395
 [6] solve(::SDEProblem{Float64, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(g), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, ::SimpleEM; dt::Float64)
   @ SimpleDiffEq ~/.julia/packages/SimpleDiffEq/vIpeG/src/euler_maruyama.jl:57
 [7] top-level scope
   @ ~/Sync/DatenVolker/git/sm_with_julia/bug.jl:19
in expression starting at /home/volker/Sync/DatenVolker/git/sm_with_julia/bug.jl:19
@YingboMa
Copy link
Member

YingboMa commented Jul 3, 2021

u0 should be an array, given your ODE definition. Try u0 = [0.5]

@YingboMa YingboMa closed this as completed Jul 3, 2021
@ChrisRackauckas
Copy link
Member

For standard solvers you now get:

using StochasticDiffEq
f(u,p,t) = 2u
g(u,p,t) = 1
u0 = 0.5
tspan = (0.0,1.0)
prob = SDEProblem(f,g,u0,tspan)
sol = solve(prob,EM(),dt=0.25)
ERROR: Initial condition incompatible with functional form.
Detected an in-place function with an initial condition of type Number or SArray.
This is incompatible because Numbers cannot be mutated, i.e.
`x = 2.0; y = 2.0; x .= y` will error.

If using a immutable initial condition type, please use the out-of-place form.
I.e. define the function `du=f(u,p,t)` instead of attempting to "mutate" the immutable `du`.

If your differential equation function was defined with multiple dispatches and one is
in-place, then the automatic detection will choose in-place. In this case, override the
choice in the problem constructor, i.e. `ODEProblem{false}(f,u0,tspan,p,kwargs...)`.

For a longer discussion on mutability vs immutability and in-place vs out-of-place, see:
https://diffeq.sciml.ai/stable/tutorials/faster_ode_example/#Example-Accelerating-a-Non-Stiff-Equation:-The-Lorenz-Equation

Stacktrace:
 [1] get_concrete_u0(prob::SDEProblem{Float64, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(g), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, isadapt::Bool, t0::Float64, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:u0, :p, :dt), Tuple{Float64, SciMLBase.NullParameters, Float64}}})
   @ DiffEqBase C:\Users\accou\.julia\dev\DiffEqBase\src\solve.jl:490
 [2] get_concrete_problem(prob::SDEProblem{Float64, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(g), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, isadapt::Bool; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:u0, :p, :dt), Tuple{Float64, SciMLBase.NullParameters, Float64}}})
   @ DiffEqBase C:\Users\accou\.julia\dev\DiffEqBase\src\solve.jl:388
 [3] solve_up(prob::SDEProblem{Float64, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(g), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, sensealg::Nothing, u0::Float64, p::SciMLBase.NullParameters, args::EM{true}; kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:dt,), Tuple{Float64}}})
   @ DiffEqBase C:\Users\accou\.julia\dev\DiffEqBase\src\solve.jl:313
 [4] solve(prob::SDEProblem{Float64, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, typeof(f), typeof(g), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(g), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, args::EM{true}; sensealg::Nothing, u0::Nothing, p::Nothing, kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:dt,), Tuple{Float64}}})
   @ DiffEqBase C:\Users\accou\.julia\dev\DiffEqBase\src\solve.jl:299
 [5] top-level scope
   @ c:\Users\accou\OneDrive\Computer\Desktop\test.jl:19

SimpleDiffEq.jl is by definition not a standard differential equation solver library, and has overly simplified implementations for very specific purposes. For that reason, it doesn't do the same error catching here, though we should think about whether it should be linked into that system in the future.

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

No branches or pull requests

3 participants