Skip to content

Commit

Permalink
apply JuliaFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
prbzrg committed Nov 30, 2023
1 parent e283773 commit eab64f9
Show file tree
Hide file tree
Showing 44 changed files with 1,022 additions and 957 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Preferences = "1.3"
Printf = "1.9"
PyCall = "1.96"
PythonCall = "0.9"
QuasiMonteCarlo = "0.3"
RCall = "0.13.18"
RecipesBase = "0.7.0, 0.8, 1.0"
RecursiveArrayTools = "2.33"
Expand All @@ -83,7 +84,6 @@ Statistics = "1"
SymbolicIndexingInterface = "0.2"
Tables = "1"
TruncatedStacktraces = "1"
QuasiMonteCarlo = "0.3"
Zygote = "0.6"
julia = "1.9"

Expand Down
32 changes: 16 additions & 16 deletions ext/SciMLBaseChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import ChainRulesCore
import ChainRulesCore: NoTangent, @non_differentiable

function ChainRulesCore.rrule(config::ChainRulesCore.RuleConfig{
>:ChainRulesCore.HasReverseMode,
},
::typeof(getindex),
VA::ODESolution,
sym,
j::Integer)
>:ChainRulesCore.HasReverseMode,
},
::typeof(getindex),
VA::ODESolution,
sym,
j::Integer)
function ODESolution_getindex_pullback(Δ)
i = issymbollike(sym) ? sym_to_index(sym, VA) : sym
if i === nothing
Expand Down Expand Up @@ -94,11 +94,11 @@ function ChainRulesCore.rrule(::Type{SDEProblem}, args...; kwargs...)
end

function ChainRulesCore.rrule(::Type{
<:ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
T11, T12,
}}, u,
args...) where {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
T12}
<:ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
T11, T12,
}}, u,
args...) where {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
T12}
function ODESolutionAdjoint(ȳ)
(NoTangent(), ȳ, ntuple(_ -> NoTangent(), length(args))...)
end
Expand All @@ -108,10 +108,10 @@ function ChainRulesCore.rrule(::Type{
end

function ChainRulesCore.rrule(::Type{
<:ODESolution{uType, tType, isinplace, P, NP, F, G, K,
ND,
}}, u,
args...) where {uType, tType, isinplace, P, NP, F, G, K, ND}
<:ODESolution{uType, tType, isinplace, P, NP, F, G, K,
ND,
}}, u,
args...) where {uType, tType, isinplace, P, NP, F, G, K, ND}
function SDESolutionAdjoint(ȳ)
(NoTangent(), ȳ, ntuple(_ -> NoTangent(), length(args))...)
end
Expand All @@ -132,4 +132,4 @@ function ChainRulesCore.rrule(::SciMLBase.EnsembleSolution, sim, time, converged
out, EnsembleSolution_adjoint
end

end
end
5 changes: 4 additions & 1 deletion ext/SciMLBasePythonCallExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ function SciMLBase.numargs(f::Py)
pyconvert(Int, length(first(inspect.getfullargspec(f2))) - inspect.ismethod(f2))
end

_pyconvert(x::Py) = pyisinstance(x, pybuiltins.list) ? _promoting_collect(_pyconvert(x) for x in x) : pyconvert(Any, x)
function _pyconvert(x::Py)
pyisinstance(x, pybuiltins.list) ? _promoting_collect(_pyconvert(x) for x in x) :

Check warning on line 17 in ext/SciMLBasePythonCallExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/SciMLBasePythonCallExt.jl#L16-L17

Added lines #L16 - L17 were not covered by tests
pyconvert(Any, x)
end
_pyconvert(x::PyList) = _promoting_collect(_pyconvert(x) for x in x)
_pyconvert(x) = x

Expand Down
2 changes: 1 addition & 1 deletion ext/SciMLBaseRCallExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ function SciMLBase.isinplace(f::RFunction, args...; kwargs...)
false
end

end
end
54 changes: 27 additions & 27 deletions ext/SciMLBaseZygoteExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ using Zygote
using Zygote: @adjoint, pullback
import Zygote: literal_getproperty
using SciMLBase
using SciMLBase: ODESolution, issymbollike, sym_to_index, remake,
getobserved, build_solution, EnsembleSolution,
NonlinearSolution, AbstractTimeseriesSolution
using SciMLBase: ODESolution, issymbollike, sym_to_index, remake,
getobserved, build_solution, EnsembleSolution,
NonlinearSolution, AbstractTimeseriesSolution

# This method resolves the ambiguity with the pullback defined in
# RecursiveArrayToolsZygoteExt
Expand Down Expand Up @@ -85,7 +85,7 @@ end
end

@adjoint function Zygote.literal_getproperty(sim::EnsembleSolution,
::Val{:u})
::Val{:u})
sim.u, p̄ -> (EnsembleSolution(p̄, 0.0, true, sim.stats),)
end

