Skip to content

Commit e755234

Browse files
Merge pull request #502 from SciML/v9
Update for MTK v9
2 parents 01fdb1a + f0dd392 commit e755234

File tree

8 files changed

+42
-36
lines changed

8 files changed

+42
-36
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
- DataDrivenLux
2525
version:
2626
- '1'
27-
- '1.6'
2827
steps:
2928
- uses: actions/checkout@v4
3029
- uses: julia-actions/setup-julia@v1

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DataInterpolations = "4"
2929
DiffEqBase = "6"
3030
DocStringExtensions = "0.7, 0.8, 0.9"
3131
MLUtils = "0.3, 0.4"
32-
ModelingToolkit = "7, 8"
32+
ModelingToolkit = "9"
3333
Parameters = "0.12"
3434
ProgressMeter = "1.6"
3535
QuadGK = "2.4"
@@ -40,7 +40,7 @@ Statistics = "1"
4040
StatsBase = "0.32.0, 0.33, 0.34"
4141
SymbolicUtils = "1"
4242
Symbolics = "5"
43-
julia = "1.6"
43+
julia = "1.10"
4444

4545
[extras]
4646
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1313
DataDrivenDiffEq = "1"
1414
Documenter = "1"
1515
Literate = "2.14"
16-
ModelingToolkit = "8"
16+
ModelingToolkit = "9"
1717
OrdinaryDiffEq = "6"
1818
Plots = "1"
1919
StableRNGs = "1"

src/DataDrivenDiffEq.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using ModelingToolkit: AbstractSystem
1717
using SymbolicUtils: operation, arguments, istree, issym
1818
using Symbolics
1919
using Symbolics: scalarize, variable, value
20-
@reexport using ModelingToolkit: states, parameters, independent_variable, observed,
20+
@reexport using ModelingToolkit: unknowns, parameters, independent_variable, observed,
2121
controls, get_iv, get_observed
2222

2323
using Random
@@ -97,7 +97,7 @@ include("./basis/utils.jl")
9797
include("./basis/type.jl")
9898
export Basis
9999
export jacobian, dynamics
100-
export implicit_variables
100+
export implicit_variables, states
101101
export get_parameter_values, get_parameter_map
102102

103103
include("./utils/basis_generators.jl")

src/basis/type.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct Basis{IMPL, CTRLS} <: AbstractBasis
5353
"""The equations of the basis"""
5454
eqs::Vector{Equation}
5555
"""Dependent (state) variables"""
56-
states::Vector
56+
unknowns::Vector
5757
"""Control variables"""
5858
ctrls::Vector
5959
"""Parameters"""
@@ -168,7 +168,7 @@ end
168168
## Printing
169169

170170
@inline function Base.print(io::IO, x::AbstractBasis)
171-
state = states(x)
171+
state = unknowns(x)
172172
ps = parameters(x)
173173
Base.printstyled(io, "Model $(nameof(x)) with $(length(x)) equations\n"; bold = true)
174174
print(io, "States :")
@@ -207,7 +207,7 @@ end
207207
@inline function Base.print(io::IO, x::AbstractBasis, fullview::Bool)
208208
!fullview && return print(io, x)
209209

210-
state = states(x)
210+
state = unknowns(x)
211211
ps = parameters(x)
212212
Base.printstyled(io, "Model $(nameof(x)) with $(length(x)) equations\n"; bold = true)
213213
print(io, "States :")
@@ -259,6 +259,10 @@ function implicit_variables(b::AbstractBasis)
259259
return getfield(b, :implicit)
260260
end
261261

