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

symbolic save idxs, new observed #392

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export step!, deleteat!, addat!, get_tmp_cache,
set_reltol!, get_du, get_du!, get_dt, get_proposed_dt, set_proposed_dt!,
u_modified!, savevalues!, reinit!, auto_dt_reset!, set_t!,
set_u!, check_error, change_t_via_interpolation!, addsteps!,
isdiscrete, reeval_internals_due_to_modification!
isdiscrete, reeval_internals_due_to_modification!, is_dense_output

export ContinuousCallback, DiscreteCallback, CallbackSet, VectorContinuousCallback

Expand Down
8 changes: 7 additions & 1 deletion src/problems/ode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ struct ODEProblem{uType, tType, isinplace, P, F, K, PT} <:
kwargs::K
"""An internal argument for storing traits about the solving process."""
problem_type::PT
"""Whether the output has all saved states."""
dense_output::Bool
@add_kwonly function ODEProblem{iip}(f::AbstractODEFunction{iip},
u0, tspan, p = NullParameters(),
problem_type = StandardODEProblem();
dense_output = true,
kwargs...) where {iip}
_tspan = promote_tspan(tspan)
new{typeof(u0), typeof(_tspan),
isinplace(f), typeof(p), typeof(f),
typeof(kwargs),
typeof(problem_type)}(f, u0, _tspan, p, kwargs, problem_type)
typeof(problem_type)}(f, u0, _tspan, p, kwargs, problem_type, dense_output)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise it breaks observed for odae and others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it break that?

Copy link
Member Author

@xtalax xtalax Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ODAE sorry, but things like sol[x[1]^2+x[2]+norm(x)]. Since you don't know which states you won't have later at solve time it was impossible to get both to work so I needed a flag. I would need some kind of signal from problem construction time to post solve, to signal what to call the observed functions with

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What signal do you need other than save_idxs?

Copy link
Member Author

@xtalax xtalax Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have save_idxs at problem construction time, only at solve time, look at the ODE PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but maybe we should.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisRackauckas thoughts on the above?

end

"""
Expand Down Expand Up @@ -484,3 +487,6 @@ function IncrementingODEProblem{iip}(f::IncrementingODEFunction, u0, tspan,
p = NullParameters(); kwargs...) where {iip}
ODEProblem(f, u0, tspan, p, IncrementingODEProblem{iip}(); kwargs...)
end

is_dense_output(prob::ODEProblem) = prob.dense_output
is_dense_output(prob) = true
6 changes: 4 additions & 2 deletions src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ function remake(prob::ODEProblem; f = missing,
end

if kwargs === missing
ODEProblem{isinplace(prob)}(_f, u0, tspan, p, prob.problem_type; prob.kwargs...,
ODEProblem{isinplace(prob)}(_f, u0, tspan, p, prob.problem_type;
dense_output = prob.dense_output, prob.kwargs...,
_kwargs...)
else
ODEProblem{isinplace(prob)}(_f, u0, tspan, p, prob.problem_type; kwargs...)
ODEProblem{isinplace(prob)}(_f, u0, tspan, p, prob.problem_type;
dense_output = prob.dense_output, kwargs...)
end
end

Expand Down
150 changes: 77 additions & 73 deletions src/solutions/dae_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/
exited due to an error. For more details, see
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
"""
struct DAESolution{T, N, uType, duType, uType2, DType, tType, P, A, ID, DE} <:
struct DAESolution{T, N, uType, duType, uType2, DType, tType, P, A, ID, DE, MType} <:
AbstractDAESolution{T, N, uType}
u::uType
du::duType
Expand All @@ -39,6 +39,7 @@ struct DAESolution{T, N, uType, duType, uType2, DType, tType, P, A, ID, DE} <:
interp::ID
dense::Bool
tslocation::Int
sym_map::MType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done using prob.f.sys? Requiring explicit maps isn't great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because save_idxs isn't known at sys construction stage, only at solve

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking out the OrdinaryDiffEq part of this makes this all make a lot more sense to me.