Expand All @@ -107,17 +107,17 @@ end
}(u,
args...) where {T1, T2, T3, T4, T5, T6, T7, T8,
T9, T10, T11, T12}
function ODESolutionAdjoint(ȳ)
(ȳ, ntuple(_ -> nothing, length(args))...)
end
ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12}(u, args...),
ODESolutionAdjoint
function ODESolutionAdjoint(ȳ)
(ȳ, ntuple(_ -> nothing, length(args))...)

Check warning on line 111 in ext/SciMLBaseZygoteExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/SciMLBaseZygoteExt.jl#L110-L111

Added lines #L110 - L111 were not covered by tests
end

ODESolution{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12}(u, args...),

Check warning on line 114 in ext/SciMLBaseZygoteExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/SciMLBaseZygoteExt.jl#L114

Added line #L114 was not covered by tests
ODESolutionAdjoint
end

@adjoint function SDEProblem{uType, tType, isinplace, P, NP, F, G, K, ND}(u,
args...) where
{uType, tType, isinplace, P, NP, F, G, K, ND}
args...) where
{uType, tType, isinplace, P, NP, F, G, K, ND}
function SDESolutionAdjoint(ȳ)
(ȳ, ntuple(_ -> nothing, length(args))...)
end
Expand All @@ -126,24 +126,24 @@ end
end

@adjoint function NonlinearSolution{T, N, uType, R, P, A, O, uType2}(u,
args...) where {
T,
N,
uType,
R,
P,
A,
O,
uType2,
}
args...) where {
T,
N,
uType,
R,
P,
A,
O,
uType2,
}
function NonlinearSolutionAdjoint(ȳ)
(ȳ, ntuple(_ -> nothing, length(args))...)
end
NonlinearSolution{T, N, uType, R, P, A, O, uType2}(u, args...), NonlinearSolutionAdjoint
end

@adjoint function literal_getproperty(sol::AbstractTimeseriesSolution,
::Val{:u})
::Val{:u})
function solu_adjoint(Δ)
zerou = zero(sol.prob.u0)
= @. ifelse=== nothing, (zerou,), Δ)
Expand All @@ -153,7 +153,7 @@ end
end

@adjoint function literal_getproperty(sol::SciMLBase.AbstractNoTimeSolution,
::Val{:u})
::Val{:u})
function solu_adjoint(Δ)
zerou = zero(sol.prob.u0)
= @. ifelse=== nothing, zerou, Δ)
Expand All @@ -163,7 +163,7 @@ end
end

@adjoint function literal_getproperty(sol::SciMLBase.OptimizationSolution,
::Val{:u})
::Val{:u})
function solu_adjoint(Δ)
zerou = zero(sol.u)
= @. ifelse=== nothing, zerou, Δ)
Expand Down Expand Up @@ -214,8 +214,8 @@ end
end

@adjoint function SciMLBase.responsible_map(f,
args::Union{AbstractArray, Tuple
}...)
args::Union{AbstractArray, Tuple
}...)
∇responsible_map(__context__, f, args...)
end

Expand Down
34 changes: 17 additions & 17 deletions src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,23 +653,23 @@ function unwrapped_f(f::FunctionWrappersWrappers.FunctionWrappersWrapper)
end

function specialization(::Union{ODEFunction{iip, specialize},
SDEFunction{iip, specialize}, DDEFunction{iip, specialize},
SDDEFunction{iip, specialize},
DAEFunction{iip, specialize},
DynamicalODEFunction{iip, specialize},
SplitFunction{iip, specialize},
DynamicalSDEFunction{iip, specialize},
SplitSDEFunction{iip, specialize},
DynamicalDDEFunction{iip, specialize},
DiscreteFunction{iip, specialize},
ImplicitDiscreteFunction{iip, specialize},
RODEFunction{iip, specialize},
NonlinearFunction{iip, specialize},
OptimizationFunction{iip, specialize},
BVPFunction{iip, specialize},
IntegralFunction{iip, specialize},
BatchIntegralFunction{iip, specialize}}) where {iip,
specialize}
SDEFunction{iip, specialize}, DDEFunction{iip, specialize},
SDDEFunction{iip, specialize},
DAEFunction{iip, specialize},
DynamicalODEFunction{iip, specialize},
SplitFunction{iip, specialize},
DynamicalSDEFunction{iip, specialize},
SplitSDEFunction{iip, specialize},
DynamicalDDEFunction{iip, specialize},
DiscreteFunction{iip, specialize},
ImplicitDiscreteFunction{iip, specialize},
RODEFunction{iip, specialize},
NonlinearFunction{iip, specialize},
OptimizationFunction{iip, specialize},
BVPFunction{iip, specialize},
IntegralFunction{iip, specialize},
BatchIntegralFunction{iip, specialize}}) where {iip,
specialize}
specialize
end

Expand Down
98 changes: 49 additions & 49 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, I, R} <: AbstractContin
reltol::T2
repeat_nudge::T3
function ContinuousCallback(condition::F1, affect!::F2, affect_neg!::F3,
initialize::F4, finalize::F5, idxs::I, rootfind,
interp_points, save_positions, dtrelax::R, abstol::T,
reltol::T2,
repeat_nudge::T3) where {F1, F2, F3, F4, F5, T, T2, T3, I, R
}
initialize::F4, finalize::F5, idxs::I, rootfind,
interp_points, save_positions, dtrelax::R, abstol::T,
reltol::T2,
repeat_nudge::T3) where {F1, F2, F3, F4, F5, T, T2, T3, I, R
}
new{F1, F2, F3, F4, F5, T, T2, T3, I, R}(condition,
affect!, affect_neg!,
initialize, finalize, idxs, rootfind,
Expand All @@ -121,15 +121,15 @@ struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, I, R} <: AbstractContin
end

function ContinuousCallback(condition, affect!, affect_neg!;
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0,
repeat_nudge = 1 // 100)
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0,
repeat_nudge = 1 // 100)
ContinuousCallback(condition, affect!, affect_neg!, initialize, finalize,
idxs,
rootfind, interp_points,
Expand All @@ -138,15 +138,15 @@ function ContinuousCallback(condition, affect!, affect_neg!;
end

function ContinuousCallback(condition, affect!;
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
affect_neg! = affect!,
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
affect_neg! = affect!,
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
ContinuousCallback(condition, affect!, affect_neg!, initialize, finalize, idxs,
rootfind, interp_points,
collect(save_positions),
Expand Down Expand Up @@ -211,11 +211,11 @@ struct VectorContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, I, R} <:
reltol::T2
repeat_nudge::T3
function VectorContinuousCallback(condition::F1, affect!::F2, affect_neg!::F3, len::Int,
initialize::F4, finalize::F5, idxs::I, rootfind,
interp_points, save_positions, dtrelax::R,
abstol::T, reltol::T2,
repeat_nudge::T3) where {F1, F2, F3, F4, F5, T, T2,
T3, I, R}
initialize::F4, finalize::F5, idxs::I, rootfind,
interp_points, save_positions, dtrelax::R,
abstol::T, reltol::T2,
repeat_nudge::T3) where {F1, F2, F3, F4, F5, T, T2,
T3, I, R}
new{F1, F2, F3, F4, F5, T, T2, T3, I, R}(condition,
affect!, affect_neg!, len,
initialize, finalize, idxs, rootfind,
Expand All @@ -226,14 +226,14 @@ struct VectorContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, I, R} <:
end

function VectorContinuousCallback(condition, affect!, affect_neg!, len;
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
VectorContinuousCallback(condition, affect!, affect_neg!, len,
initialize, finalize,
idxs,
Expand All @@ -243,15 +243,15 @@ function VectorContinuousCallback(condition, affect!, affect_neg!, len;
end

function VectorContinuousCallback(condition, affect!, len;
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
affect_neg! = affect!,
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind = LeftRootFind,
save_positions = (true, true),
affect_neg! = affect!,
interp_points = 10,
dtrelax = 1,
abstol = 10eps(), reltol = 0, repeat_nudge = 1 // 100)
VectorContinuousCallback(condition, affect!, affect_neg!, len, initialize, finalize,
idxs,
rootfind, interp_points,
Expand Down Expand Up @@ -297,16 +297,16 @@ struct DiscreteCallback{F1, F2, F3, F4} <: AbstractDiscreteCallback
finalize::F4
save_positions::BitArray{1}
function DiscreteCallback(condition::F1, affect!::F2,
initialize::F3, finalize::F4,
save_positions) where {F1, F2, F3, F4}
initialize::F3, finalize::F4,
save_positions) where {F1, F2, F3, F4}
new{F1, F2, F3, F4}(condition,
affect!, initialize, finalize,
BitArray(collect(save_positions)))
end
end
function DiscreteCallback(condition, affect!;
initialize = INITIALIZE_DEFAULT, finalize = FINALIZE_DEFAULT,
save_positions = (true, true))
initialize = INITIALIZE_DEFAULT, finalize = FINALIZE_DEFAULT,
save_positions = (true, true))
DiscreteCallback(condition, affect!, initialize, finalize, save_positions)
end

Expand Down
Loading

0 comments on commit eab64f9

Please sign in to comment.