pub struct Graph {
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
pub training_strategy: Option<TrainingStrategy>,
}Expand description
A directed graph of computational nodes.
Fields§
§nodes: Vec<Node>The nodes, in insertion order (execution order comes from the edges).
edges: Vec<Edge>The directed edges connecting them.
training_strategy: Option<TrainingStrategy>Training strategy for distributed execution. Inherited by subgraphs unless overridden.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn with_strategy(self, strategy: TrainingStrategy) -> Self
pub fn with_strategy(self, strategy: TrainingStrategy) -> Self
Set the training strategy for this graph.
Sourcepub fn set_strategy(&mut self, strategy: TrainingStrategy)
pub fn set_strategy(&mut self, strategy: TrainingStrategy)
Set the training strategy (mutable).
Sourcepub fn effective_strategy_is_distributed(&self) -> bool
pub fn effective_strategy_is_distributed(&self) -> bool
Whether the effective strategy needs more than this process.
Local does not, and neither does an absent one — which is the
same thing. Everything else asks for workers, so a caller can use
this to decide whether to take the distributed path at all rather
than matching on the enum in three places.
Sourcepub fn effective_strategy(&self) -> &TrainingStrategy
pub fn effective_strategy(&self) -> &TrainingStrategy
Get the effective training strategy (defaults to Local).
Sourcepub fn add_node(&mut self, node: Node)
pub fn add_node(&mut self, node: Node)
Add a node. Duplicate ids are not checked here; Self::validate
rejects them at compile time.
Sourcepub fn add_filter(&mut self, filter_name: impl Into<String>) -> &str
pub fn add_filter(&mut self, filter_name: impl Into<String>) -> &str
Add a filter node using the filter name as the node id. If a node with that name already exists, appends a suffix.
Sourcepub fn add_edge(&mut self, edge: Edge)
pub fn add_edge(&mut self, edge: Edge)
Add an edge. Endpoints are not checked here; Self::validate
rejects edges to unknown nodes at compile time.
Sourcepub fn connect(&mut self, source: impl Into<String>, target: impl Into<String>)
pub fn connect(&mut self, source: impl Into<String>, target: impl Into<String>)
Connect two nodes with a data edge (auto-generates edge id).
Sourcepub fn predecessors(&self, node_id: &str) -> Vec<&str>
pub fn predecessors(&self, node_id: &str) -> Vec<&str>
Get predecessors of a node (nodes with edges pointing to it).
Sourcepub fn successors(&self, node_id: &str) -> Vec<&str>
pub fn successors(&self, node_id: &str) -> Vec<&str>
Get successors of a node (nodes it points to).
Sourcepub fn topological_sort(&self) -> Result<Vec<&str>>
pub fn topological_sort(&self) -> Result<Vec<&str>>
Topological sort using Kahn’s algorithm. Returns Err if the graph contains a cycle.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the graph structure (recursively validates sub-graphs).
Sourcepub fn contains_steps(&self) -> bool
pub fn contains_steps(&self) -> bool
Does this graph — or any sub-graph nested inside it — contain a step?
A step calls models and tools, so a graph that contains one is not a
deterministic function of its input. crate::effect::Effect::is_pure
asks this before memoizing a graph effect by content.
Source§impl Graph
impl Graph
Sourcepub fn to_mermaid(&self) -> String
pub fn to_mermaid(&self) -> String
Render as a Mermaid diagram.
graph LR
scaler[scaler]
model[model]
scaler --> modelSourcepub fn to_mermaid_with(&self, overlay: &GraphOverlay) -> String
pub fn to_mermaid_with(&self, overlay: &GraphOverlay) -> String
Render as a Mermaid diagram with per-node execution annotations.
Each annotated node gets a second label line (duration, cache
tier, health flags — see crate::viz::NodeOverlay::sublabel_text)
and a status classDef for coloring. An empty overlay produces
exactly Graph::to_mermaid’s output.
Sourcepub fn to_graphviz(&self) -> String
pub fn to_graphviz(&self) -> String
Render as Graphviz DOT format.
Sourcepub fn to_graphviz_with(&self, overlay: &GraphOverlay) -> String
pub fn to_graphviz_with(&self, overlay: &GraphOverlay) -> String
Render as Graphviz DOT with per-node execution annotations:
a second label line plus fill/border status colors. An empty
overlay produces exactly Graph::to_graphviz’s output.
Source§impl Graph
impl Graph
Sourcepub fn to_svg_with(&self, overlay: &GraphOverlay) -> String
pub fn to_svg_with(&self, overlay: &GraphOverlay) -> String
Render as a self-contained SVG diagram with per-node execution
annotations (status colors + a duration/cache/flags sublabel),
same overlay semantics as Graph::to_mermaid_with.