Parameter templates and scripts

Trying to build a suite.rc for an ensemble of runs, in the cylc section I have:
[cylc]
[[parameters]]
member = 1…6
[[parameter templates]]
casename = kensemble.%(member)03d
caseroot = /home/jedwards/scratch/kensemble.%(member)03d

and in the runtime section:
[[st_archive]]
script = cd %(caseroot)s; ./case.submit --job case.st_archive; ./xmlchange CONTINUE_RUN=TRUE

but this results in an error because %(caseroot)s is not expanded.
So then I tried:

[runtime]
[[set_external_workflow]]
script = cd $MYDIR; ./xmlchange EXTERNAL_WORKFLOW=TRUE
[[[parameter environment templates]]]
MYDIR = %(caseroot)s

But this results in a validation error:
ERROR - bad parameter environment template:
[set_external_workflow]MYDIR=%(caseroot)s # bad parameter
Illegal parameter environment template(s) detected

How can I start each member in the correct directory?

I found in the rose tutorial:
{CYLC_TASK_PARAM_member} which is an environment variable with the correct value so I can do: cd /home/jedwards/scratch/kensemble.(printf “%03d” ${CYLC_TASK_PARAM_member})

but this doesn’t seem to work for [[parameter templates]] only for [[parameters]]
I would also like to expand a variable in the [[directives]] section.

Hi Jim,

Firstly, for context, the ‘parameter templates’ did not work because script settings have values which are translated to bash logic & parameters cannot be used directly there, only for non-scripting configuration.

Using ‘parameter environment templates’ is the right way to go, but I think the issue here (assuming you have ‘1..6’ in your actual suite definition rather than ‘1…6’ as you have typed here, as that contains an ellipsis unicode character which would invalidate the suite & could propagate down to cause the error you are seeing instead) is that you are setting your parameter environment templates to be equal to the parameter templates. These will be parsed separately, so that the PETs does not know about the PTs.

If you set your PET directly, i.e:

[[[parameter environment templates]]]
MYDIR = /home/jedwards/scratch/kensemble.%(member)03d

then it should get expanded as you desire from that environment variable in your script.

Hope that helps.

Hi Jim,

To add a bit to @sadie.bartholomew’s reply - I think (from your first example, at least) you might have misunderstood the purpose of suite parameters. They are only for parameterizing task names - i.e. to create a whole bunch of tasks from a single template. As such, during suite parsing, parameters are only detected and expanded where task names are expected - not universally. If you want a universal templating system, use Jinja2 (however, if all you want to do is parameterize tasks, then our built-in parameters are cleaner and easier). For convenience, we allow you define (in [parameter templates]) how the templates are expanded - but these should not look like directory paths, as they are expanded in task names. And additionally (also for convenience) the [parameter environment templates] section does let you define environment variables for task jobs by expanding the same parameters (this is the one exception to my point about expansion in task names only) - which is easier than using the automatically defined $CYLC_TASK_PARAM_… variables in your job scripting.

It may be worth playing around with a small example suite, to see exactly how parameters work (but just ask if it still isn’t clear!)

Regards,
Hilary

1 Like

I think that I have it mostly figured out, but I’m still stuck trying to generate unique names for
the batch queueing system:
[[[directives]]]
-N = run.$CASEKEY
doesn’t pick up the environment variable
-N = run.%(member)03d
also doesn’t expand. This turns out to be a pretty important variable when you are running a large ensemble suite and need to know which member is associated with a given batch job.

Actually you never need to set the batch system job name, Cylc automatically sets it for you based on the unique task name (in the PBS case, our pbs.py module automatically sets the -N directive). For parameterized tasks, the task name is includes the expanded parameters - so you should be good to go now!

Hilary

Ahh - I just need to remove the -N and let cylc do it. Thanks!