destats::DE
retcode::ReturnCode.T
end
Expand Down Expand Up @@ -74,6 +75,7 @@ function build_solution(prob::AbstractDAEProblem, alg, t, u, du = nothing;
HermiteInterpolation(t, u, du),
retcode = ReturnCode.Default,
destats = nothing,
sym_map = nothing,
kwargs...)
T = eltype(eltype(u))

Expand All @@ -88,34 +90,28 @@ function build_solution(prob::AbstractDAEProblem, alg, t, u, du = nothing;
errors = Dict{Symbol, real(eltype(prob.u0))}()

sol = DAESolution{T, N, typeof(u), typeof(du), typeof(u_analytic), typeof(errors),
typeof(t),
typeof(prob), typeof(alg), typeof(interp), typeof(destats)}(u, du,
u_analytic,
errors,
t,
prob,
alg,
interp,
dense,
0,
destats,
retcode)
typeof(t), typeof(prob), typeof(alg), typeof(interp),
typeof(destats), typeof(sym_map)}(u, du, u_analytic, errors, t,
prob, alg, interp, dense, 0,
sym_map, destats, retcode)

if calculate_error
calculate_solution_errors!(sol; timeseries_errors = timeseries_errors,
dense_errors = dense_errors)
end
sol
else
DAESolution{T, N, typeof(u), typeof(du), Nothing, Nothing, typeof(t),
typeof(prob), typeof(alg), typeof(interp), typeof(destats)}(u, du,
nothing,
nothing, t,
prob, alg,
interp,
dense, 0,
destats,
retcode)
DAESolution{T, N, typeof(u), typeof(du), Nothing, Nothing, typeof(t), typeof(prob),
typeof(alg), typeof(interp), typeof(destats), typeof(sym_map)}(u, du,
nothing,
nothing,
t, prob,
alg,
interp,
dense, 0,
sym_map,
destats,
retcode)
end
end

Expand Down Expand Up @@ -160,70 +156,78 @@ end
function build_solution(sol::AbstractDAESolution{T, N}, u_analytic, errors) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(u_analytic), typeof(errors),
typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats)}(sol.u,
sol.du,
u_analytic,
errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
sol.tslocation,
sol.destats,
sol.retcode)
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats),
typeof(sol.sym_map)}(sol.u,
sol.du,
u_analytic,
errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
sol.tslocation,
sol.sym_map,
sol.destats,
sol.retcode)
end

function solution_new_retcode(sol::AbstractDAESolution{T, N}, retcode) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
sol.tslocation,
sol.destats,
retcode)
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats),
typeof(sol.sym_map)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
sol.tslocation,
sol.sym_map,
sol.destats,
retcode)
end

function solution_new_tslocation(sol::AbstractDAESolution{T, N}, tslocation) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
tslocation,
sol.destats,
sol.retcode)
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats),
typeof(sol.sym_map)}(sol.u,
sol.du,
sol.u_analytic,
sol.errors,
sol.t,
sol.prob,
sol.alg,
sol.interp,
sol.dense,
tslocation,
sol.sym_map,
sol.destats,
sol.retcode)
end

function solution_slice(sol::AbstractDAESolution{T, N}, I) where {T, N}
DAESolution{T, N, typeof(sol.u), typeof(sol.du), typeof(sol.u_analytic),
typeof(sol.errors), typeof(sol.t),
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats)}(sol.u[I],
sol.du[I],
sol.u_analytic ===
nothing ?
nothing :
sol.u_analytic[I],
sol.errors,
sol.t[I],
sol.prob,
sol.alg,
sol.interp,
false,
sol.tslocation,
sol.destats,
sol.retcode)
typeof(sol.prob), typeof(sol.alg), typeof(sol.interp), typeof(sol.destats),
typeof(sol.sym_map)}(sol.u[I],
sol.du[I],
sol.u_analytic ===
nothing ?
nothing :
sol.u_analytic[I],
sol.errors,
sol.t[I],
sol.prob,
sol.alg,
sol.interp,
false,
sol.tslocation,
sol.sym_map,
sol.destats,
sol.retcode)
end
Loading