Skip to content

Commit 17b640e

Browse files
Merge pull request #1034 from SciML/format
Format
2 parents 61d4754 + 39f2438 commit 17b640e

33 files changed

+630
-553
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ makedocs(sitename = "SciMLBase.jl",
1313
format = Documenter.HTML(assets = ["assets/favicon.ico"],
1414
canonical = "https://docs.sciml.ai/SciMLBase/stable"),
1515
linkcheck_ignore = [
16-
"https://www.sciencedirect.com/science/article/abs/pii/S0045782523007156"
16+
"https://www.sciencedirect.com/science/article/abs/pii/S0045782523007156"
1717
],
1818
pages = pages)
1919

docs/src/interfaces/Ensembles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ compute covariance matrices similarly:
476476

477477
```@example ensemble4
478478
timeseries_steps_meancov(sim) # Use the time steps, assume fixed dt
479-
timeseries_point_meancov(sim, 0:(1 // 2^(3)):1, 0:(1 // 2^(3)):1) # Use time points, interpolate
479+
timeseries_point_meancov(sim, 0:(1 // 2 ^ (3)):1, 0:(1 // 2 ^ (3)):1) # Use time points, interpolate
480480
```
481481

482482
For general analysis, we can build a `EnsembleSummary` type.

ext/SciMLBaseChainRulesCoreExt.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function ChainRulesCore.rrule(
1616
j::Integer)
1717
function ODESolution_getindex_pullback(Δ)
1818
i = symbolic_type(sym) != NotSymbolic() ? variable_index(VA, sym) : sym
19-
du, dprob = if i === nothing
19+
du,
20+
dprob = if i === nothing
2021
getter = getobserved(VA)
2122
grz = rrule_via_ad(config, getter, sym, VA.u[j], VA.prob.p, VA.t[j])[2](Δ)
2223
du = [k == j ? grz[3] : zero(VA.u[1]) for k in 1:length(VA.u)]
@@ -64,8 +65,9 @@ function ChainRulesCore.rrule(::Type{ODEProblem}, args...; kwargs...)
6465
ODEProblem(args...; kwargs...), ODEProblemAdjoint
6566
end
6667

67-
function ChainRulesCore.rrule(::Type{
68-
<:ODEProblem{iip, T}}, args...; kwargs...) where {iip, T}
68+
function ChainRulesCore.rrule(
69+
::Type{
70+
<:ODEProblem{iip, T}}, args...; kwargs...) where {iip, T}
6971
function ODEProblemAdjoint(ȳ)
7072
(NoTangent(), ȳ.f, ȳ.u0, ȳ.tspan, ȳ.p, ȳ.kwargs, ȳ.problem_type)
7173
end
@@ -92,7 +94,8 @@ function ChainRulesCore.rrule(
9294
(NoTangent(), ȳ, ntuple(_ -> NoTangent(), length(args))...)
9395
end
9496

95-
ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16}(u, args...),
97+
ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16}(
98+
u, args...),
9699
ODESolutionAdjoint
97100
end
98101

@@ -108,7 +111,7 @@ function ChainRulesCore.rrule(
108111
end
109112

110113
RODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
111-
T11, T12, T13, T14}(u, args...),
114+
T11, T12, T13, T14}(u, args...),
112115
RODESolutionAdjoint
113116
end
114117

