From 78863679194560ad8748bffb22d1db3512c4d1e8 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Thu, 20 Aug 2026 08:02:35 -0400 Subject: [PATCH] Add PrecompileTools workload Co-Authored-By: Chris Rackauckas --- Project.toml | 2 ++ src/ModelingToolkitStandardLibrary.jl | 12 ++++++++++++ test/precompile_workload.jl | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/precompile_workload.jl diff --git a/Project.toml b/Project.toml index d5ec408a..91942310 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" ModelingToolkitBase = "7771a370-6774-4173-bd38-47e70ca0b839" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46" SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" @@ -23,6 +24,7 @@ ForwardDiff = "0.10, 1" LinearAlgebra = "1.10" ModelingToolkit = "11.28" ModelingToolkitBase = "1.49" +PrecompileTools = "1.2.1" OrdinaryDiffEq = "7" OrdinaryDiffEqBDF = "2" OrdinaryDiffEqDefault = "2" diff --git a/src/ModelingToolkitStandardLibrary.jl b/src/ModelingToolkitStandardLibrary.jl index fb0455c3..fb9e17b0 100644 --- a/src/ModelingToolkitStandardLibrary.jl +++ b/src/ModelingToolkitStandardLibrary.jl @@ -1,5 +1,7 @@ module ModelingToolkitStandardLibrary import SymbolicUtils: unwrap +using ModelingToolkitBase: System, connect, t_nounits as t +using PrecompileTools: @compile_workload, @setup_workload """ @symcheck J > 0 || throw(ArgumentError("Expected `J` to be positive")) @@ -23,4 +25,14 @@ include("Electrical/Electrical.jl") include("Magnetic/Magnetic.jl") include("Hydraulic/Hydraulic.jl") +@setup_workload begin + constant = Blocks.Constant(; name = :constant, k = 1.0) + integrator = Blocks.Integrator(; name = :integrator, x = 0.0) + connections = [connect(constant.output, integrator.input)] + + @compile_workload begin + System(connections, t; name = :model, systems = [integrator, constant]) + end +end + end diff --git a/test/precompile_workload.jl b/test/precompile_workload.jl new file mode 100644 index 00000000..d61414d1 --- /dev/null +++ b/test/precompile_workload.jl @@ -0,0 +1,17 @@ +using ModelingToolkitStandardLibrary.Blocks +using ModelingToolkitBase: System, connect, equations, t_nounits as t +using Test + +@testset "Precompile workload" begin + constant = Constant(; name = :constant, k = 1.0) + integrator = Integrator(; name = :integrator, x = 0.0) + model = System( + [connect(constant.output, integrator.input)], + t; + name = :model, + systems = [integrator, constant] + ) + + @test model isa System + @test !isempty(equations(model)) +end