Skip to content

Commit eec9252

Browse files
start trying to precompile ModelingToolkit better
```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.
1 parent 7969d00 commit eec9252

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/ModelingToolkit.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ using .SystemStructures
151151

152152
include("systems/alias_elimination.jl")
153153
include("structural_transformation/StructuralTransformations.jl")
154+
155+
include("precompile.jl")
156+
154157
@reexport using .StructuralTransformations
155158

156159
for S in subtypes(ModelingToolkit.AbstractSystem)

src/precompile.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
let
2+
while true
3+
@parameters t σ ρ β
4+
@variables x(t) y(t) z(t)
5+
D = Differential(t)
6+
7+
eqs = [D(D(x)) ~ σ*(y-x) + 0.000000000000135,
8+
D(y) ~ x*-z)-y,
9+
D(z) ~ x*y - β*z]
10+
11+
@named sys = ODESystem(eqs)
12+
sys = ode_order_lowering(sys)
13+
14+
u0 = [D(x) => 2.0,
15+
x => 1.0,
16+
y => 0.0,
17+
z => 0.0]
18+
19+
p ==> 28.0,
20+
ρ => 10.0,
21+
β => 8/3]
22+
23+
tspan = (0.0,100.0)
24+
prob = ODEProblem(sys,u0,tspan,p,jac=true)
25+
26+
break
27+
end
28+
end

0 commit comments

Comments
 (0)