Skip to content

Commit

Permalink
Fix StochSystem(::CoupledODEs) method (#20)
Browse files Browse the repository at this point in the history
* Fix `StochSystem(::CoupledODEs)` method

* add iip kwarg

---------

Co-authored-by: Reyk Börner <[email protected]>
  • Loading branch information
oameye and reykboerner authored Mar 20, 2024
1 parent a704f2c commit 7ca6c73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/StochSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ to_cds(sys::StochSystem) = CoupledODEs(sys)
Converts a [`CoupledODEs`](https://juliadynamics.github.io/DynamicalSystems.jl/stable/tutorial/#DynamicalSystemsBase.CoupledODEs)
system into a [`StochSystem`](@ref).
"""
StochSystem(ds::DynamicalSystemsBase.CoupledODEs; σ=0.0, g=idfunc, pg=nothing, Σ=I(length(get_state(ds))), process="WhiteGauss") =
StochSystem(dynamic_rule(ds), [ds.p0], get_state(ds), σ, g, pg, Σ, process)
StochSystem(ds::DynamicalSystemsBase.CoupledODEs, σ=0.0, g=idfunc, pg=nothing, Σ=I(length(get_state(ds))), process="WhiteGauss") =
StochSystem(dynamic_rule(ds), ds.p0, get_state(ds), σ, g, pg, Σ, process)
12 changes: 7 additions & 5 deletions src/trajectories/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ function simulate(sys::StochSystem, init::State;
solver=EM(),
callback=nothing,
progress=true,
iip=is_iip(sys.f),
kwargs...)

prob = SDEProblem(sys.f, σg(sys), init, (0, tmax), p(sys), noise=stochprocess(sys))
prob = SDEProblem{iip}(sys.f, σg(sys), init, (0, tmax), p(sys), noise=stochprocess(sys))
solve(prob, solver; dt=dt, callback=callback, progress=progress, kwargs...)
end;

Expand All @@ -43,7 +44,7 @@ This function integrates `sys.f` forward in time, using the [`ODEProblem`](https
* `callback=nothing`: callback condition
* `kwargs...`: keyword arguments for [`solve(ODEProblem)`](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options)
For more info, see [`ODEProblem`](https://diffeq.sciml.ai/stable/types/ode_types/#SciMLBase.ODEProblem).
For more info, see [`ODEProblem`](https://diffeq.sciml.ai/stable/types/ode_types/#SciMLBase.ODEProblem).
For stochastic integration, see [`simulate`](@ref).
> Warning: This function has only been tested for the `Euler()` solver.
Expand All @@ -53,8 +54,9 @@ function relax(sys::StochSystem, init::State;
tmax=1e3,
solver=Euler(),
callback=nothing,
iip=is_iip(sys.f),
kwargs...)
prob = ODEProblem(sys.f, init, (0, tmax), p(sys))

prob = ODEProblem{iip}(sys.f, init, (0, tmax), p(sys))
solve(prob, solver; dt=dt, callback=callback, kwargs...)
end;
end;

0 comments on commit 7ca6c73

Please sign in to comment.