From eb2fa1829943a97fad4f7b7af3f27350bf502f2c Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 15 Jul 2025 13:25:01 +0530 Subject: [PATCH] refactor: move `@compile_workload` to after exports --- src/ModelingToolkit.jl | 70 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index 46c6892607..c81774946d 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -242,41 +242,6 @@ const D_nounits = Differential(t_nounits) const D_unitful = Differential(t_unitful) const D = Differential(t) -PrecompileTools.@compile_workload begin - using ModelingToolkit - @variables x(ModelingToolkit.t_nounits) - @named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits) - prob = ODEProblem(mtkcompile(sys), [x => 30.0], (0, 100), jac = true) - @mtkmodel __testmod__ begin - @constants begin - c = 1.0 - end - @structural_parameters begin - structp = false - end - if structp - @variables begin - x(t) = 0.0, [description = "foo", guess = 1.0] - end - else - @variables begin - x(t) = 0.0, [description = "foo w/o structp", guess = 1.0] - end - end - @parameters begin - a = 1.0, [description = "bar"] - if structp - b = 2 * a, [description = "if"] - else - c - end - end - @equations begin - x ~ a + b - end - end -end - export ODEFunction, convert_system_indepvar, System, OptimizationSystem, JumpSystem, SDESystem, NonlinearSystem, ODESystem export SDEFunction @@ -378,4 +343,39 @@ for prop in [SYS_PROPS; [:continuous_events, :discrete_events]] @eval @public $getter, $hasfn end +PrecompileTools.@compile_workload begin + using ModelingToolkit + @variables x(ModelingToolkit.t_nounits) + @named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits) + prob = ODEProblem(mtkcompile(sys), [x => 30.0], (0, 100), jac = true) + @mtkmodel __testmod__ begin + @constants begin + c = 1.0 + end + @structural_parameters begin + structp = false + end + if structp + @variables begin + x(t) = 0.0, [description = "foo", guess = 1.0] + end + else + @variables begin + x(t) = 0.0, [description = "foo w/o structp", guess = 1.0] + end + end + @parameters begin + a = 1.0, [description = "bar"] + if structp + b = 2 * a, [description = "if"] + else + c + end + end + @equations begin + x ~ a + b + end + end +end + end # module