SciML / SciMLBase.jl

The Base interface of the SciML ecosystem
https://docs.sciml.ai/SciMLBase/stable
MIT License
118 stars 91 forks source link

Problems with integrators for `JumpProblem`s #654

Closed TorkelE closed 2 months ago

TorkelE commented 3 months ago

Problem 1: no setu for JumpProblem integrators?

using ModelingToolkit, JumpProcesses
using ModelingToolkit: t_nounits as t

@parameters k
@variables X(t)
rate = k
affect = [X ~ X - 1]

crj = ConstantRateJump(1.0 ,[X ~ X - 1])
@named js = JumpSystem([crj], t, [X], [k])
js = complete(js)

u0 = [X => 10]
tspan = (0.0, 1.0)
ps = [k => 1.0]
dp = DiscreteProblem(js, u0, tspan, ps)
jp = JumpProblem(js, dp, Direct())

int = init(jprob, SSAStepper())
setu(int, X)(int, 50)

gives a

ERROR: set_u!: method has not been implemented for the integrator
Stacktrace:

error(s::String) at [error.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

set_u!(integrator::JumpProcesses.SSAIntegrator{…}, u::Vector{…}) at [integrator_interface.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

set_state!(A::JumpProcesses.SSAIntegrator{…}, val::Int64, idx::Int64) at [integrator_interface.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

(::SymbolicIndexingInterface.var"#setter!#132"{…})(prob::JumpProcesses.SSAIntegrator{…}, val::Int64) at [state_indexing.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

top-level scope at [playground.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Some type information was truncated. Use show(err) to see complete types.

ERROR: set_u!: method has not been implemented for the integrator
Stacktrace:

error(s::String) at [error.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

set_u!(integrator::JumpProcesses.SSAIntegrator{…}, u::Vector{…}) at [integrator_interface.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

set_state!(A::JumpProcesses.SSAIntegrator{…}, val::Int64, idx::Int64) at [integrator_interface.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

(::SymbolicIndexingInterface.var"#setter!#132"{…})(prob::JumpProcesses.SSAIntegrator{…}, val::Int64) at [state_indexing.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

top-level scope at [playground.jl](vscode-file://vscode-app/snap/code/155/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Some type information was truncated. Use show(err) to see complete types.

Problem 2: No save_everystep=false option when initiating JumpProblem integrators

Not sure if this should be possible, since JumpSystems are a bit different from other systems, but:

using ModelingToolkit, JumpProcesses
using ModelingToolkit: t_nounits as t

@parameters k
@variables X(t)
rate = k
affect = [X ~ X - 1]

crj = ConstantRateJump(1.0 ,[X ~ X - 1])
@named js = JumpSystem([crj], t, [X], [k])
js = complete(js)

u0 = [X => 10]
tspan = (0.0, 1.0)
ps = [k => 1.0]
dp = DiscreteProblem(js, u0, tspan, ps)
jp = JumpProblem(js, dp, Direct())

int = init(jprob, SSAStepper(); save_everystep=false)

gives a

ERROR: MethodError: no method matching __init(::JumpProblem{…}, ::SSAStepper; callback::Nothing, save_everystep::Bool)

Closest candidates are:
  __init(::JumpProblem, ::SSAStepper; save_start, save_end, seed, alias_jump, saveat, callback, tstops, numsteps_hint) got unsupported keyword argument "save_everystep"
   @ JumpProcesses ~/.julia/packages/JumpProcesses/HPjOl/src/SSA_stepper.jl:147
  __init(::SciMLBase.AbstractJumpProblem{P}, ::SciMLBase.AbstractDEAlgorithm; ...) where P
   @ JumpProcesses ~/.julia/packages/JumpProcesses/HPjOl/src/solve.jl:10
  __init(::SciMLBase.AbstractJumpProblem{P}, ::SciMLBase.AbstractDEAlgorithm, ::Any; ...) where P
   @ JumpProcesses ~/.julia/packages/JumpProcesses/HPjOl/src/solve.jl:10
  ...

Stacktrace:
 [1] kwerr(::@NamedTuple{…}, ::Function, ::JumpProblem{…}, ::SSAStepper)
   @ Base ./error.jl:165
 [2] init_call(_prob::JumpProblem{…}, args::SSAStepper; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…})
   @ DiffEqBase ~/.julia/packages/DiffEqBase/8vI1R/src/solve.jl:530
 [3] init(prob::JumpProblem{…}, args::SSAStepper; kwargs::@Kwargs{…})
   @ DiffEqBase ~/.julia/packages/DiffEqBase/8vI1R/src/solve.jl:548
 [4] top-level scope
   @ ~/Desktop/Julia Playground/Environment - Catalyst test/playground.jl:24
Some type information was truncated. Use `show(err)` to see complete types.
AayushSabharwal commented 2 months ago

This is now fixed