Skip to content

How to remake with a Vector{Pair}? #472

Closed

Description

@sdwfrost

The following code throws an error - I can remake an ODEProblem with a vector of Float64, but not with a vector of Pair{Operation,Float64}.

using ModelingToolkit
using OrdinaryDiffEq
using SimpleDiffEq
using DifferentialEquations

begin
	beta = 0.5
	gamma = 0.25
end

begin
	@parameters t β c γ
	@variables S(t) I(t) R(t)
	@derivatives D'~t
	N=S+I+R
	eqs = [D(S) ~ -β*c*I/N*S,
       	   D(I) ~ β*c*I/N*S-γ*I,
           D(R) ~ γ*I]
end

sys = ODESystem(eqs)

begin
	δt = 0.1
	tmax = 40.0
	u0 = [S => 990.0, I => 10.0, R => 0.0]
	alg = Tsit5()
end;

init_prob = ODEProblem(sys,u0,(0.0,tmax),[β=>0.05, c=>10.0, γ=>0.2])
prob = remake(init_prob,p=[β=>beta, c=>10.0, γ=>gamma])
sol = solve(prob,alg,saveat=δt)
```

```
ERROR: TypeError: non-boolean (Operation) used in boolean context
Stacktrace:
 [1] ==(::Array{Pair{Operation,Float64},1}, ::Array{Pair{Operation,Float64},1}) at ./abstractarray.jl:1778
 [2] get_concrete_problem(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Pair{Operation,Float64},1},ODEFunction{true,ModelingToolkit.var"#f#84"{ggfunc,ggfunc},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Array{Symbol,1},Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}; kwargs::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:u0, :p, :saveat),Tuple{Array{Float64,1},Array{Pair{Operation,Float64},1},Float64}}}) at /home/simon/.julia/packages/DiffEqBase/TjqaN/src/solve.jl:138
```

Activity

  1. ChrisRackauckas commented on Jun 22, 2020

    @ChrisRackauckas
    Member

    Thanks. This issue might take a bit to solve. It's rather difficult because on the DiffEq end it doesn't know about systems and these maps. A lot of #340 is necessary to fix this.

  2. sdwfrost commented on Jun 22, 2020

    @sdwfrost
    Author

    As a workaround for now, is there a way to compile the system into a nonsymbolic form that can be remade?

  3. ChrisRackauckas commented on Jun 23, 2020

    @ChrisRackauckas
    Member

    ModelingToolkit.varmap_to_vars([β=>beta, c=>10.0, γ=>gamma],states(sys))

  4. sdwfrost commented on Jun 24, 2020

    @sdwfrost
    Author

    Thanks! This workaround worked (though there was an error in your suggestion - one needs parameters and not states); for reference, the end of the code is now:

    using ModelingToolkit: varmap_to_vars
    init_prob = ODEProblem(sys,u0,(0.0,tmax),[β=>0.05, c=>10.0, γ=>0.2])
    pnew = varmap_to_vars([β=>beta, c=>10.0, γ=>gamma],parameters(sys))
    prob = remake(init_prob,p=pnew)
    sol = solve(prob,alg,saveat=δt)
  5. added
    enhancement
    on Mar 11, 2021
  6. ChrisRackauckas commented on Mar 11, 2021

    @ChrisRackauckas
    Member

    Remove from FAQ when fixed.

  7. ChrisRackauckas commented on Feb 23, 2024

    @ChrisRackauckas
    Member

    remake was made to work with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions