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 Apr 1, 2024
1 parent 7888fa4 commit a07a002
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/integrator_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ SymbolicIndexingInterface.parameter_values(A::DEIntegrator) = A.p
SymbolicIndexingInterface.state_values(A::DEIntegrator) = A.u
SymbolicIndexingInterface.current_time(A::DEIntegrator) = A.t
function SymbolicIndexingInterface.set_state!(A::DEIntegrator, val, idx)
# So any error checking happens to ensure we actually _can_ set state
set_u!(A, A.u)
A.u[idx] = val
u_modified!(A, true)
end
Expand Down Expand Up @@ -528,8 +526,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 529 in src/integrator_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/integrator_interface.jl#L529

Added line #L529 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
8 changes: 8 additions & 0 deletions test/downstream/integrator_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,11 @@ 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])

0 comments on commit a07a002

Please sign in to comment.