Note that this similar ish to this question.
I’ve got a suite with this graph statement…
postproc{{ '_atmos' if SPLIT_PP else '' }}[-{{FMT}}] => retrieve_ozone => redistribute_ozone => coupled & rose_arch_ozone
… however I need the *ozone tasks to be ignored in the first year (1850), where 1 year may be multiple cycle points.
I’ve tried this…
THISYEAR = $(rose date -c -f %Y)
graph = """
{% if THISYEAR == 1850 %}
postproc{{ '_atmos' if SPLIT_PP else '' }}[-{{FMT}}] => coupled
{%else%}
postproc{{ '_atmos' if SPLIT_PP else '' }}[-{{FMT}}] => retrieve_ozone => redistribute_ozone => coupled & rose_arch_ozone
{% endif%}
"""
… but I get this error…
[FAIL] Jinja2Error:
[FAIL] File "/home/williamsjh/cylc-run/u-cb503/site/niwa_cray.rc", line 292, in top-level template code
[FAIL] {% if THISYEAR == 1850 %}
[FAIL] UndefinedError: 'THISYEAR' is undefined
Any ideas how to implement this?
Thanks!
Hi Jonny,
Greetings from the Cook Strait Ferry bar
Firstly, the Jinja2 UndefinedError
is because you didn’t define THISYEAR
as a Jinja2 variable. All Jinja2 code has to be enclosed in the appropriate curly braces, e.g.: {% set AUSPICIOUS_YEAR = 1969 %}
.
Secondly, however, if I understand your problem, you want the graph structure to change 1 year into the workflow. You can’t use Jinja2 to achieve that because Jinja2 is a template processor that we use to programmatically generate the workflow configuration before the scheduler starts up (the template is the suite.rc
file with embedded Jinja2 code; the result is plain suite.rc
syntax generated by processing the template with Jinja2). So JInja2 never sees “the current cycle point” for a task - that is a runtime concept.
Instead, use Cylc’s cycling graph syntax to generate a graph that is different in the first year. E.g. (you can run this to see how it works):
[cylc]
cycle point format = %Y%m%d
[scheduling]
initial cycle point = 1850
[[dependencies]]
[[[R/^/P1M]]]
# Run cheese every month from initial cycle point...
graph = cheese
[[[R/^+P1Y/P1M]]]
# ...but after the first year, make cheese wait on toast.
graph = toast => cheese
[runtime]
[[root]]
script = sleep 10
Hilary
1 Like
nice
Thanks a lot for the info, very helpful.
I’ve subsequently realised that (I think) the solution should be even simpler than this.
This is the bit of the site
file which I have inherited…
[scheduling]
[[dependencies]]
[[[ 0101T/P1Y ]]]
graph = """
postproc{{ '_atmos' if SPLIT_PP else '' }}[-{{FMT}}] => retrieve_ozone => redistribute_ozone => coupled & rose_arch_ozone
"""
So this modifies the graph in the suite.rc
only on cycle points that start on January 1st. In this suite the resubmission period is 3 months.
Referring back to the other ticket and specifically Oliver Saunders’ reply I think all I need to do is this…
[scheduling]
[[dependencies]]
[[[ 0101T/P1Y!^ ]]]
graph = """
postproc{{ '_atmos' if SPLIT_PP else '' }}[-{{FMT}}] => retrieve_ozone => redistribute_ozone => coupled & rose_arch_ozone
"""
… where !
is ‘not equal to’ and ^
is the first cycle point.
Let me know if you disagree!
Cheers
Jonny
Yep, that’s another way to do it. !^
excludes only the initial point, but that graph section only applies at the start of each year, so
1 Like
thanks hilary. this solution is working well! cheers, j