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

refactor: change remake_initialization_data #873

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
30 changes: 23 additions & 7 deletions src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function remake(prob::ODEProblem; f = missing,

if f === missing
if build_initializeprob
initialization_data = remake_initialization_data(
prob.f.sys, prob.f, u0, tspan[1], p)
initialization_data = remake_initialization_data_compat_wrapper(
prob.f.sys, prob.f, u0, tspan[1], p, newu0, newp)
else
initialization_data = nothing
end
Expand Down Expand Up @@ -203,16 +203,32 @@ function remake_initializeprob(sys, scimlfn, u0, t0, p)
end

"""
remake_initialization_data(sys, scimlfn, u0, t0, p)
$(TYPEDSIGNATURES)

Wrapper around `remake_initialization_data` for backward compatibility when `newu0` and
`newp` were not arguments.
"""
function remake_initialization_data_compat_wrapper(sys, scimlfn, u0, t0, p, newu0, newp)
if hasmethod(remake_initialization_data,
Tuple{typeof(sys), typeof(scimlfn), typeof(u0), typeof(t0), typeof(p)})
remake_initialization_data(sys, scimlfn, u0, t0, p)
else
remake_initialization_data(sys, scimlfn, u0, t0, p, newu0, newp)
end
end

"""
remake_initialization_data(sys, scimlfn, u0, t0, p, newu0, newp)

Re-create the initialization data present in the function `scimlfn`, using the
associated system `sys` and the user provided new values of `u0`, initial time `t0` and
`p`. By default, this calls `remake_initializeprob` for backward compatibility and
attempts to construct an `OverrideInitData` from the result.
associated system `sys`, the user provided new values of `u0`, initial time `t0`,
user-provided `p`, new u0 vector `newu0` and new parameter object `newp`. By default,
this calls `remake_initializeprob` for backward compatibility and attempts to construct
an `OverrideInitData` from the result.

Note that `u0` or `p` may be `missing` if the user does not provide a value for them.
"""
function remake_initialization_data(sys, scimlfn, u0, t0, p)
function remake_initialization_data(sys, scimlfn, u0, t0, p, newu0, newp)
return reconstruct_initialization_data(
nothing, remake_initializeprob(sys, scimlfn, u0, t0, p)...)
end
Expand Down
2 changes: 1 addition & 1 deletion test/downstream/adjoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ gs_ts, = Zygote.gradient(sol) do sol
sum(sum.(sol[[lorenz1.x, lorenz2.x], :]))
end

@test_broken all(map(x -> x == true_grad_vecsym, gs_ts))
@test all(map(x -> x == true_grad_vecsym, gs_ts))

# BatchedInterface AD
@variables x(t)=1.0 y(t)=1.0 z(t)=1.0 w(t)=1.0
Expand Down
Loading