Skip to content

Commit a43e9d2

Browse files
authored
Merge pull request #186 from SciML/precompile
Copy of "Add precompilation"
2 parents e8eafcc + 4a481b2 commit a43e9d2

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1515
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1616
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1717
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
18+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1819
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
1920
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2021
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
@@ -29,6 +30,7 @@ IterTools = "1"
2930
MacroTools = "0.5"
3031
ModelingToolkit = "7, 8"
3132
Nemo = "0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
33+
PrecompileTools = "1"
3234
Primes = "0.5"
3335
SpecialFunctions = "1, 2"
3436
SymbolicUtils = "1"

src/ODE.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,13 @@ macro ODEmodel(ex::Expr...)
387387
)
388388
end
389389
end
390-
@info "Summary of the model:"
391-
@info "State variables: " * join(map(string, collect(x_vars)), ", ")
392-
@info "Parameters: " * join(map(string, collect(params)), ", ")
393-
@info "Inputs: " * join(map(string, collect(u_vars)), ", ")
394-
@info "Outputs: " * join(map(string, collect(y_vars)), ", ")
390+
logging_exprs = [
391+
:(@info "Summary of the model:"),
392+
:(@info "State variables: " * $(join(map(string, collect(x_vars)), ", "))),
393+
:(@info "Parameters: " * $(join(map(string, collect(params)), ", "))),
394+
:(@info "Inputs: " * $(join(map(string, collect(u_vars)), ", "))),
395+
:(@info "Outputs: " * $(join(map(string, collect(y_vars)), ", "))),
396+
]
395397

396398
# creating the ode object
397399
ode_expr = :(ODE{StructuralIdentifiability.Nemo.fmpq_mpoly}(
@@ -402,6 +404,7 @@ macro ODEmodel(ex::Expr...)
402404

403405
result = Expr(
404406
:block,
407+
logging_exprs...,
405408
exp_ring,
406409
assignments...,
407410
x_dict_create_expr,

src/StructuralIdentifiability.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,7 @@ function assess_identifiability(
188188
return out_dict
189189
end
190190

191+
using PrecompileTools
192+
include("precompile.jl")
193+
191194
end

src/precompile.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
@setup_workload begin
3+
# Putting some things in `@setup_workload` instead of `@compile_workload` can reduce the size of the
4+
# precompile file and potentially make loading faster.
5+
using Logging
6+
using ModelingToolkit
7+
@parameters a01 a21 a12
8+
@variables t x0(t) x1(t) y(t)
9+
D = Differential(t)
10+
eqs = [D(x0) ~ -(a01 + a21) * x0 + a12 * x1, D(x1) ~ a21 * x0 - a12 * x1]
11+
de = ODESystem(eqs, t, name = :Test)
12+
@compile_workload begin
13+
# all calls in this block will be precompiled, regardless of whether
14+
# they belong to your package or not (on Julia 1.8 and higher)
15+
with_logger(ConsoleLogger(stdout, Logging.Warn)) do
16+
ode = @ODEmodel(
17+
x1'(t) = -(a01 + a21) * x1(t) + a12 * x2(t) + u(t),
18+
x2'(t) = a21 * x1(t) - a12 * x2(t) - x3(t) / b,
19+
x3'(t) = x3(t),
20+
y(t) = x2(t)
21+
)
22+
assess_identifiability(ode)
23+
assess_identifiability(de; measured_quantities = [x0])
24+
assess_identifiability(de; measured_quantities = [y ~ x0])
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)