Hey, I'm trying to find a programmatic way of runn...
# ask-metaflow
c
Hey, I'm trying to find a programmatic way of running Metaflow using Argo Workflows using NBRunner. I tried the following without success:
Copy code
from metaflow import FlowSpec, step, NBRunner


class HelloFlow(FlowSpec):
    @step
    def start(self):
        self.x = 1
        self.next(self.end)

    @step
    def end(self):
        self.x += 1
        print("Hello world! The value of x is", self.x)


run = NBRunner(HelloFlow).nbrun(decospecs=["argo-workflows"])
• Any idea how to achieve this? • Any idea how to default to using Argo Workflows? Thanks
1
b
Hi, the usage is kinda incorrect, let me give the correct usage in a moment...
Copy code
from metaflow import NBDeployer, FlowSpec, step

class HelloFlow(FlowSpec):
    @step
    def start(self):
        self.x = 1
        self.next(self.end)

    @step
    def end(self):
        self.x += 1
        print("Hello world! The value of x is", self.x)

deployer = NBDeployer(HelloFlow)
then, in the next cell, you could have...
Copy code
deployed_flow = deployer.argo_workflows().create()
df_name = deployed_flow.name # for later use...
triggered_run = deployed_flow.trigger()
then, you can access the
Run
object with:
Copy code
run_obj = triggered_run.run
more details about Run object here: https://docs.metaflow.org/api/client also, since you have already deployed the flow, you can trigger it again as follows:
Copy code
from metaflow import DeployedFlow

df = DeployedFlow.from_deployment(identifier=df_name)
triggered_run = df.trigger()
this is for the use-case when you have already deployed to argo workflows and don't want to call
.create()
again but fetch the already deployed flow and just trigger it again... (eg: from a separate notebook or terminal where you don't have access to the original
deployed_flow
object)
thankyou 1
more details about
Deployer
here: https://docs.metaflow.org/api/deployer