Skip to content

Running flows from within flows #2538

@eric-czech

Description

@eric-czech

Are there any fundamental limitations inherent to executing a Flow as a step in a parent Flow? For example:

> cat nested_flow_child.py
from metaflow import FlowSpec, step


class ChildFlow(FlowSpec):
    """A simple child flow that processes some data."""
    
    @step
    def start(self):
        print("Child flow: Processing data...")
        self.result = "processed_data"
        self.next(self.end)
    
    @step
    def end(self):
        print(f"Child flow complete. Result: {self.result}")


if __name__ == "__main__":
    ChildFlow()
> cat nested_flow_parent.py
from metaflow import FlowSpec, step, Runner
from nested_flow_child import ChildFlow

class ParentFlow(FlowSpec):
    """A parent flow that runs the ChildFlow using Runner."""
    
    @step
    def start(self):
        print("Parent flow: Starting...")
        self.next(self.run_child_flow)
    
    @step
    def run_child_flow(self):
        print("Parent flow: Running child flow...")
        
        # Use Runner to execute the child flow
        child_flow_file = __file__.replace('_parent', '_child')
        with Runner(child_flow_file).run() as running:
            # Access the run object and get data from the end step
            run = running.run
            self.child_result = run['end'].task.data.result
        
        print(f"Parent flow: Got result from child: {self.child_result}")
        self.next(self.end)
    
    @step
    def end(self):
        print("Parent flow: Complete!")


if __name__ == "__main__":
    ParentFlow()

This ParentFlow has a single step that runs ChildFlow with Runner, and it appears to execute correctly.

Will this usage likely cause conflicts or problems with many other features though (params, configs, etc.)?

I'm aware of https://docs.metaflow.org/production/event-triggering/flow-events, and I have a good reason for wanting to use this pattern instead. Any advice would be much appreciated, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions