diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index d70d9d2afe..a80463b22b 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -79,6 +79,8 @@ jobs: elseif PKG == "ModelingToolkit" @info "Testing ModelingToolkit" Pkg.activate(".") + @info "`dev`ing ModelingToolkitBase" + Pkg.develop(PackageSpec(; path = "lib/ModelingToolkitBase")) @info "Running tests" GROUP Pkg.test() elseif PKG == "SciCompDSL" diff --git a/lib/ModelingToolkitBase/ext/MTKDynamicQuantitiesExt.jl b/lib/ModelingToolkitBase/ext/MTKDynamicQuantitiesExt.jl index 0edeaf8d0c..f958ea3808 100644 --- a/lib/ModelingToolkitBase/ext/MTKDynamicQuantitiesExt.jl +++ b/lib/ModelingToolkitBase/ext/MTKDynamicQuantitiesExt.jl @@ -17,7 +17,18 @@ function __init__() only(@independent_variables t [unit = DQ.u"s"]) end SymbolicUtils.hashcons(unwrap(MTK.t), true) - return MTK.D = Differential(MTK.t) + MTK.D = Differential(MTK.t) + # Workaround for Julia 1.10 compiler bug + # See https://github.com/SciML/ModelingToolkit.jl/issues/4211 + return @static if VERSION < v"1.11" + # Force collect_var! compilation to fix collect_vars! + @variables _dummy_t + @parameters _dummy_p + @variables _dummy_x(_dummy_t) = _dummy_p + _us = OrderedSet{SymbolicT}() + _ps = OrderedSet{SymbolicT}() + MTK.collect_var!(_us, _ps, unwrap(_dummy_x), unwrap(_dummy_t); depth = 0) + end end #For dispatching get_unit const Conditional = Union{typeof(ifelse)} diff --git a/lib/ModelingToolkitBase/test/initializationsystem.jl b/lib/ModelingToolkitBase/test/initializationsystem.jl index 4b4a3a0cbb..bd15774133 100644 --- a/lib/ModelingToolkitBase/test/initializationsystem.jl +++ b/lib/ModelingToolkitBase/test/initializationsystem.jl @@ -1524,7 +1524,11 @@ end prob.ps[Initial(y[1])] = 0.5 integ = init(prob, Tsit5(); abstol = 1.0e-6, reltol = 1.0e-6) @test integ[x] ≈ 0.5 - @test integ[y] ≈ [0.5, sqrt(3.5)] atol = 1.0e-6 + if VERSION < v"1.11" && !@isdefined(ModelingToolkit) # on lts with MTKBase, this flips sign + @test integ[y] ≈ [0.5, -sqrt(3.5)] atol = 1.0e-6 + else + @test integ[y] ≈ [0.5, sqrt(3.5)] atol = 1.0e-6 + end end @testset "Issue#3342" begin diff --git a/test/runtests.jl b/test/runtests.jl index 19ab5dd901..f8a583bbea 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,6 @@ import REPL const MTKBasePath = joinpath(dirname(@__DIR__), "lib", "ModelingToolkitBase") const MTKBasePkgSpec = PackageSpec(; path = MTKBasePath) -Pkg.develop([MTKBasePkgSpec]) const GROUP = get(ENV, "GROUP", "All") diff --git a/test/structural_transformation/utils.jl b/test/structural_transformation/utils.jl index 790adfb513..d241fe9cc9 100644 --- a/test/structural_transformation/utils.jl +++ b/test/structural_transformation/utils.jl @@ -216,14 +216,14 @@ end mapping = map_variables_to_equations(sys) x1 = operation(unwrap(osc1.x)) x2 = operation(unwrap(osc2.x)) - @test mapping[osc1.x] == (D(osc1.x) ~ osc1.y) - @test mapping[osc1.y] == (D(osc1.y) ~ osc1.jcn - osc1.k * x1(t - osc1.τ)) - @test mapping[osc1.delx] == (osc1.delx ~ x1(t - osc1.τ)) - @test mapping[osc1.jcn] == (osc1.jcn ~ osc2.delx) - @test mapping[osc2.x] == (D(osc2.x) ~ osc2.y) - @test mapping[osc2.y] == (D(osc2.y) ~ osc2.jcn - osc2.k * x2(t - osc2.τ)) - @test mapping[osc2.delx] == (osc2.delx ~ x2(t - osc2.τ)) - @test mapping[osc2.jcn] == (osc2.jcn ~ osc1.delx) + @test mapping[sys.osc1.x] == (D(sys.osc1.x) ~ sys.osc1.y) + @test mapping[sys.osc1.y] == (D(sys.osc1.y) ~ sys.osc1.jcn - sys.osc1.k * x1(t - sys.osc1.τ)) + @test mapping[sys.osc1.delx] == (sys.osc1.delx ~ x1(t - sys.osc1.τ)) + @test mapping[sys.osc1.jcn] == (sys.osc1.jcn ~ sys.osc2.delx) + @test mapping[sys.osc2.x] == (D(sys.osc2.x) ~ sys.osc2.y) + @test mapping[sys.osc2.y] == (D(sys.osc2.y) ~ sys.osc2.jcn - sys.osc2.k * x2(t - sys.osc2.τ)) + @test mapping[sys.osc2.delx] == (sys.osc2.delx ~ x2(t - sys.osc2.τ)) + @test mapping[sys.osc2.jcn] == (sys.osc2.jcn ~ sys.osc1.delx) @test length(mapping) == 8 end end