component_graph (function)
Stable function · Graphs
Tier: stable · Kind: function · Topic: Graphs
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
component_graph | componentGraph | component_graph | component_graph | not exported |
Julia
component_graph(file::EsmFile)
component_graph(file::EsmFile) -> Graph{ComponentNode, CouplingEdge}
Generate component-level graph showing systems and their couplings.
Creates nodes for each model, reaction system, and data source. Operators are
NOT given nodes: a CouplingOperatorApply entry only registers an operator
(the operator lives in the file’s operators section), so it contributes no
node or edge here. Creates edges based on the remaining coupling entries with
appropriate types and labels.
Arguments
file::EsmFile: Input ESM file
Returns
Graph{ComponentNode, CouplingEdge}: Component graph with coupling relationships
Example
graph = component_graph(file)
# Access nodes and edges
for node in graph.nodes
println("Component: $(node.name) ($(node.type))")
end
for edge in graph.edges
println("Coupling: $(edge.from) --[$(edge.label)]--> $(edge.to)")
end
Example (component_graph)
graph = component_graph(doc)
@assert [n.name for n in graph.nodes] == ["Heater", "Box"]
mermaid = to_mermaid(graph)
println(mermaid)
@assert occursin("Heater -.->|\"T\"| Box", mermaid)
@assert startswith(to_dot(graph), "digraph")
TypeScript
function componentGraph(file: EsmFile): Graph<ComponentNode, CouplingEdge>
Extract the system graph from an ESM file. Returns a directed graph (ESM Libraries Specification §4.8) where nodes are model components and edges are coupling rules, with adjacency helpers.
Example (component_graph)
const doc = loadPath(fixture('coupled.esm'))
const graph = componentGraph(doc)
assert.deepEqual(graph.nodes.map((n) => n.id), ['Heater', 'Box'])
assert.deepEqual(graph.successors('Heater'), ['Box'])
const [edge] = graph.edges
assert.equal(edge.data.type, 'variable_map')
// Render for a Markdown page or for Graphviz.
const mermaid = toMermaid(graph)
assert.match(mermaid, /Heater -\.->\|T\| Box/)
assert.match(toDot(graph), /"Heater" -> "Box"/)
Python
component_graph(file: EsmFile) -> Graph[ComponentNode, CouplingEdge]
Build the component/coupling graph of file.
Nodes are the file’s models and reaction systems. Edges come from the coupling entries that name two DECLARED components:
operator_composeandcouple— a singlesystems[0] → systems[1]edge (every binding records one directed edge, not a pair);variable_map— an edge between the two endpoints’ owning components, labelled with the source variable.
operator_apply, callback, event and coupling_import name no
two concrete components and contribute no edge, as in every binding. An
endpoint that is not a declared node is skipped rather than fabricated.
Rust
pub fn component_graph(esm_file: &EsmFile) -> ComponentGraph
Build a component graph from an ESM file
Arguments
esm_file- The ESM file to analyze
Returns
- Component graph showing structure and coupling
Example (component_graph)
let doc = load_path(fixture("coupled.esm"))?;
let graph = component_graph(&doc);
let ids: Vec<&str> = graph.nodes.iter().map(|n| n.id.as_str()).collect();
assert_eq!(ids, ["Box", "Heater"]);
assert_eq!(graph.edges.len(), 1);
assert_eq!((graph.edges[0].from.as_str(), graph.edges[0].to.as_str()), ("Heater", "Box"));
let dot = to_dot(&graph);
assert!(dot.starts_with("digraph"));
assert!(to_mermaid(&graph).contains("Heater"));
Go
Go does not export this function.