Skip to content

Commit

Permalink
example of a branching workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jun 12, 2024
1 parent 0539856 commit 7db7ae5
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions custom_memory_over_time/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
sacct -j "$JOBID" --noheader
done
"""

12 changes: 12 additions & 0 deletions optional-paths/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Demo optional output funtionality

Advanced use cases for optional outputs:
1. Graph Branching - Depending upon the output of a task
the workflow will go down different paths.
2. Pre-finish triggering - A long running task can emit outputs
allowing downstream tasks to start sooner.
n.b. Task messages have been elevated to warning to help you
follow events if you choose to run the workflow on the command line.
---
Written for Cylc Version: 8.x
Tested with Cylc Version: 8.3.0.dev (pre-release copy)
85 changes: 85 additions & 0 deletions optional-paths/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!jinja2
[meta]
title = "Demo optional output funtionality"
description = """
Advanced use cases for optional outputs:
1. Graph Branching - Depending upon the output of a task
the workflow will go down different paths.
2. Pre-finish triggering - A long running task can emit outputs
allowing downstream tasks to start sooner.
n.b. Task messages have been elevated to warning to help you
follow events if you choose to run the workflow on the command line.
"""
written for cylc version = "8.x"
tested with cylc version = "8.3.0.dev (pre-release copy)"

{% from 'cylc.flow' import LOG %}

{% set base_time = 5 if base_time is not defined %}
{% set dice = 3 if dice is not defined %}

{% do LOG.warning("`base_time` (used by sleep as a slow-down factor) is set to: " + base_time.__str__()) %}
{% do LOG.warning("`dice` (used to determine the outcome of multiple_outcomes) has " + dice.__str__() + " sides") %}

[scheduler]
cycle point format = %Y

[scheduling]
initial cycle point = 1000
final cycle point = 1002
[[graph]]
P1Y = """
# Branching execution:
multiple_outcomes:red? => red_task?
multiple_outcomes:green? => green_task?
multiple_outcomes:blue? => blue_task?
multiple_outcomes:black? => black_task?
multiple_outcomes[-P1Y] => multiple_outcomes

# Long running task returns interim messages.
long_task:increment1 => process_increment1
long_task:increment2 => process_increment2
long_task => process_increment3
long_task[-P1Y] => long_task
"""

[runtime]
[[root]]
script = sleep {{base_time}}

[[MULTIPLE_OUTCOMES, INCREMENT_OUTCOMES]]

# Create a families for convenince when viewing.
[[long_task, process_increment1, process_increment2, process_increment3]]
inherit = INCREMENT_OUTCOMES
[[multiple_outcomes, red_task, green_task, blue_task, black_task]]
inherit = MULTIPLE_OUTCOMES

[[multiple_outcomes]]
script = """
for outcome in Gules Vert Azure Sable; do
if [[ $((RANDOM % {{dice}})) == 0 ]]; then
sleep {{base_time}}
cylc message -- "WARNING:${outcome}"
fi
done
"""
[[[outputs]]]
red = Gules
green = Vert
blue = Azure
black = Sable

[[long_task]]
script = """
for counter in 1 2; do
sleep {{base_time}}
cylc message -- "WARNING:Increment ${counter} finished"
done
sleep {{base_time}}
"""
[[[outputs]]]
increment1 = 'Increment 1 finished'
increment2 = 'Increment 2 finished'
2 changes: 1 addition & 1 deletion strange-parameters/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
R1 = filius_bonacci<fib>

# Cicada Tasks only run once every N years, where N is a prime number:
{% for n in prime(10) %}
{% for n in prime(5) %}
R/1983/P{{n}}Y = cicada_{{n}}[-P{{n}}Y] => cicada_{{n}}
{% endfor %}

0 comments on commit 7db7ae5

Please sign in to comment.