Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix setindex! not erroring appropriately for integrators #657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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 @@
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])
Loading