import pygraphsp as gs
def main():
print("=== Graph-SP Python Example: Branching ===\n")
print("Example 1: Creating Branches")
print("-----------------------------")
graph = gs.Graph()
graph.create_branch("experiment_a")
graph.create_branch("experiment_b")
print(f"✓ Created branches: {graph.branch_names()}")
print(f"✓ Has 'experiment_a': {graph.has_branch('experiment_a')}")
print(f"✓ Has 'experiment_b': {graph.has_branch('experiment_b')}")
print(f"✓ Has 'nonexistent': {graph.has_branch('nonexistent')}")
print()
print("Example 2: Main Graph vs Branches")
print("----------------------------------")
graph2 = gs.Graph()
def main_fn(inputs):
return {"output": "main graph result"}
graph2.add(
main_fn,
label="Main Node",
outputs=["output"]
)
graph2.create_branch("branch_a")
graph2.create_branch("branch_b")
print(f"✓ Main graph has {graph2.node_count()} node")
print(f"✓ Created {len(graph2.branch_names())} branches")
print(f"✓ Branches: {graph2.branch_names()}")
print()
print("Example 3: Practical Use Cases")
print("-------------------------------")
print("Branches can be used for:")
print(" • A/B testing different algorithms")
print(" • Parallel experimentation")
print(" • Organizing complex workflows")
print(" • Creating variant configurations")
print()
print("=== Summary ===")
print("✓ Branch creation and management demonstrated")
print("✓ Python bindings support basic branch operations")
print("\nNote: Full merge and variant features are available in Rust API")
print(" and will be added to Python API in future updates.")
if __name__ == "__main__":
main()