# Xtrigger suite\_state function usage

**URL:** <https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219>\
**Category:** Cylc Support\
**Created:** [March 24, 2020, 9:31pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219 "2020-03-24T21:31:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [March 24, 2020, 9:31pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/1 "2020-03-24T21:31:14Z")

</div>

Can I use the suite\_state xtrigger without a message? I have been trying the example in 12.2 in the documentation. As far as I can tell, the cylc message and the output, x, need to be the same as the message in suite\_state for it to work. I tried setting the message to None but it didn’t succeed in this case. How can I get it to trigger just on the successful completion of the task?

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [March 24, 2020, 10:36pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/2 "2020-03-24T22:36:03Z")

</div>

By removing the message variable I managed to make this work but when I had ‘message=None’ or ‘message=none’ in the suite\_state function it didn’t work…

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [March 25, 2020, 1:47am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/3 "2020-03-25T01:47:36Z")

</div>

Another question about suite\_state usage. I am trying to pass some environment variables into it. i.e  
suite\_state(suite = {SUITE\_NAME}, task = {TASK\_NAME}… etc  
But these do not seem to be being evaluated - i.e. the downstream task waits indefinitely and when I look at the prerequisites the environment variables have not been evaluated and are there as ${SUITE\_NAME} etc. What is the best way to past environment variables (I could do Jinja too…) to the function?

---

<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 29, 2020, 10:32pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/4 "2020-03-29T22:32:45Z")

</div>

Hi Emily,

Sorry for missing these questions last week (I think many of us were adjusting to the new “locked down” reality).

Your questions are good ones, I can see we need to document this functionality more clearly (sorry again!). I’ll try to explain. Feel free to ask more if it’s still not clear.

The “suite state function signature” shown in the user guide is the actual Python function definition signature. Arguments like `offset=None` default to None (not defined) if you don’t pass anything in for them. However, what’s probably not clear is the difference between passing arguments to the function from within a Python program, and from the Cylc suite configuration file. In the latter case, the Cylc file parser extracts the argument strings, without any knowledge of Python, from the function signature in your suite.rc, and passes them verbatim to the underlying Python function. The “no knowledge of Python” bit means that if you put `message=None` in your functional call signature it will be interpreted literally as the string “None” not the Python value `None`. We will document this better!

Relevant to other parts of your questions:

- You can’t use shell environment variables for task name etc. in these function arguments because the shell never sees any of this. The suite.rc file is a configuration file parsed by the Python Cylc scheduler program, which calls the `suite_state` Python function with the arguments you listed. (Environment variables like `$CYLC_TASK_NAME` are written to Cylc-defined to task job scripts, but that’s because jobs are executed as shell scripts).
- Jinja2 can be used anywhere throughout the suite config file, but it is only a preprocessor, used at start-up before the suite starts running, so you can’t pass dynamic information like a particular task name or cycle point in that way. Jinja2 is really a way to programmatically construct the static suite configuration used to initialized the scheduler.

Long story short,

- to trigger off of upstream task success only do not use the `message` argument at all (that is for custom output messages), just use `status=succeeded`.
- for the upstream suite and task name use a literal string (the actual names)
- if the upstream cycle point is related to the cycle point of the dependent task in your suite (presumably it is) use Python-like string templating as described (but not well enough!) in the user guide: `%(point)s` gets replaced with the cycle point of the dependent task. And `offset=PT6H` (say) if the upstream cycle point is offset from the local dependent task’s cycle point.

All of the available string templates are described a little lower down in the user guide chapter, under “custom xtrigger functions”: [https://cylc.github.io/doc/built-sphinx-single/index.html#custom-trigger-functions](https://cylc.github.io/doc/built-sphinx-single/index.html#custom-trigger-functions) (in the current user guide). However, note that they all refer to values in the suite that calls the the xtrigger function. So in the `suite_state` (inter-suite triggering) case, they are the downstream (dependent) suite values, and the only relevant template argument for that xtrigger function is `%(point)s`.

Hilary

---

<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 30, 2020, 12:27am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/5 "2020-03-30T00:27:46Z")

</div>

> [@hilary.j.oliver](#):
>
> for the upstream suite and task name use a literal string (the actual names)

(Or Jinja2 variables that contain those static names, if you like).

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [May 7, 2020, 3:42am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/6 "2020-05-07T03:42:38Z")

</div>

Another question about suite\_state function usage:  
One of the suites that I want to use the xtrigger to poll off has a different format for the cycle\_point\_format than the downstream suite (and indeed other suites that I am polling). Can I redefine this format (or make a new string template like %(point)s ) to feed in the cycle point in the correct format? How would I do this?

---

<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:** [May 8, 2020, 12:00am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/7 "2020-05-08T00:00:17Z")

</div>

Hi @EmilyLane,

The cycle point should be converted automatically to the format used by the target suite (the target suite database, which the xtrigger function looks at, knows the format). So it should just work - have you tried it and found a problem?

Hilary

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [May 8, 2020, 2:25am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/8 "2020-05-08T02:25:32Z")

</div>

What seems to be the problem is if I specify the cycle point format under [cylc]. If I do that then %(point)s seems to be hardwired to that one. When I comment it out it doesn’t matter that there is a difference in the format.

The upstream suite has the format %y%m%dT%h%MZ for the cycle point

The following hangs indefinitely:

* * *

[cylc]  
cycle point format = %Y%m%dT%H%M  
[scheduling]  
initial cycle point = 20200505T0300  
final cycle point = 20200507T0300  
[[xtriggers]]  
upstream = suite\_state(suite=u-ak198, task=fcst\_done, point=%(point)s, cylc\_run\_dir=/home/mooresa/cylc-run):PT10S  
[[dependencies]]  
[[[PT12H]]]  
graph = “”"  
@upstream =\> blam  
“”"  
[runtime]  
[[root]]  
script = sleep 5  
[[blam]]  
script = “”" echo Triggered “”"

* * *

Whereas if you delete the cycle point format line or change it to be consistent with the upstream format it works  
Not sure if this is what it is supposed to do or not…

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [May 8, 2020, 3:07am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/9 "2020-05-08T03:07:47Z")

</div>

Actually I think I might have found the problem. The upstream suite didn’t specify a cycle point format explicitly. In this case it seems to revert to the format of the downstream suite.

---

<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:** [May 9, 2020, 8:13am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/10 "2020-05-09T08:13:38Z")

</div>

Hi Emily,

You’re right, I’ve just confirmed that the cycle point format conversion is only done if the upstream suite sets its explicitly.

Thanks for the excellent detective work and bug report!

Do you have control over the upstream suite (so that you can change it to set the format)?

Hilary

---

<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:** [May 9, 2020, 8:25am UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/11 "2020-05-09T08:25:22Z")

</div>

New issue posted to track the fix: [https://github.com/cylc/cylc-flow/issues/3600](https://github.com/cylc/cylc-flow/issues/3600)

---

<div class="post-metadata">

**Author:** ![EmilyLane](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@EmilyLane](https://cylc.discourse.group/u/EmilyLane)\
**Post date:** [May 10, 2020, 9:07pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/12 "2020-05-10T21:07:55Z")

</div>

No but Stuart Moore, who owns that suite, changed it for me; so all good.

---

<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:** [May 11, 2020, 10:58pm UTC](https://cylc.discourse.group/t/xtrigger-suite-state-function-usage/219/13 "2020-05-11T22:58:57Z")

</div>

(Fix merged for next release).
