Skip to content

Commit

Permalink
Bring back xlabel/ticks and legend frame. Added lightbox. Some simpli…
Browse files Browse the repository at this point in the history
…fication.
  • Loading branch information
evetion committed Nov 6, 2024
1 parent 5b2748c commit db0103c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
31 changes: 19 additions & 12 deletions docs/dev/callstacks.qmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
lightbox: auto
---

# Call stacks

```{julia}
Expand Down Expand Up @@ -37,14 +41,12 @@ close(db)
plot_graph(
graph;
size = (2000, 1200),
squash_methods = [
:n_neighbor_bounds_flow,
:n_neighbor_bounds_control,
:sort_by_function,
:neighbortypes
:neighbortypes,
],
xlims = (-0.4, 5.6)
)
```

Expand All @@ -59,7 +61,7 @@ model = Ribasim.Model(toml_path)
du = get_du(model.integrator)
(; u, p, t) = model.integrator
graph, verts = tracecall((Ribasim,), Ribasim.water_balance!, (du, u, p, t))
plot_graph(graph, size = (1700, 1000), xlims = (-0.4, 4.5))
plot_graph(graph; max_depth = 4)
```

## Allocation initialization
Expand All @@ -68,13 +70,16 @@ In this part of the code the data structures for allocation are set up. Most end

```{julia}
# | code-fold: true
toml_path = normpath(@__DIR__, "../../generated_testmodels/main_network_with_subnetworks/ribasim.toml")
config = Ribasim.Config(toml_path; allocation_use_allocation=false)
toml_path = normpath(
@__DIR__,
"../../generated_testmodels/main_network_with_subnetworks/ribasim.toml",
)
config = Ribasim.Config(toml_path; allocation_use_allocation = false)
db_path = Ribasim.database_path(config)
db = SQLite.DB(db_path)
p = Ribasim.Parameters(db, config)
graph, verts = tracecall((Ribasim,), Ribasim.initialize_allocation!, (p, config))
plot_graph(graph, size = (1800, 1000), xlims = (-0.5, 5.5))
plot_graph(graph)
```

## Allocation run
Expand All @@ -86,7 +91,7 @@ Running the allocation algorithm consists of running the optimization itself (wh
# | code-fold: true
model = Ribasim.Model(toml_path)
graph, verts = tracecall((Ribasim,), Ribasim.update_allocation!, (model.integrator,))
plot_graph(graph, size = (2000, 1000), xlims = (-0.4, 5.5))
plot_graph(graph)
```

## Discrete control
Expand All @@ -95,12 +100,14 @@ Discrete control works by a [`FunctionCallingCallback`](https://docs.sciml.ai/Di

```{julia}
# | code-fold: true
toml_path = normpath(@__DIR__, "../../generated_testmodels/pump_discrete_control/ribasim.toml")
toml_path =
normpath(@__DIR__, "../../generated_testmodels/pump_discrete_control/ribasim.toml")
model = Ribasim.Model(toml_path)
(; u, t) = model.integrator
model.integrator.p.basin.storage0 .= [0.1, 100.0]
graph, verts = tracecall((Ribasim,), Ribasim.apply_discrete_control!, (u, t, model.integrator))
plot_graph(graph; size = (1300, 500), prune_from = [:water_balance!], xlims = (-0.5, 3.5))
graph, verts =
tracecall((Ribasim,), Ribasim.apply_discrete_control!, (u, t, model.integrator))
plot_graph(graph; prune_from = [:water_balance!], max_depth = 3)
```

## Writing output
Expand All @@ -111,5 +118,5 @@ Writing output (currently) happens only after the full simulation is finished. F
toml_path = normpath(@__DIR__, "../../generated_testmodels/basic_transient/ribasim.toml")
model = Ribasim.Model(toml_path)
graph, verts = tracecall((Ribasim,), Ribasim.write_results, (model,))
plot_graph(graph, size = (1600, 1000), xlims = (-0.5, 4.5))
plot_graph(graph; max_depth = 4)
```
18 changes: 13 additions & 5 deletions docs/dev/scripts/plot_trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end

function plot_graph(
graph_orig::MetaGraph;
size = (1000, 1000),
size = (2000, 1000),
max_depth::Int = 5,
plot_non_Ribasim::Bool = false,
squash_per_depth::Bool = true,
Expand Down Expand Up @@ -197,9 +197,8 @@ function plot_graph(
plot_edges!(ax, graph, max_depth, nodes_per_depth)
plot_labels!(ax, graph, max_depth, color_dict)
hideydecorations!(ax)
hidexdecorations!(ax)
hidespines!(ax)
!isnothing(xlims) && xlims!(ax, xlims...)
isnothing(xlims) ? xlims!(ax, -0.25, max_depth + 0.5) : xlims!(ax, xlims...)

# Build legend
elements = LegendElement[
Expand All @@ -213,7 +212,16 @@ function plot_graph(
push!(elements, LineElement(; color = :black, linestyle = :solid))
push!(descriptions, "within a script")

Legend(f[1, 2], elements, descriptions)

axislegend(
ax,
elements,
descriptions;
position = :lt,
framevisible = true,
margin = (20, 20, 20, 20),
padding = 10,
framecolor = :lightgrey,
)
resize_to_layout!(f)
f
end

0 comments on commit db0103c

Please sign in to comment.