Skip to content

Commit 0f64981

Browse files
committed
add precompile workload
1 parent 06ad818 commit 0f64981

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

NetworkDynamicsInspector/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1313
NetworkDynamics = "22e9dc34-2a0d-11e9-0de0-8588d035468b"
1414
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
1515
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
16+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1617
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1718
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
1819

@@ -36,6 +37,7 @@ Graphs = "1.12.0"
3637
NetworkDynamics = "0.9.13"
3738
Observables = "0.5.5"
3839
OrderedCollections = "1.8.0"
40+
PrecompileTools = "1.2.1"
3941
SciMLBase = "2.75.1"
4042
WGLMakie = "0.11"
4143
julia = "1.10"

NetworkDynamicsInspector/src/NetworkDynamicsInspector.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using Colors: Colors, @colorant_str, RGB, color
2424
using ColorSchemes: ColorSchemes, ColorScheme
2525
using SciMLBase: SciMLBase
2626
using Downloads: Downloads
27+
using PrecompileTools: @compile_workload
2728

2829
# defined based on the julia version
2930
using NetworkDynamics: AnnotatedIOBuffer, AnnotatedString, @styled_str
@@ -256,6 +257,34 @@ function element_info_card(app, session)
256257
)
257258
end
258259

259-
260+
@compile_workload begin
261+
using NetworkDynamics: EdgeModel, VertexModel, AntiSymmetric, Network, dim, pdim
262+
using Graphs: complete_graph
263+
Base.@propagate_inbounds function diffusionedge!(e, v_s, v_d, (p,), _)
264+
e .= p * (v_s[1] .- v_d[1])
265+
end
266+
e = EdgeModel(g=AntiSymmetric(diffusionedge!), outdim=1, pdim=1, pdef=[1], name=:diff_edge, indim=1)
267+
Base.@propagate_inbounds function diffusionvertex!(dv, _, acc, _, _)
268+
dv[1] = acc[1]
269+
nothing
270+
end
271+
v = VertexModel(f=diffusionvertex!, dim=1, g=1:1, indim=1)
272+
273+
g = complete_graph(3)
274+
nw = Network(g, v, e)
275+
prob = SciMLBase.ODEProblem(nw, zeros(dim(nw)), (0, 0.1), zeros(pdim(nw)))
276+
277+
t = [0, 0.1]
278+
u = [zeros(dim(nw)) for _ in t]
279+
sol = SciMLBase.build_solution(prob, nothing, t, u)
280+
281+
app = NetworkDynamicsInspector.AppState(sol);
282+
session = Bonito.Session()
283+
NetworkDynamicsInspector.graphplot_card(app, session);
284+
NetworkDynamicsInspector.gpstate_control_card(app, :vertex);
285+
NetworkDynamicsInspector.element_info_card(app, session);
286+
NetworkDynamicsInspector.timeseries_col(app, session);
287+
NetworkDynamicsInspector.clear_obs_and_close!(app);
288+
end
260289

261290
end # module NetworkDynamicsInspector

NetworkDynamicsInspector/src/timeseries.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ function timeseries_card(app, key, session)
401401
@error "$key: Plotting failed for idx $(valid_idxs[])" e
402402
end
403403
end
404-
put!(plotqueue, task)
404+
if !is_precompiling()
405+
put!(plotqueue, task)
406+
end
405407
nothing
406408
end |> track_obsf
407409

@@ -474,7 +476,7 @@ function _plot_queue(key)
474476
rmt = take!(ch) # remove the executed task
475477
@assert istaskdone(rmt)
476478
end
477-
@info "Plot queue for $key closed"
479+
@debug "Plot queue for $key closed"
478480
end
479481
end
480482

NetworkDynamicsInspector/src/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,5 @@ function wait_for(queue)
161161
sleep(0.01)
162162
end
163163
end
164+
165+
is_precompiling() = ccall(:jl_generating_output, Cint, ()) == 1

0 commit comments

Comments
 (0)