Skip to content

Commit 6f1a1d8

Browse files
committed
Merge remote-tracking branch 'origin' into idp
Merge
2 parents 3619c74 + d819c31 commit 6f1a1d8

35 files changed

+394
-219
lines changed

.typos.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[default.extend-words]
2-
ND = "ND"
2+
ND = "ND"
3+
Cachable = "Cachable"

Project.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SciMLBase"
22
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
33
authors = ["Chris Rackauckas <[email protected]> and contributors"]
4-
version = "2.72.0"
4+
version = "2.74.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -12,12 +12,12 @@ ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1212
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1313
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
15-
Expronicon = "6b7a57c9-7cc1-4fdf-b7f5-e857abae3636"
1615
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
1716
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
1817
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1918
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2019
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
20+
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
2121
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
2222
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
2323
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -34,6 +34,7 @@ SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
3434
[weakdeps]
3535
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
3636
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
37+
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
3738
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
3839
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
3940
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
@@ -43,6 +44,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
4344

4445
[extensions]
4546
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
47+
SciMLBaseMLStyleExt = "MLStyle"
4648
SciMLBaseMakieExt = "Makie"
4749
SciMLBasePartialFunctionsExt = "PartialFunctions"
4850
SciMLBasePyCallExt = "PyCall"
@@ -62,14 +64,15 @@ DataFrames = "1.6"
6264
Distributed = "1.10"
6365
DocStringExtensions = "0.9"
6466
EnumX = "1"
65-
Expronicon = "0.8"
6667
ForwardDiff = "0.10.36"
6768
FunctionWrappersWrappers = "0.1.3"
6869
IteratorInterfaceExtensions = "^1"
6970
LinearAlgebra = "1.10"
7071
Logging = "1.10"
72+
MLStyle = "0.4.17"
7173
Makie = "0.20, 0.21, 0.22"
7274
Markdown = "1.10"
75+
Moshi = "0.3"
7376
NonlinearSolve = "3, 4"
7477
PartialFunctions = "1.1"
7578
PrecompileTools = "1.2"
@@ -99,6 +102,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
99102
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
100103
DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
101104
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
105+
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
102106
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
103107
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
104108
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
@@ -116,4 +120,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
116120
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
117121

