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 observed for DEintegrator #595

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
6 changes: 0 additions & 6 deletions src/integrator_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ end

# SymbolicIndexingInterface
SymbolicIndexingInterface.symbolic_container(A::DEIntegrator) = A.f
function SymbolicIndexingInterface.is_observed(A::DEIntegrator, sym)
return !is_variable(A, sym) && !is_parameter(A, sym) && !is_independent_variable(A, sym) && symbolic_type(sym) == ScalarSymbolic()
end
function SymbolicIndexingInterface.observed(A::DEIntegrator, sym)
return getobserved(A)(sym)
end
SymbolicIndexingInterface.parameter_values(A::DEIntegrator) = A.p
SymbolicIndexingInterface.state_values(A::DEIntegrator) = A.u
SymbolicIndexingInterface.current_time(A::DEIntegrator) = A.t
Expand Down
9 changes: 2 additions & 7 deletions src/problems/problem_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
end

SymbolicIndexingInterface.symbolic_container(prob::AbstractSciMLProblem) = prob.f
function SymbolicIndexingInterface.is_observed(A::AbstractSciMLProblem, sym)
return !is_variable(A, sym) && !is_parameter(A, sym) && !is_independent_variable(A, sym) && symbolic_type(sym) == ScalarSymbolic()
end
function SymbolicIndexingInterface.observed(A::AbstractSciMLProblem, sym)
return getobserved(A)(sym)
end

SymbolicIndexingInterface.parameter_values(prob::AbstractSciMLProblem) = prob.p
SymbolicIndexingInterface.state_values(prob::AbstractSciMLProblem) = prob.u0
SymbolicIndexingInterface.current_time(prob::AbstractSciMLProblem) = prob.tspan[1]
Expand All @@ -33,7 +28,7 @@
elseif is_independent_variable(prob.f, sym)
return getindepsym(prob)
elseif is_observed(prob.f, sym)
obs = SymbolicIndexingInterface.observed(prob.f, sym)
obs = SymbolicIndexingInterface.observed(prob, sym)

Check warning on line 31 in src/problems/problem_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/problems/problem_interface.jl#L31

Added line #L31 was not covered by tests
if is_time_dependent(prob.f)
return obs(prob.u0, prob.p, 0.0)
else
Expand Down
7 changes: 0 additions & 7 deletions src/solutions/solution_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ SymbolicIndexingInterface.is_independent_variable(::AbstractNoTimeSolution, sym)

SymbolicIndexingInterface.independent_variable_symbols(::AbstractNoTimeSolution) = []

for soltype in [AbstractTimeseriesSolution, AbstractNoTimeSolution]
@eval function SymbolicIndexingInterface.observed(A::$(soltype), sym::Symbol)
has_sys(A.prob.f) || error("Cannot use observed without system")
return SymbolicIndexingInterface.observed(A, getproperty(A.prob.f.sys, sym))
end
end

SymbolicIndexingInterface.is_time_dependent(::AbstractTimeseriesSolution) = true

SymbolicIndexingInterface.is_time_dependent(::AbstractNoTimeSolution) = false
Expand Down
2 changes: 2 additions & 0 deletions test/downstream/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

Expand Down
29 changes: 20 additions & 9 deletions test/downstream/symbol_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,32 @@ p = [lorenz1.σ => 10.0,

tspan = (0.0, 100.0)
prob = ODEProblem(sys_simplified, u0, tspan, p)
integ = init(prob, Rodas4())
sol = solve(prob, Rodas4())

@test_throws Any sol[b]
@test_throws Any sol[b, 1]
@test_throws Any sol[b, 1:5]
@test_throws Any sol[b, [1, 2, 3]]
@test_throws Any sol['a']
@test_throws Any sol['a', 1]
@test_throws Any sol['a', 1:5]
@test_throws Any sol['a', [1, 2, 3]]
@testset "indexing should error" begin
for obj in [prob, integ, sol]
for sym in ['a', :b]
@test_throws Any obj[sym]
@test_throws Any obj[sym, 1]
@test_throws Any obj[sym, 1:5]
@test_throws Any obj[sym, [1, 2, 3]]
end
end
end

@testset "observed shouldn't error" begin
for obj in [prob, integ, sol]
obj[:a]
SymbolicIndexingInterface.observed(obj, :a)
end
end


@test sol[a] isa AbstractVector
@test sol[:a] == sol[a]
@test sol[a, 1] isa Real
@test sol[:a, 1] == sol[a, 1]
@test sol[:a, 1] == sol[a, 1] == prob[a] == prob[:a] == integ[a] == integ[:a] == -1.0
@test sol[a, 1:5] isa AbstractVector
@test sol[:a, 1:5] == sol[a, 1:5]
@test sol[a, [1, 2, 3]] isa AbstractVector
Expand Down
Loading