From eec9252d166a6675002d86b00fdb142381488127 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Wed, 18 Aug 2021 16:36:43 -0400 Subject: [PATCH 1/4] start trying to precompile ModelingToolkit better MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```julia using ModelingToolkit, OrdinaryDiffEq function f() @parameters t σ ρ β @variables x(t) y(t) z(t) D = Differential(t) eqs = [D(D(x)) ~ σ*(y-x), D(y) ~ x*(ρ-z)-y, D(z) ~ x*y - β*z] @named sys = ODESystem(eqs) sys = ode_order_lowering(sys) u0 = [D(x) => 2.0, x => 1.0, y => 0.0, z => 0.0] p = [σ => 28.0, ρ => 10.0, β => 8/3] tspan = (0.0,100.0) prob = ODEProblem(sys,u0,tspan,p,jac=true) end using SnoopCompile tinf = @snoopi_deep f() ``` ```julia Before: InferenceTimingNode: 8.138765/20.550152 on Core.Compiler.Timings.ROOT() with 821 direct children InferenceTimingNode: 8.152606/20.643050 on Core.Compiler.Timings.ROOT() with 821 direct children After: InferenceTimingNode: 8.216759/17.715817 on Core.Compiler.Timings.ROOT() with 839 direct children InferenceTimingNode: 8.272943/17.854555 on Core.Compiler.Timings.ROOT() with 840 direct children ``` only 2 seconds for now, but it's a start. --- src/ModelingToolkit.jl | 3 +++ src/precompile.jl | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/precompile.jl diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index f46b500fb6..969ba43e7e 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -151,6 +151,9 @@ using .SystemStructures include("systems/alias_elimination.jl") include("structural_transformation/StructuralTransformations.jl") + +include("precompile.jl") + @reexport using .StructuralTransformations for S in subtypes(ModelingToolkit.AbstractSystem) diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 0000000000..c7ae5a9be5 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,28 @@ +let + while true + @parameters t σ ρ β + @variables x(t) y(t) z(t) + D = Differential(t) + + eqs = [D(D(x)) ~ σ*(y-x) + 0.000000000000135, + D(y) ~ x*(ρ-z)-y, + D(z) ~ x*y - β*z] + + @named sys = ODESystem(eqs) + sys = ode_order_lowering(sys) + + u0 = [D(x) => 2.0, + x => 1.0, + y => 0.0, + z => 0.0] + + p = [σ => 28.0, + ρ => 10.0, + β => 8/3] + + tspan = (0.0,100.0) + prob = ODEProblem(sys,u0,tspan,p,jac=true) + + break + end +end From 3c45aeaa73eeb2d285061c658860c4ced674d0af Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 1 Feb 2022 08:31:18 -0500 Subject: [PATCH 2/4] Update precompile.jl --- src/precompile.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/precompile.jl b/src/precompile.jl index c7ae5a9be5..96e201d12c 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -9,7 +9,7 @@ let D(z) ~ x*y - β*z] @named sys = ODESystem(eqs) - sys = ode_order_lowering(sys) + sys = structural_simplify(sys) u0 = [D(x) => 2.0, x => 1.0, From e12e97c6fcc84018f31705f8c61847af6959fa39 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Tue, 1 Feb 2022 09:00:24 -0500 Subject: [PATCH 3/4] Move precompile.jl to the end --- src/ModelingToolkit.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index 969ba43e7e..42d4472741 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -152,8 +152,6 @@ using .SystemStructures include("systems/alias_elimination.jl") include("structural_transformation/StructuralTransformations.jl") -include("precompile.jl") - @reexport using .StructuralTransformations for S in subtypes(ModelingToolkit.AbstractSystem) @@ -210,4 +208,6 @@ export modelingtoolkitize export @variables, @parameters export @named, @nonamespace, @namespace, extend, compose +include("precompile.jl") + end # module From 33f1261a15044d8ba97cbe566ff351c5cedad2fc Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Tue, 1 Feb 2022 09:27:50 -0500 Subject: [PATCH 4/4] once you hack the fun don't snack. --- src/precompile.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/precompile.jl b/src/precompile.jl index 96e201d12c..802333975f 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -4,7 +4,7 @@ let @variables x(t) y(t) z(t) D = Differential(t) - eqs = [D(D(x)) ~ σ*(y-x) + 0.000000000000135, + eqs = [D(D(x)) ~ σ*(y-x) + x^0.000000000000135, D(y) ~ x*(ρ-z)-y, D(z) ~ x*y - β*z]