Pass command line environment variable to suite's rose-app.conf file

Hiya

I have a data analysis suite with multiple lines like this…

enabled = true

The thing is that I want to run each instance of this as a separate suite because they’re so slow to run.

Can I pass arguments from the command line to a ~/roses/[suite]/app/[my app]/rose-app.conf using something like this?..

> myvar=true

… and then in the rose-app.conf

enabled=$(myvar)

Thanks for any ideas!

Cheers

Jonny

Hello,

If I understand your question correctly you can pass environment variables from a Cylc suite to a Rose application easily by doing this:

suite.rc

[runtime]
    [[mytask]]
        script = rose task-run
        [[[environment]]]
            MY_VARIABLE=foo

app/mytask/rose-app.conf

[command]
default=echo $MY_VARIABLE

You can also derive variables in your Rose Application like this:

app/mytask/rose-app.conf

[command]
default = echo $ANOTHER_VARIABLE

[env]
ANOTHER_VARIABLE=a/b/$MY_VARIABLE/c

Thanks a lot for that; that’s definitely an option. What I’d really like to do is to be able to pass variables from the command line; i.e. where I run rose suite-run from. Is that possible?

Thanks again

Jonny

What I’d really like to do is to be able to pass variables from the command line; i.e. where I run rose suite-run from. Is that possible?

Sure, Rose/Cylc support passing through Jinja2 variables from the command line.

suite.rc

#!Jinja2
[runtime]
    [[mytask]]
        script = rose task-run
        [[[environment]]]
            # translate jinja2 variable into environment variable
            MY_VARIABLE={{ MY_VARIABLE }}
# the rose way
$ rose suite-run -S 'MY_VARIABLE=42'  # note capital 'S'
# the cylc way
$ cylc run -s 'MY_VARIABLE=42'  # note lower 's'

Note you can define default values in your suite configuration file which you can (optionally) override on the command line using -S:

rose-suite.conf

[jinja2:suite.rc]
MY_VARIABLE=42

Note: If you are overriding variables often you many want to group commonly used options into files which you can turn on or off. Rose provides a mechanism for doing this called optional configurations, these work for suite and application configurations. See also the related ROSE_APP_OPT_CONF_KEYS and ROSE_SUITE_OPT_CONF_KEYS environment variables.

3 Likes

Thanks a lot for this. Apols for not replying sooner, I didn’t get a notification… Well, not one that I saw! :slight_smile:

Ngaa mihi

Jonny