It’s pretty easy - here’s a working mock-up based roughly on your requirements above (if I’ve understood them).
Main suite, in ~/suites/main/suite.rc
:
[cylc]
UTC mode = True
[scheduling]
initial cycle point = 2020
[[dependencies]]
[[[P1D]]]
graph = "foo => run-subsuite => bar"
[runtime]
[[foo, bar]]
script = sleep 10
[[run-subsuite]]
script = """
N_RUNS=$((1 + RANDOM % 5)) # determine no. of iterations on the fly
SUBNAME=${CYLC_SUITE_NAME}-sub-${CYLC_TASK_CYCLE_POINT}
cylc register ${SUBNAME} ${CYLC_SUITE_DEF_PATH}/sub
cylc run --no-detach --set="FINAL_CYCLE_POINT=$N_RUNS" ${SUBNAME}
"""
Sub-suite, in ~/suites/main/sub/suite.rc
:
#!Jinja2
[scheduling]
cycling mode = integer
initial cycle point = 1
final cycle point = {{FINAL_CYCLE_POINT}}
[[dependencies]]
[[[P1]]]
graph = "task[-P1] => task => postproc"
[runtime]
[[task, postproc]]
script = sleep 10
Your iterations are handled as integer cycles in the sub-suite. Each sub-suite run is represented by a task in the main-suite, which registers and runs the sub-suite, passing the number of iterations to it as the final cycle point. Run sub-suites with --no-detach
so that the main-suite task does not finish until the sub-suite is done. Multiple sub-suites can run concurrently if the main-suite dependencies allow that.
Note Cylc does not actually have special built-in support for sub-suites; we’re just running one suite inside of a task in another suite. Consequently each running sub-suite appears as (and in fact is) a full suite in its own right. Stopping the main suite will not automatically stop any child sub-suites that are running at the time (however you can monitor and manage them just like any other suite).
If you run this, the suite run directories will look like:
$ ls -lrt cylc-run
total 0
drwxr-xr-x 6 oliverh unix-users 105 May 11 12:17 main
drwxr-xr-x 6 oliverh unix-users 105 May 11 12:17 main-sub-20200101T0000Z
drwxr-xr-x 6 oliverh unix-users 105 May 11 12:18 main-sub-20200102T0000Z
drwxr-xr-x 6 oliverh unix-users 105 May 11 12:18 main-sub-20200103T0000Z
drwxr-xr-x 6 oliverh unix-users 105 May 11 12:18 main-sub-20200104T0000Z
If your main-suite has many cycle points you will probably want to add a housekeeping task (to the main suite) that extracts the important results from finished sub-suites and then deletes their run directories.
Personally I think sub-suites are by far the most elegant way to handle dynamically determined iterative processes in every main suite cycle point - so long as you realize they are actually first-class suites in their own right, and manage them accordingly.
Hilary