Skip to content

Commit

Permalink
fix: fix setindex! not erroring appropriately for integrators
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Mar 26, 2024
1 parent 7888fa4 commit 0f2c5aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/integrator_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ function Base.setindex!(A::DEIntegrator, val, sym)
error("Invalid indexing of integrator: Integrator does not support indexing without a system")
if symbolic_type(sym) == ScalarSymbolic()
if is_variable(A, sym)
A.u[variable_index(A, sym)] = val
u_modified!(A, true)
set_state!(A, val, variable_index(A, sym))

Check warning on line 531 in src/integrator_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/integrator_interface.jl#L531

Added line #L531 was not covered by tests
elseif is_parameter(A, sym)
error("Parameter indexing is deprecated. Use `setp(sys, $sym)(integrator, $val)` to set parameter value.")
else
Expand Down
16 changes: 16 additions & 0 deletions test/downstream/integrator_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,19 @@ setp(sys, p)(integrator, [4, 5, 6])
@test getp(sys, p)(integrator) == integrator.ps[p] == [4, 5, 6]
integrator.ps[p] = [7, 8, 9]
@test getp(sys, p)(integrator) == integrator.ps[p] == [7, 8, 9]

# Issue#653
@parameters p
@variables X(t)

eq = D(X) ~ p - X
@mtkbuild osys = ODESystem([eq], t)
oprob = ODEProblem(osys, [X => 0.1], (0.0, 1.0), [p => 1.0])

oint = init(oprob, Tsit5())
@test_throws ErrorException oint[X]=1.0
@test_throws ErrorException setu(oint, X)(oint, 10.0)

oint = init(oprob, Tsit5(); save_everystep = false)
@test_nowarn oint[X] = 1.0
@test_nowarn setu(oint, X)(oint, 10.0)

0 comments on commit 0f2c5aa

Please sign in to comment.