from cosmos.Workflow.models import Workflow from cosmos.lib.ezflow.dag import DAG, add_,split_ from tools import ECHO, CAT #################### # Workflow #################### dag = DAG().sequence_( add_([ ECHO(tags={'word':'hello'}), ECHO(tags={'word':'world'}) ]), split_([('i',[1,2])],CAT) ) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example 1',restart=True) dag.add_to_workflow(WF) WF.run()
from cosmos.Workflow.models import Workflow from cosmos.contrib.ezflow.dag import DAG, Split, Add, Map from tools import ECHO, CAT, WC, FAIL #################### # Workflow #################### dag = ( DAG() |Add| [ ECHO(tags={'word':'hello'}), ECHO(tags={'word':'world'}) ] |Split| ([('i',[1,2])],CAT) |Map| FAIL |Map| WC ) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example Fail') dag.add_to_workflow(WF) WF.run()
series of stages. cosmos.contrib.ezflow.dag.DAG.branch() is the key to branching. """ from cosmos.Workflow.models import Workflow from cosmos.i import DAG import tools #################### # Workflow #################### dag = ( DAG() .add([ tools.ECHO(tags={'word':'hello'}), tools.ECHO(tags={'word':'world'}) ]) .split([('i',[1,2])],tools.CAT) .map(tools.WC) .branch('ECHO') .map(tools.WC,'Extra Independent Word Count') ) # Generate image dag.create_dag_img('/tmp/ex_branch.svg') ################# # Run Workflow ################# WF = Workflow.start('Example Branch',restart=True) dag.add_to_workflow(WF) WF.run()
from cosmos.Workflow.models import Workflow from cosmos.lib.ezflow.dag import DAG, split_,add_,map_,reduce_ from tools import ECHO, CAT, WC, PASTE, Sleep #################### # Workflow #################### dag = DAG().sequence_( add_([ ECHO(tags={'word':'hello'}), ECHO(tags={'word':'world'}) ]), map_(Sleep), split_([('i',[1,2])], CAT), reduce_([], PASTE), map_(WC), ) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example 3',restart=True,delete_intermediates=True) dag.add_to_workflow(WF) WF.run()
This workflow demonstrates branching for when you need something more complicated than a linear step-by-step series of stages. cosmos.lib.ezflow.dag.DAG.branch() is the key to branching. """ from cosmos.Workflow.models import Workflow from cosmos.lib.ezflow.dag import DAG import tools #################### # Workflow #################### dag = (DAG().add([ tools.ECHO(tags={'word': 'hello'}), tools.ECHO(tags={'word': 'world'}) ]).split([('i', [1, 2])], tools.CAT).map(tools.WC).branch('ECHO').map( tools.WC, 'Extra Independent Word Count')) # Generate image dag.create_dag_img('/tmp/ex_branch.svg') ################# # Run Workflow ################# WF = Workflow.start('Example Branch', restart=True) dag.add_to_workflow(WF) WF.run()
from cosmos.Workflow.models import Workflow from cosmos.contrib.ezflow.dag import DAG, split_,add_,map_,reduce_ from tools import ECHO, CAT, WC, PASTE, Sleep #################### # Workflow #################### dag = DAG().sequence_( add_([ ECHO(tags={'word':'hello'}), ECHO(tags={'word':'world'}) ]), map_(Sleep), split_([('i',[1,2])], CAT), reduce_([], PASTE), map_(WC), ) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example 3',restart=True,delete_intermediates=True) dag.add_to_workflow(WF) WF.run()
""" A Simple Workflow """ from cosmos.Workflow.models import Workflow wf = Workflow.start('Simple') stage = wf.add_stage('My Stage') task = stage.add_task('echo "hello world"') wf.run()
from cosmos.Workflow.models import Workflow from cosmos.lib.ezflow.dag import DAG, add_, split_ from tools import ECHO, CAT #################### # Workflow #################### dag = DAG().sequence_( add_([ECHO(tags={'word': 'hello'}), ECHO(tags={'word': 'world'})]), split_([('i', [1, 2])], CAT)) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example 1', restart=True) dag.add_to_workflow(WF) WF.run()
from cosmos.Workflow.models import Workflow from cosmos.lib.ezflow.dag import DAG, Split, Add, Map from tools import ECHO, CAT, WC, FAIL #################### # Workflow #################### dag = (DAG() | Add | [ECHO(tags={'word': 'hello'}), ECHO(tags={'word': 'world'})] | Split | ([('i', [1, 2])], CAT) | Map | FAIL | Map | WC) dag.create_dag_img('/tmp/ex.svg') ################# # Run Workflow ################# WF = Workflow.start('Example Fail') dag.add_to_workflow(WF) WF.run()