@@ -125,12 +128,13 @@ function ChainRulesCore.rrule(::SciMLBase.EnsembleSolution, sim, time, converged
125128
out, EnsembleSolution_adjoint
126129
end
127130

128-
function ChainRulesCore.rrule(::Type{SciMLBase.IntervalNonlinearProblem}, args...; kwargs...)
131+
function ChainRulesCore.rrule(
132+
::Type{SciMLBase.IntervalNonlinearProblem}, args...; kwargs...)
129133
function IntervalNonlinearProblemAdjoint(ȳ)
130134
(NoTangent(), ȳ.f, ȳ.tspan, ȳ.p, ȳ.kwargs, ȳ.problem_type)
131135
end
132136

133137
SciMLBase.IntervalNonlinearProblem(args...; kwargs...), IntervalNonlinearProblemAdjoint
134138
end
135139

136-
end
140+
end

ext/SciMLBaseMakieExt.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ function Makie.convert_arguments(PT::Type{<:Plot},
105105
@assert tscale isa Symbol "`tscale` if passed in to `Makie.plot` must be a Symbol, got a $(typeof(tscale))"
106106

107107
# Convert the solution to arrays - this is the hard part!
108-
plot_vecs, labels = SciMLBase.diffeq_to_arrays(sol, plot_analytic, denseplot,
108+
plot_vecs,
109+
labels = SciMLBase.diffeq_to_arrays(sol, plot_analytic, denseplot,
109110
plotdensity, tspan, vars, tscale, plotat)
110111

111112
# We must convert from plot Type to symbol here, for plotspec use

src/SciMLBase.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ abstract type AbstractNonlinearProblem{uType, isinplace} <: AbstractDEProblem en
110110
abstract type AbstractIntervalNonlinearProblem{uType, isinplace} <:
111111
AbstractNonlinearProblem{uType,
112112
isinplace} end
113-
const AbstractSteadyStateProblem{uType, isinplace} = AbstractNonlinearProblem{uType,
113+
const AbstractSteadyStateProblem{
114+
uType, isinplace} = AbstractNonlinearProblem{uType,
114115
isinplace}
115116

116117
"""
@@ -375,7 +376,6 @@ abstract type AbstractDiscretization <: AbstractSciMLAlgorithm end
375376
# Discretization metadata
376377
"""
377378
$(TYPEDEF)
378-
379379
"""
380380
abstract type AbstractDiscretizationMetadata{hasTime} end
381381

@@ -568,7 +568,10 @@ abstract type AbstractPDENoTimeSolution{T, N, S, D} <:
568568
"""
569569
$(TYPEDEF)
570570
"""
571-
const AbstractPDESolution{T, N, S, D} = Union{AbstractPDETimeSeriesSolution{T, N, S, D},
571+
const AbstractPDESolution{T,
572+
N,
573+
S,
574+
D} = Union{AbstractPDETimeSeriesSolution{T, N, S, D},
572575
AbstractPDENoTimeSolution{T, N, S, D}}
573576

574577
"""
@@ -630,8 +633,8 @@ abstract type ADOriginator end
630633
"""
631634
$(TYPEDEF)
632635
633-
Used to specify which variables can be aliased in a solve.
634-
Every concrete AbstractAliasSpecifier should have at least the fields `alias_p` and `alias_f`.
636+
Used to specify which variables can be aliased in a solve.
637+
Every concrete AbstractAliasSpecifier should have at least the fields `alias_p` and `alias_f`.
635638
"""
636639
abstract type AbstractAliasSpecifier end
637640

src/adapt.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
function adapt_structure(to, prob::Union{NonlinearProblem{<:Any, <:Any, iip}, ImmutableNonlinearProblem{<:Any, <:Any, iip}}) where {iip}
1+
function adapt_structure(to,
2+
prob::Union{NonlinearProblem{<:Any, <:Any, iip},
3+
ImmutableNonlinearProblem{<:Any, <:Any, iip}}) where {iip}
24
ImmutableNonlinearProblem{iip}(NonlinearFunction{iip}(adapt(to, prob.f.f)),
35
adapt(to, prob.u0),
46
adapt(to, prob.p);
57
adapt(to, prob.kwargs)...)
68
end
79

8-
function adapt_structure(to, prob::Union{ODEProblem{<:Any, <:Any, iip}, ImmutableODEProblem{<:Any, <:Any, iip}}) where {iip}
10+
function adapt_structure(to,
11+
prob::Union{ODEProblem{<:Any, <:Any, iip}, ImmutableODEProblem{<:Any, <:Any, iip}}) where {iip}
912
ImmutableODEProblem{iip, FullSpecialize}(adapt(to, prob.f),
1013
adapt(to, prob.u0),
1114
adapt(to, prob.tspan),

src/callbacks.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,15 @@ is constructed by passing the constructor `ContinuousCallback`, `DiscreteCallbac
378378
You can pass as many callbacks as you like. When the solvers encounter multiple
379379
callbacks, the following rules apply:
380380
381-
* `ContinuousCallback`s and `VectorContinuousCallback`s are applied before `DiscreteCallback`s. (This is because
382-
they often implement event-finding that will backtrack the timestep to smaller
383-
than `dt`).
384-
* For `ContinuousCallback`s and `VectorContinuousCallback`s, the event times are found by rootfinding and only
385-
the first `ContinuousCallback` or `VectorContinuousCallback` affect is applied.
386-
* The `DiscreteCallback`s are then applied in order. Note that the ordering only
387-
matters for the conditions: if a previous callback modifies `u` in such a way
388-
that the next callback no longer evaluates condition to `true`, its `affect`
389-
will not be applied.
390-
381+
- `ContinuousCallback`s and `VectorContinuousCallback`s are applied before `DiscreteCallback`s. (This is because
382+
they often implement event-finding that will backtrack the timestep to smaller
383+
than `dt`).
384+
- For `ContinuousCallback`s and `VectorContinuousCallback`s, the event times are found by rootfinding and only
385+
the first `ContinuousCallback` or `VectorContinuousCallback` affect is applied.
386+
- The `DiscreteCallback`s are then applied in order. Note that the ordering only
387+
matters for the conditions: if a previous callback modifies `u` in such a way
388+
that the next callback no longer evaluates condition to `true`, its `affect`
389+
will not be applied.
391390
"""
392391
struct CallbackSet{T1 <: Tuple, T2 <: Tuple} <: DECallback
393392
continuous_callbacks::T1

src/ensemble/basic_ensemble_solve.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ tighten_container_eltype(u) = u
138138
function __solve(prob::EnsembleProblem{<:AbstractVector{<:AbstractSciMLProblem}},
139139
alg::Union{AbstractDEAlgorithm, Nothing},
140140
ensemblealg::BasicEnsembleAlgorithm; kwargs...)
141-
Base.depwarn("This dispatch is deprecated for the standard ensemble syntax. See the Parallel
142-
Ensembles Simulations Interface page for more details", :EnsembleProblemSolve)
141+
Base.depwarn(
142+
"This dispatch is deprecated for the standard ensemble syntax. See the Parallel
143+
Ensembles Simulations Interface page for more details",
144+
:EnsembleProblemSolve)
143145
invoke(__solve, Tuple{AbstractEnsembleProblem, typeof(alg), typeof(ensemblealg)},
144146
prob, alg, ensemblealg; trajectories = length(prob.prob), kwargs...)
145147
end

src/ensemble/ensemble_problems.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Defines a structure to manage an ensemble (batch) of problems.
102102
Each field controls how the ensemble behaves during simulation.
103103
104104
## Arguments
105+
105106
- `prob`: The original base problem to replicate or modify.
106107
- `prob_func`: A function that defines how to generate each subproblem.
107108
- `output_func`: A function to post-process each individual simulation result.
@@ -144,11 +145,14 @@ $(TYPEDEF)
144145
Constructor for deprecated usage where a vector of problems is passed directly.
145146
146147
!!! warning
148+
147149
This constructor is deprecated. Use the standard ensemble syntax with `prob_func` instead.
148150
"""
149151
function EnsembleProblem(prob::AbstractVector{<:AbstractSciMLProblem}; kwargs...)
150-
Base.depwarn("This dispatch is deprecated for the standard ensemble syntax. See the Parallel \
151-
Ensembles Simulations Interface page for more details", :EnsembleProblem)
152+
Base.depwarn(
153+
"This dispatch is deprecated for the standard ensemble syntax. See the Parallel \
154+
Ensembles Simulations Interface page for more details",
155+
:EnsembleProblem)
152156
invoke(EnsembleProblem,
153157
Tuple{Any},
154158
prob;
@@ -163,12 +167,12 @@ Main constructor for `EnsembleProblem`.
163167
164168
## Keyword Arguments
165169
166-
- `prob`: The base problem.
167-
- `prob_func`: Function to modify the base problem per trajectory.
168-
- `output_func`: Function to extract output from a solution.
169-
- `reduction`: Function to aggregate results.
170-
- `u_init`: Initial value for aggregation.
171-
- `safetycopy`: Whether to deepcopy the problem before modifying.
170+
- `prob`: The base problem.
171+
- `prob_func`: Function to modify the base problem per trajectory.
172+
- `output_func`: Function to extract output from a solution.
173+
- `reduction`: Function to aggregate results.
174+
- `u_init`: Initial value for aggregation.
175+
- `safetycopy`: Whether to deepcopy the problem before modifying.
172176
"""
173177
function EnsembleProblem(prob;
174178
prob_func = DEFAULT_PROB_FUNC,
@@ -203,12 +207,15 @@ $(TYPEDEF)
203207
Constructor that is used for NOnlinearProblem.
204208
205209
!!! warning
210+
206211
This dispatch is deprecated. See the Parallel Ensembles Simulations Interface page.
207212
"""
208213
function SciMLBase.EnsembleProblem(
209214
prob::AbstractSciMLProblem, u0s::Vector{Vector{T}}; kwargs...) where {T}
210-
Base.depwarn("This dispatch is deprecated for the standard ensemble syntax. See the Parallel \
211-
Ensembles Simulations Interface page for more details", :EnsembleProblem)
215+
Base.depwarn(
216+
"This dispatch is deprecated for the standard ensemble syntax. See the Parallel \
217+
Ensembles Simulations Interface page for more details",
218+
:EnsembleProblem)
212219
prob_func = (prob, i, repeat = nothing) -> remake(prob, u0 = u0s[i])
213220
return SciMLBase.EnsembleProblem(prob; prob_func, kwargs...)
214221
end
@@ -220,8 +227,8 @@ Defines a weighted version of an `EnsembleProblem`, where different simulations
220227
221228
## Arguments
222229
223-
- `ensembleprob`: The base ensemble problem.
224-
- `weights`: A vector of weights corresponding to each simulation.
230+
- `ensembleprob`: The base ensemble problem.
231+
- `weights`: A vector of weights corresponding to each simulation.
225232
"""
226233
struct WeightedEnsembleProblem{T1 <: AbstractEnsembleProblem, T2 <: AbstractVector} <:
227234
AbstractEnsembleProblem
@@ -251,7 +258,6 @@ end
251258
$(TYPEDEF)
252259
253260
Constructor for `WeightedEnsembleProblem`. Ensures weights sum to 1 and matches problem count.
254-
255261
"""
256262
function WeightedEnsembleProblem(args...; weights, kwargs...)
257263
# TODO: allow skipping checks?
@@ -260,4 +266,3 @@ function WeightedEnsembleProblem(args...; weights, kwargs...)
260266
@assert length(ep.prob) == length(weights)
261267
WeightedEnsembleProblem(ep, weights)
262268
end
263-

src/initialization.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ struct OverrideInitData{
4444
function OverrideInitData(initprob::I, update_initprob!::J, initprobmap::K,
4545
initprobpmap::L, metadata::M, is_update_oop::O) where {I, J, K, L, M, O}
4646
@assert initprob isa
47-
Union{SCCNonlinearProblem, ImmutableNonlinearProblem, NonlinearProblem, NonlinearLeastSquaresProblem}
47+
Union{SCCNonlinearProblem, ImmutableNonlinearProblem,
48+
NonlinearProblem, NonlinearLeastSquaresProblem}
4849
return new{I, J, K, L, M, O}(
4950
initprob, update_initprob!, initprobmap, initprobpmap, metadata, is_update_oop)
5051
end
@@ -172,9 +173,10 @@ the `u0` and `p` as-is, and is always successful if it returns. Valid only for
172173
`AbstractDEProblem` and `AbstractDAEProblem`. Requires a `DEIntegrator` as its second argument.
173174
174175
Keyword arguments:
175-
- `abstol`: The absolute value below which the norm of the residual of algebraic equations
176-
should lie. The norm function used is `integrator.opts.internalnorm` if present, and
177-
`LinearAlgebra.norm` if not.
176+
177+
- `abstol`: The absolute value below which the norm of the residual of algebraic equations
178+
should lie. The norm function used is `integrator.opts.internalnorm` if present, and
179+
`LinearAlgebra.norm` if not.
178180
"""
179181
function get_initial_values(
180182
prob::AbstractDEProblem, integrator::DEIntegrator, f, alg::CheckInit,
@@ -227,12 +229,13 @@ If the field is absent or the value is `nothing`, return `u0` and `p` successful
227229
The success value returned depends on the success of the nonlinear solve.
228230
229231
Keyword arguments:
230-
- `nlsolve_alg`: The NonlinearSolve.jl algorithm to use. If not provided, this function will
231-
throw an error.
232-
- `abstol`, `reltol`: The `abstol` (`reltol`) to use for the nonlinear solve. The value
233-
provided to the `OverrideInit` constructor takes priority over this keyword argument.
234-
If the former is `nothing`, this keyword argument will be used. If it is also not provided,
235-
an error will be thrown.
232+
233+
- `nlsolve_alg`: The NonlinearSolve.jl algorithm to use. If not provided, this function will
234+
throw an error.
235+
- `abstol`, `reltol`: The `abstol` (`reltol`) to use for the nonlinear solve. The value
236+
provided to the `OverrideInit` constructor takes priority over this keyword argument.
237+
If the former is `nothing`, this keyword argument will be used. If it is also not provided,
238+
an error will be thrown.
236239
237240
All additional keyword arguments are forwarded to `solve`.
238241

src/remake.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,8 @@ end
843843
remake($subprob_name; u0 = _u0)
844844
end
845845
offset += N
846-
end, subprob_name
846+
end,
847+
subprob_name
847848
end
848849
expr = quote
849850
offset = 0
@@ -895,7 +896,8 @@ function remake(prob::SCCNonlinearProblem; u0 = missing, p = missing, probs = mi
895896
f = coalesce(f, prob.f)
896897
f = remake(f; sys)
897898

898-
return SCCNonlinearProblem{typeof(probs), typeof(explicitfuns!), typeof(f), typeof(newp)}(
899+
return SCCNonlinearProblem{
900+
typeof(probs), typeof(explicitfuns!), typeof(f), typeof(newp)}(
899901
probs, explicitfuns!, f, newp, parameters_alias)
900902
end
901903

@@ -1164,7 +1166,8 @@ function updated_u0_p(
11641166
return (u0 === missing ? state_values(prob) : u0),
11651167
(p === missing ? parameter_values(prob) : p)
11661168
end
1167-
newu0, newp = _updated_u0_p_internal(
1169+
newu0,
1170+
newp = _updated_u0_p_internal(
11681171
prob, u0, p, t0; interpret_symbolicmap, use_defaults)
11691172
return late_binding_update_u0_p(prob, u0, p, t0, newu0, newp)
11701173
end
@@ -1208,7 +1211,8 @@ function maybe_eager_initialize_problem(prob::AbstractSciMLProblem, initializati
12081211
end
12091212
if initialization_data !== nothing && !lazy_initialization &&
12101213
(!is_time_dependent(prob) || current_time(prob) !== nothing)
1211-
u0, p, _ = get_initial_values(
1214+
u0, p,
1215+
_ = get_initial_values(
12121216
prob, prob, prob.f, OverrideInit(), Val(isinplace(prob)))
12131217
if u0 !== nothing && eltype(u0) == Any && isempty(u0)
12141218
u0 = nothing

src/retcodes.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,23 +402,22 @@ EnumX.@enumx ReturnCode begin
402402
Stalled
403403

404404
"""
405-
ReturnCode.StalledSuccess
405+
ReturnCode.StalledSuccess
406406
407407
The solution process has stalled, but the stall is not considered a failure of the solver.
408408
For example, a nonlinear optimizer may have stalled, that is its steps went to zero, which
409-
is a valid local minima.
409+
is a valid local minima.
410410
411411
## Common Reasons for Seeing this Return Code
412412
413-
- For nonlinear least squares optimizations, this is given for local minima which exceed
414-
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered
413+
- For nonlinear least squares optimizations, this is given for local minima which exceed
414+
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered
415415
ReturnCode.Success but it is still considered a successful return of the solver since
416416
it's a valid local minima (and there no minima which achieves the tolerance).
417417
418418
## Properties
419419
420420
- `successful_retcode` = `true`
421-
422421
"""
423422
StalledSuccess
424423

0 commit comments

Comments
 (0)