From ced7d2517471d46f6c07a3a60cc5a1b2b679c85f Mon Sep 17 00:00:00 2001 From: Datseris Date: Wed, 10 Sep 2025 10:30:49 +0100 Subject: [PATCH 1/3] move to mtk10 --- CHANGELOG.md | 4 ++++ Project.toml | 4 ++-- src/make.jl | 16 +++++++--------- test/runtests.jl | 10 ++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b175c8e..fb540bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ProcessBasedModelling.jl follows semver 2.0. Changelog is kept with respect to v1 release. +## 1.8 + +- Updated to ModelingToolkit.jl v10. `type` keyword in `processes_to_mtkmodel` is now no longer used. + ## 1.7 - Added an additional check when constructing the raw equations that catches diff --git a/Project.toml b/Project.toml index 185154b..e29a5f9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,13 @@ name = "ProcessBasedModelling" uuid = "ca969041-2cf3-4b10-bc21-86f4417093eb" authors = ["Datseris "] -version = "1.7.0" +version = "1.8.0" [deps] ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" [compat] -ModelingToolkit = "9.0" +ModelingToolkit = "10.0" Reexport = "1.2" julia = "1.9.0" diff --git a/src/make.jl b/src/make.jl index 86789f4..76a49aa 100644 --- a/src/make.jl +++ b/src/make.jl @@ -1,10 +1,9 @@ """ processes_to_mtkmodel(processes::Vector [, default]; kw...) -Construct a ModelingToolkit.jl model/system using the provided `processes` and `default` processes. -The model/system is _not_ structurally simplified. Use the function -[`processes_to_mtkeqs`](@ref) to obtain the raw `Vector{Equation}` before it is -passed to the MTK model/system like `ODESystem`. +Construct a ModelingToolkit.jl model using the provided `processes` and `default` processes. +The model is _not_ `mtkcompile`-d. Use the function +[`processes_to_mtkeqs`](@ref) to obtain the raw `Vector{Equation}`. During construction, the following automations improve user experience: @@ -49,9 +48,8 @@ These registered default processes are used when `default` is a `Module`. ## Keyword arguments -- `type = ODESystem`: the model type to make. -- `name = nameof(type)`: the name of the model. -- `independent = t`: the independent variable (default: `@variables t`). +- `name = :model`: the name of the model. +- `independent = t`: the independent variable (default: `@independent_variables t`). `t` is also exported by ProcessBasedModelling.jl for convenience. - `warn_default::Bool = true`: if `true`, throw a warning when a variable does not have an assigned process but it has a default value so that it becomes a parameter instead. @@ -61,10 +59,10 @@ These registered default processes are used when `default` is a `Module`. (has happened to me many times!). """ function processes_to_mtkmodel(args...; - type = ODESystem, name = nameof(type), independent = t, kw..., + type = System, name = :model, independent = t, kw..., ) eqs = processes_to_mtkeqs(args...; kw...) - sys = type(eqs, independent; name) + sys = System(eqs, independent; name) return sys end diff --git a/test/runtests.jl b/test/runtests.jl index 2d31b1f..286ab3d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -64,7 +64,7 @@ end @test sys isa ODESystem @test length(unknowns(sys)) == 3 - sys = structural_simplify(sys) + sys = mtkcompile(sys) @test length(unknowns(sys)) == 1 @test has_symbolic_var(equations(sys), T) @@ -87,13 +87,11 @@ end ] sys = processes_to_mtkmodel(processes) - @test sys isa ODESystem @test length(unknowns(sys)) == 3 - sys = structural_simplify(sys) + sys = mtkcompile(sys) @test length(unknowns(sys)) == 1 @test has_symbolic_var(equations(sys), T) - end @testset "add missing processes" begin @@ -192,7 +190,7 @@ end AdditionProcess(TimeDerivative(q, x^2, 1.2), ExpRelaxation(q, x^2), q ~ y*x) ] mtk = processes_to_mtkmodel(processes) - mtk = structural_simplify(mtk) + mtk = mtkcompile(mtk) eqs = all_equations(mtk) @test has_symbolic_var(eqs, x) @test has_symbolic_var(eqs, y) @@ -209,7 +207,7 @@ end @test_throws ArgumentError AdditionProcess(x ~ 0.1z, y ~ x^2) end -@testset "ODESystem as process" begin +@testset "System as process" begin @variables z(t) = 0.0 @variables x(t) = 0.0 @variables y(t) = 0.0 From 37636590fd1879f1a47562a51825c38185b5b851 Mon Sep 17 00:00:00 2001 From: Datseris Date: Wed, 10 Sep 2025 10:39:51 +0100 Subject: [PATCH 2/3] fix system mistake --- src/make.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/make.jl b/src/make.jl index 76a49aa..e508c64 100644 --- a/src/make.jl +++ b/src/make.jl @@ -142,9 +142,9 @@ function processes_to_mtkeqs(_processes::Vector, default::Dict{Num, Any}; end function expand_multi_processes(procs::Vector) - etypes = Union{Vector, ODESystem, SDESystem, PDESystem} + etypes = Union{Vector, System} !any(p -> p isa etypes, procs) && return procs - # Expand vectors of processes or ODESystems + # Expand vectors of processes or Systems expanded = Any[procs...] idxs = findall(p -> p isa etypes, procs) multiprocs = expanded[idxs] @@ -152,7 +152,7 @@ function expand_multi_processes(procs::Vector) for mp in multiprocs if mp isa Vector append!(expanded, mp) - else # then it is XDE system + else # then it is System append!(expanded, equations(mp)) end end From a9455fa00eaf121ed90172816c2de66afd5b0a14 Mon Sep 17 00:00:00 2001 From: Datseris Date: Wed, 10 Sep 2025 13:03:10 +0100 Subject: [PATCH 3/3] fix over determination of system --- test/runtests.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 286ab3d..e5cd1ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,8 +20,8 @@ end # First, make some default processes @variables T(t) = 300.0 # temperature, in Kelvin - @variables α(t) = 0.3 # albedo of ice, unitless - @variables ε(t) = 0.5 # effective emissivity, unitless + @variables α(t) # albedo of ice, unitless + @variables ε(t) # effective emissivity, unitless solar_constant = 340.25 # W/m^2, already divided by 4 σ_Stefan_Boltzman = 5.670374419e-8 # stefan boltzman constant @@ -61,9 +61,7 @@ end ] sys = processes_to_mtkmodel(processes) - @test sys isa ODESystem @test length(unknowns(sys)) == 3 - sys = mtkcompile(sys) @test length(unknowns(sys)) == 1 @test has_symbolic_var(equations(sys), T)