# Modify cylc graph but only in first year

**URL:** <https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312>\
**Category:** Cylc Support\
**Created:** [March 4, 2021, 1:58am UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312 "2021-03-04T01:58:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [March 4, 2021, 1:58am UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312/1 "2021-03-04T01:58:42Z")

</div>

Note that this similar ish to [this](https://cylc.discourse.group/t/include-a-task-in-all-but-the-first-cycle-point/115/2) question.

I’ve got a suite with this graph statement…

```auto
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…

```auto
          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…

```auto
[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!

---

<div class="post-metadata">

**Author:** ![hilary.j.oliver](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/hilary.j.oliver/32/4_2.png) [@hilary.j.oliver](https://cylc.discourse.group/u/hilary.j.oliver)\
**Post date:** [March 4, 2021, 3:31am UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312/2 "2021-03-04T03:31:30Z")

</div>

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):

```ini
[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

---

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [March 5, 2021, 12:25am UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312/3 "2021-03-05T00:25:10Z")

</div>

> [@hilary.j.oliver](#):
>
> Greetings from the Cook Strait Ferry bar 🍻

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…

```auto
[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](https://cylc.discourse.group/t/include-a-task-in-all-but-the-first-cycle-point/115/2) and specifically Oliver Saunders’ [reply](https://cylc.discourse.group/t/include-a-task-in-all-but-the-first-cycle-point/115/3) I think all I need to do is this…

```auto
[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

---

<div class="post-metadata">

**Author:** ![hilary.j.oliver](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/hilary.j.oliver/32/4_2.png) [@hilary.j.oliver](https://cylc.discourse.group/u/hilary.j.oliver)\
**Post date:** [March 9, 2021, 7:33pm UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312/4 "2021-03-09T19:33:17Z")

</div>

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 👍

---

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [March 29, 2021, 8:55am UTC](https://cylc.discourse.group/t/modify-cylc-graph-but-only-in-first-year/312/5 "2021-03-29T08:55:33Z")

</div>

thanks hilary. this solution is working well! cheers, j
