Skip to content

Commit

Permalink
note that if split-true you can't use integer access
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Feb 22, 2024
1 parent 562ce9f commit bc3d75c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/dynamicalsystem_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ See also the DynamicalSystems.jl tutorial online for an example.
!!! warn "ModelingToolkit.jl v9"
In ModelingToolkit.jl v9 the default `split` behavior of the parameter container
is `true`. This leads to various accessing errors, so the integration
only works if you explicitly pass `structural_simplify(sys; split = false)`
when structurally simplifying the equations systems before making the
`...Problem` instance.
is `true`. This means that the parameter container is no longer a `Vector{Float64}`
by default, which means that you cannot use integers to access parameters.
In this case, the `index` given to `current_parameter/set_parameter!`
must be the symbolic parameter binding.
Use `structural_simplify(sys; split = false)` to allow accessing parameters
with integers again.
## API
Expand Down
16 changes: 16 additions & 0 deletions test/mtk_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ set_parameter!(pmap, fol_1.τ, 4.0)
@test current_parameter(pmap, fol_1.τ) == 4.0
@test observe_state(pmap, fol_1.x) 0 atol = 1e-3 rtol = 0

# test with split
sys = structural_simplify(connected; split = true)

u0 = [fol_1.x => -0.5,
fol_2.x => 1.0]

p = [fol_1.τ => 2.0,
fol_2.τ => 4.0]

prob = ODEProblem(sys, u0, (0.0, 10.0), p)
ds = CoupledODEs(prob)

@test current_parameter(ds, fol_1.τ) == 2.0
set_parameter!(ds, fol_1.τ, 3.0)
@test current_parameter(ds, fol_1.τ) == 3.0

# test without sys
function lorenz!(du, u, p, t)
du[1] = p[1] * (u[2] - u[1])
Expand Down

0 comments on commit bc3d75c

Please sign in to comment.