pub struct Graph { /* private fields */ }Expand description
The main graph structure representing a DAG
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn with_strict_edges() -> Self
pub fn with_strict_edges() -> Self
Create a new graph with strict edge mapping enabled When enabled, edges must be explicitly added with add_edge() When disabled (default), edges are automatically created based on node order
Sourcepub fn set_strict_edge_mapping(&mut self, strict: bool)
pub fn set_strict_edge_mapping(&mut self, strict: bool)
Set strict edge mapping mode
Sourcepub fn add_node(&mut self, node: Node) -> Result<()>
👎Deprecated since 0.2.0: Use add instead
pub fn add_node(&mut self, node: Node) -> Result<()>
add insteadAlias for add() for backward compatibility
Sourcepub fn get_node_mut(&mut self, node_id: &str) -> Result<&mut Node>
pub fn get_node_mut(&mut self, node_id: &str) -> Result<&mut Node>
Get a mutable reference to a node by ID
Sourcepub fn topological_order(&self) -> Result<Vec<NodeId>>
pub fn topological_order(&self) -> Result<Vec<NodeId>>
Get a topological ordering of the nodes
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges
Sourcepub fn incoming_edges(&self, node_id: &str) -> Result<Vec<&Edge>>
pub fn incoming_edges(&self, node_id: &str) -> Result<Vec<&Edge>>
Get incoming edges for a node
Sourcepub fn outgoing_edges(&self, node_id: &str) -> Result<Vec<&Edge>>
pub fn outgoing_edges(&self, node_id: &str) -> Result<Vec<&Edge>>
Get outgoing edges for a node
Sourcepub fn auto_connect(&mut self) -> Result<usize>
pub fn auto_connect(&mut self) -> Result<usize>
Automatically connect nodes based on matching port names This enables implicit edge mapping without explicit add_edge() calls
§Matching Strategy
- Connects output ports to input ports with the same name
- Only creates edges if the port names match exactly
- Respects topological ordering to avoid cycles
§Returns
The number of edges created
Sourcepub fn with_auto_connect(self) -> Result<Self>
pub fn with_auto_connect(self) -> Result<Self>
Build a graph with strict mode disabled - uses implicit edge mapping This is a convenience method that calls auto_connect() after all nodes are added
Sourcepub fn create_branch(&mut self, name: impl Into<String>) -> Result<&mut Graph>
pub fn create_branch(&mut self, name: impl Into<String>) -> Result<&mut Graph>
Create a new branch (subgraph) with the given name
Sourcepub fn get_branch(&self, name: &str) -> Result<&Graph>
pub fn get_branch(&self, name: &str) -> Result<&Graph>
Get a reference to a branch by name
Sourcepub fn get_branch_mut(&mut self, name: &str) -> Result<&mut Graph>
pub fn get_branch_mut(&mut self, name: &str) -> Result<&mut Graph>
Get a mutable reference to a branch by name
Sourcepub fn branch_names(&self) -> Vec<String>
pub fn branch_names(&self) -> Vec<String>
Get all branch names
Sourcepub fn has_branch(&self, name: &str) -> bool
pub fn has_branch(&self, name: &str) -> bool
Check if a branch exists
Sourcepub fn merge(
&mut self,
node_id: impl Into<NodeId>,
config: MergeConfig,
) -> Result<()>
pub fn merge( &mut self, node_id: impl Into<NodeId>, config: MergeConfig, ) -> Result<()>
Create a merge node that combines outputs from multiple branches
The merge node will collect outputs from the specified branches and combine them using the provided merge function (or collect into a list by default).
Sourcepub fn create_variants(&mut self, config: VariantConfig) -> Result<Vec<String>>
pub fn create_variants(&mut self, config: VariantConfig) -> Result<Vec<String>>
Create variant branches for config sweeps
This creates multiple isolated branches, each with a different parameter value. Variants can be used for hyperparameter sweeps, A/B testing, or any scenario where you want to run the same computation with different inputs.
Returns the names of the created variant branches.