262+
function states(b::AbstractBasis)
263+
return getfield(b, :unknowns)
264+
end
265+
262266
# For internal use
263267
is_implicit(b::Basis{X, <:Any}) where {X} = X
264268
is_controlled(b::Basis{<:Any, X}) where {X} = X
@@ -380,7 +384,7 @@ Base.iterate(x::B, id) where {B <: AbstractBasis} = iterate(equations(x), id)
380384
## Internal update
381385
function __update!(b::AbstractBasis, eval_expression = false)
382386
ff = DataDrivenFunction([bi.rhs for bi in collect(equations(b))],
383-
implicit_variables(b), states(b), parameters(b), [get_iv(b)],
387+
implicit_variables(b), unknowns(b), parameters(b), [get_iv(b)],
384388
controls(b), eval_expression)
385389
@set! b.f = ff
386390
return
@@ -403,13 +407,14 @@ If control variables are defined, the function can also be called by `f(u,p,t,co
403407
404408
If the Jacobian with respect to other variables is needed, it can be passed via a second argument.
405409
"""
406-
jacobian(x::Basis, eval_expression::Bool = false) = jacobian(x, states(x), eval_expression)
410+
jacobian(x::Basis, eval_expression::Bool = false) = jacobian(
411+
x, unknowns(x), eval_expression)
407412

408413
function jacobian(x::Basis, s, eval_expression::Bool = false)
409414
j = Symbolics.jacobian([xi.rhs for xi in equations(x)], s)
410415

411416
return DataDrivenFunction(j,
412-
implicit_variables(x), states(x), parameters(x), [get_iv(x)],
417+
implicit_variables(x), unknowns(x), parameters(x), [get_iv(x)],
413418
controls(x), eval_expression)
414419
end
415420

@@ -481,7 +486,7 @@ end
481486

482487
function Base.merge!(x::Basis, y::Basis; eval_expression = false)
483488
push!(x, equations(y))
484-
@set! x.states = unique(vcat(states(x), states(y)))
489+
@set! x.unknowns = unique(vcat(unknowns(x), unknowns(y)))
485490
@set! x.ps = unique(vcat(parameters(x), parameters(y)))
486491
@set! x.ctrls = unique(vcat(controls(x), controls(y)))
487492
@set! x.observed = unique(vcat(get_observed(x), get_observed(y)))

src/problem/type.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ get_name(p::AbstractDataDrivenProblem) = getfield(p, :name)
287287

288288
## Utils
289289

290-
function ModelingToolkit.states(p::AbstractDataDrivenProblem, i = :, j = :)
290+
function states(p::AbstractDataDrivenProblem, i = :, j = :)
291291
x = getfield(p, :X)
292292
isempty(x) ? x : getindex(x, i, j)
293293
end

test/basis/basis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ end
114114

115115
@test size(basis) == (6,)
116116
@test size(basis_2) == (5,)
117-
@test basis_2([1.0; 2.0; π], [0.0; 1.0]) [1.0; -1.0; π; 2.0; 1.0]
117+
@test basis_2([1.0; 2.0; π], [0.0; 1.0]) [1.0; -1.0; 2.0; π; 1.0]
118118
@test basis([1.0; 2.0; π], [0.0; 1.0]) [1.0; 2.0; π; -1.0; 5 * π + 2.0; 1.0]
119119

120120
@test size(basis) == size(basis_2) .+ (1,)

test/runtests.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SafeTestsets, Pkg
1+
using SafeTestsets, Test, Pkg
22

33
@info "Finished loading packages"
44

@@ -18,26 +18,28 @@ end
1818

1919
@time begin
2020
if GROUP == "All" || GROUP == "Core" || GROUP == "Downstream"
21-
@safetestset "Basis" begin
22-
include("./basis/basis.jl")
23-
end
24-
@safetestset "Implicit Basis" begin
25-
include("./basis/implicit_basis.jl")
26-
end
27-
@safetestset "Basis generators" begin
28-
include("./basis/generators.jl")
29-
end
30-
@safetestset "DataDrivenProblem" begin
31-
include("./problem/problem.jl")
32-
end
33-
@safetestset "DataDrivenSolution" begin
34-
include("./solution/solution.jl")
35-
end
36-
@safetestset "Utilities" begin
37-
include("./utils.jl")
38-
end
39-
@safetestset "CommonSolve" begin
40-
include("./commonsolve/commonsolve.jl")
21+
@testset "All" begin
22+
@safetestset "Basis" begin
23+
include("./basis/basis.jl")
24+
end
25+
@safetestset "Implicit Basis" begin
26+
include("./basis/implicit_basis.jl")
27+
end
28+
@safetestset "Basis generators" begin
29+
include("./basis/generators.jl")
30+
end
31+
@safetestset "DataDrivenProblem" begin
32+
include("./problem/problem.jl")
33+
end
34+
@safetestset "DataDrivenSolution" begin
35+
include("./solution/solution.jl")
36+
end
37+
@safetestset "Utilities" begin
38+
include("./utils.jl")
39+
end
40+
@safetestset "CommonSolve" begin
41+
include("./commonsolve/commonsolve.jl")
42+
end
4143
end
4244
else
4345
dev_subpkg(GROUP)

0 commit comments

Comments
 (0)