metaflow icon indicating copy to clipboard operation
metaflow copied to clipboard

How can I progress `@step` based on some condition?

Open sangwoo-joh opened this issue 1 year ago • 3 comments

For example, the following code seems not working:

class SomeFlow(FlowSpec):
    some_condition = Parameter( ... )

    @step
    def start(self):
        if self.some_condition == ... : 
            self.next(self.a)
        else:
            self.next(self.b)

    @step 
    def a(self): ...

    @step 
    def b(self): ....

How can I do this with metaflow @step?

sangwoo-joh avatar Nov 30 '23 08:11 sangwoo-joh

@sangwoo-joh Conditions are not supported. Found this via Googling "metaflow conditional step": https://github.com/Netflix/metaflow/issues/71

You can easily workaround that by doing something like this:

self.next(self.a, self.b)

And then inside of a and b, check for self.some_condition and act accordingly.

Alternatively, combine the logic of a and b into c and call c instead where you would use an if/then/else to do different things.

Hope that works for you!

maxzheng avatar Dec 07 '23 02:12 maxzheng

what if I want to skip one step based on condition? a --> b --> c

@step
def a(self):
    if condition: 
        self.next(b)
    else:
        self.next(c)

Shuaijun-Gao avatar Jul 23 '24 11:07 Shuaijun-Gao