118122
[targets]
119-
test = ["Pkg", "Plots", "UnicodePlots", "SafeTestsets", "Serialization", "Test", "StableRNGs", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions", "DataFrames", "NonlinearSolve", "OrdinaryDiffEq", "ForwardDiff", "Tables"]
123+
test = ["Pkg", "Plots", "UnicodePlots", "SafeTestsets", "Serialization", "Test", "StableRNGs", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions", "DataFrames", "NonlinearSolve", "OrdinaryDiffEq", "ForwardDiff", "Tables", "MLStyle"]

docs/src/interfaces/Common_Keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ Note that if a method does not have adaptivity, the following rules apply:
102102
## Memory Optimizations
103103

104104
- `alias`: an `AbstractAliasSpecifier` object that holds fields specifying which variables to alias
105-
when solving. For example, to tell an ODE solver to alias the `u0` array, you can use an `ODEAliases` object,
106-
and the `alias_u0` keyword argument, e.g. `solve(prob,alias = ODEAliases(alias_u0 = true))`.
105+
when solving. For example, to tell an ODE solver to alias the `u0` array, you can use an `ODEAliases` object,
106+
and the `alias_u0` keyword argument, e.g. `solve(prob,alias = ODEAliases(alias_u0 = true))`.
107107
For more information on what can be aliased for each problem type, see the documentation for the `AbstractAliasSpecifier`
108108
associated with that problem type. Set to `true` to alias every variable possible, or to `false` to disable aliasing.
109109
Defaults to an `AbstractAliasSpecifier` instance with `nothing` for all fields, which tells the solver to use the default behavior.

ext/SciMLBaseMLStyleExt.jl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
The SciMLBaseMLStyleExt module provides backwards compatibility for those using MLStyle
3+
to pattern match the Clocks algebraic data type (ADT).
4+
5+
Before this ADT was made using Expronomicon, which directly supported MLStyle.
6+
Now that the ADT is made using Moshi, we need to define MLStyle custom patterns.
7+
Using Moshi pattern matching is recommended over relying on this package extension.
8+
"""
9+
module SciMLBaseMLStyleExt
10+
11+
using SciMLBase: TimeDomain, ContinuousClock, SolverStepClock, PeriodicClock
12+
using MLStyle: MLStyle
13+
using MLStyle.AbstractPatterns: literal, wildcard, PComp, BasicPatterns, decons
14+
using Moshi.Data: isa_variant
15+
16+
# This makes Singletons also work without parentheses in matches
17+
MLStyle.is_enum(::Type{ContinuousClock}) = true
18+
MLStyle.is_enum(::Type{SolverStepClock}) = true
19+
function MLStyle.pattern_uncall(::Type{ContinuousClock}, self::Function, _, _, _)
20+
literal(ContinuousClock())
21+
end
22+
MLStyle.pattern_uncall(T::TimeDomain, self::Function, _, _, _) = literal(T())
23+
24+
function MLStyle.pattern_uncall(::Type{SolverStepClock}, self::Function, _, _, _)
25+
literal(SolverStepClock())
26+
end
27+
28+
function periodic_clock_pattern(c)
29+
if c isa TimeDomain && isa_variant(c, PeriodicClock)
30+
(c.dt, c.phase)
31+
else
32+
# These values are used in match results, but they shouldn't.
33+
# This means that any wildcard pattern will be `nothing`, see broken test.
34+
(nothing, nothing)
35+
end
36+
end
37+
38+
function MLStyle.pattern_uncall(
39+
::Type{PeriodicClock}, self::Function, type_params, type_args, args)
40+
@assert isempty(type_params)
41+
@assert isempty(type_args)
42+
n_args = length(args)
43+
44+
trans(expr) = Expr(:call, periodic_clock_pattern, expr)
45+
type_infer(_...) = Any
46+
47+
extract = if n_args <= 1
48+
(expr::Any, i::Int, ::Any, ::Any) -> expr
49+
else
50+
(expr::Any, i::Int, ::Any, ::Any) -> Core._expr(:ref, expr, i)
51+
end
52+
53+
comp = PComp(
54+
"PeriodicClock(c)", type_infer; view = BasicPatterns.SimpleCachablePre(trans))
55+
56+
ps = if n_args === 0
57+
[]
58+
elseif n_args === 1
59+
[self(Expr(:call, Some, args[1]))]
60+
elseif n_args === 2
61+
if args[2] == :(_...)
62+
[self(args[1]), wildcard]
63+
else
64+
[self(args[1]), self(args[2])]
65+
end
66+
else
67+
error("too many arguments")
68+
end
69+
70+
decons(comp, extract, ps)
71+
end
72+
73+
end

src/SciMLBase.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import RuntimeGeneratedFunctions
2323
import EnumX
2424
import ADTypes: ADTypes, AbstractADType
2525
import Accessors: @set, @reset, @delete, @insert
26-
using Expronicon.ADT: @match
26+
using Moshi.Data: @data
27+
using Moshi.Match: @match
2728

2829
using Reexport
2930
using SciMLOperators

src/clock.jl

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
1-
module Clocks
2-
3-
export TimeDomain
4-
5-
using Expronicon.ADT: variant_type, @adt, @match
6-
7-
@adt TimeDomain begin
8-
Continuous
1+
@data Clocks begin
2+
ContinuousClock
93
struct PeriodicClock
104
dt::Union{Nothing, Float64, Rational{Int}}
115
phase::Float64 = 0.0
126
end
137
SolverStepClock
148
end
159

16-
Base.Broadcast.broadcastable(d::TimeDomain) = Ref(d)
17-
18-
const DiscriminatorType = typeof(variant_type(Continuous))
19-
20-
function Base.write(io::IO, x::DiscriminatorType)
21-
write(io, Base.reinterpret(UInt32, x))
22-
end
23-
24-
function Base.read(io::IO, ::Type{DiscriminatorType})
25-
Base.reinterpret(DiscriminatorType, read(io, UInt32))
26-
end
27-
28-
end
10+
# for backwards compatibility
11+
const TimeDomain = Clocks.Type
12+
using .Clocks: ContinuousClock, PeriodicClock, SolverStepClock
13+
const Continuous = ContinuousClock()
14+
(clock::TimeDomain)() = clock
2915

30-
using .Clocks
16+
Base.Broadcast.broadcastable(d::TimeDomain) = Ref(d)
3117

3218
"""
3319
Clock(dt)
@@ -55,27 +41,27 @@ filters.
5541
""" SolverStepClock
5642

5743
isclock(c) = @match c begin
58-
PeriodicClock(_...) => true
44+
PeriodicClock() => true
5945
_ => false
6046
end
6147

6248
issolverstepclock(c) = @match c begin
63-
&SolverStepClock => true
49+
SolverStepClock() => true
6450
_ => false
6551
end
6652

6753
iscontinuous(c) = @match c begin
68-
&Continuous => true
54+
ContinuousClock() => true
6955
_ => false
7056
end
7157

7258
is_discrete_time_domain(c) = !iscontinuous(c)
7359

7460
function first_clock_tick_time(c, t0)
7561
@match c begin
76-
PeriodicClock(dt, _...) => ceil(t0 / dt) * dt
77-
&SolverStepClock => t0
78-
&Continuous => error("Continuous is not a discrete clock")
62+
PeriodicClock(dt) => ceil(t0 / dt) * dt
63+
SolverStepClock() => t0
64+
ContinuousClock() => error("ContinuousClock() is not a discrete clock")
7965
end
8066
end
8167

@@ -90,13 +76,13 @@ function canonicalize_indexed_clock(ic::IndexedClock, sol::AbstractTimeseriesSol
9076
c = ic.clock
9177

9278
return @match c begin
93-
PeriodicClock(dt, _...) => ceil(sol.prob.tspan[1] / dt) * dt .+ (ic.idx .- 1) .* dt
94-
&SolverStepClock => begin
79+
PeriodicClock(dt) => ceil(sol.prob.tspan[1] / dt) * dt .+ (ic.idx .- 1) .* dt
80+
SolverStepClock() => begin
9581
ssc_idx = findfirst(eachindex(sol.discretes)) do i
9682
!isa(sol.discretes[i].t, AbstractRange)
9783
end
9884
sol.discretes[ssc_idx].t[ic.idx]
9985
end
100-
&Continuous => sol.t[ic.idx]
86+
ContinuousClock() => sol.t[ic.idx]
10187
end
10288
end

src/initialization.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,23 @@ end
295295
function is_trivial_initialization(prob::AbstractSciMLProblem)
296296
is_trivial_initialization(prob.f)
297297
end
298+
299+
@enum DETERMINED_STATUS OVERDETERMINED FULLY_DETERMINED UNDERDETERMINED
300+
301+
function initialization_status(prob::AbstractSciMLProblem)
302+
has_initialization_data(prob.f) || return nothing
303+
304+
sys = prob.f.initialization_data.initializeprob.f.sys
305+
isnothing(sys) && return nothing
306+
307+
neqs = length(equations(sys))
308+
nunknowns = length(unknowns(sys))
309+
310+
if neqs > nunknowns
311+
return OVERDETERMINED
312+
elseif neqs < nunknowns
313+
return UNDERDETERMINED
314+
else
315+
return FULLY_DETERMINED
316+
end
317+
end

src/problems/analytical_problems.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ end
2929

3030
export AnalyticalProblem, AbstractAnalyticalProblem
3131

32-
3332
@doc doc"""
3433
3534
Holds information on what variables to alias
@@ -66,5 +65,3 @@ struct AnalyticalAliasSpecifier <: AbstractAliasSpecifier
6665
end
6766
end
6867
end
69-
70-

src/problems/bvp_problems.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,3 @@ struct BVPAliasSpecifier <: AbstractAliasSpecifier
474474
end
475475
end
476476
end
477-
478-
479-

src/problems/dae_problems.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,3 @@ struct DAEAliasSpecifier
155155
end
156156
end
157157
end
158-
159-
160-

0 commit comments

Comments
 (0)