From ce4628482373f701ac32eccecd59589b440f87f4 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sun, 20 Jul 2025 08:53:36 -0400 Subject: [PATCH] generate connection_namemap and is_stochastic if not given to PartitionedGraphSystem --- Project.toml | 2 +- src/graph_system.jl | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index af1b89a..8990f70 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "GraphDynamics" uuid = "bcd5d0fe-e6b7-4ef1-9848-780c183c7f4c" -version = "0.4.6" +version = "0.4.7" [workspace] projects = ["test", "scrap"] diff --git a/src/graph_system.jl b/src/graph_system.jl index 8e88c3f..1178063 100644 --- a/src/graph_system.jl +++ b/src/graph_system.jl @@ -77,18 +77,18 @@ function system_wiring_rule!(g, src, dst; kwargs...) end @kwdef struct PartitionedGraphSystem{CM <: ConnectionMatrices, S, P, EVT, Ns, CONM, SNM, PNM, CNM, EP} - is_stochastic::Bool - graph::GraphSystem = GraphSystem() - flat_graph::GraphSystem = GraphSystem() + graph::Union{Nothing, GraphSystem} = nothing + flat_graph::Union{Nothing, GraphSystem} = nothing connection_matrices::CM states_partitioned::S params_partitioned::P tstops::EVT = Float64[] names_partitioned::Ns - connection_namemap::CONM + connection_namemap::CONM = make_connection_namemape(names_partitioned, connection_matrices) state_namemap::SNM = make_state_namemap(names_partitioned, states_partitioned) param_namemap::PNM = make_param_namemap(names_partitioned, params_partitioned) compu_namemap::CNM = make_compu_namemap(names_partitioned, states_partitioned, params_partitioned) + is_stochastic::Bool=any(v -> any(isstochastic, v), states_partitioned) extra_params::EP = (;) end @@ -266,3 +266,29 @@ function check_no_double_connections(g, conn_key) end end end + +@generated function make_connection_namemape(names_partitioned::NTuple{Len, Any}, + connection_matrices::ConnectionMatrices{NConn}) where {Len, NConn} + quote + connection_namemap = OrderedDict{Symbol, ConnectionIndex}() + @nexprs $Len k -> begin + @nexprs $Len i -> begin + @nexprs $NConn nc -> begin + M = connection_matrices[nc].data[k][i] + if !(M isa NotConnected) + for j ∈ eachindex(names_partitioned) + for (l, conn) ∈ maybe_sparse_enumerate_col(M, j) + name_kl = names_partitioned[k][l] + name_ij = names_partitioned[i][j] + for (prop, name) ∈ pairs(connection_property_namemap(conn, name_kl, name_ij)) + connection_namemap[name] = ConnectionIndex(nc, k, i, l, j, prop) + end + end + end + end + end + end + end + connection_namemap + end +end