# Optional outputs

**URL:** <https://cylc.discourse.group/t/optional-outputs/650>\
**Category:** Cylc Support\
**Created:** [May 12, 2023, 9:48am UTC](https://cylc.discourse.group/t/optional-outputs/650 "2023-05-12T09:48:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ukmo-ccbunney](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/ukmo-ccbunney/32/251_2.png) [@ukmo-ccbunney](https://cylc.discourse.group/u/ukmo-ccbunney)\
**Post date:** [May 12, 2023, 9:48am UTC](https://cylc.discourse.group/t/optional-outputs/650/1 "2023-05-12T09:48:43Z")

</div>

[cylc 8.1.4]

I am using `?` to set optional output dependencies on a task, but got stuck for a while with the error:

`GraphParseError: Output XXXXX:succeeded can't be both required and optional`

Here’s a simple example of what I was doing:

```auto
[scheduling]
    [[graph]]
        R1 = """
            a => b
            b? | b:expired? => c
        """

```

This produced the above error. I can only get the error to go away if I add `?` to the first dependency, i.e.:

```auto
[scheduling]
   [[graph]]
       R1 = """
           a => b? # <--- why?
           b? | b:expired? => c
       """

```

but I am struggling to understand why I need to do this. This line is surely just setting the dependencies of `b` triggering based on `a`? It is not setting any dependencies on `b`’s output. Is this by design, or a bug? I can’t quite get my head around it!!

The Cylc8 documentation has an example like my code above here: [Scheduling Configuration — Cylc 8.1.4 documentation](https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/scheduling.html#basic-example), copied below for reference:

```auto
foo => bar
bar:fail? => recover
bar? | recover => baz

```

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:** [May 12, 2023, 10:50am UTC](https://cylc.discourse.group/t/optional-outputs/650/2 "2023-05-12T10:50:55Z")

</div>

> [@ukmo-ccbunney](#):
>
> The Cylc8 documentation has an example like my code above here: [Scheduling Configuration — Cylc 8.1.4 documentation](https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/scheduling.html#basic-example), copied below for reference:

Unfortunately that example in the docs is wrong, it fails with the same error as your graph. We’ll fix it!

---

<div class="post-metadata">

**Author:** ![ukmo-ccbunney](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/ukmo-ccbunney/32/251_2.png) [@ukmo-ccbunney](https://cylc.discourse.group/u/ukmo-ccbunney)\
**Post date:** [May 12, 2023, 11:02am UTC](https://cylc.discourse.group/t/optional-outputs/650/3 "2023-05-12T11:02:45Z")

</div>

OK - thanks @hilary.j.oliver .

It wasn’t clear to me from the docs that the first dependency `a => b` needed an optional output on `b`.

I know the docs say that if one graph entry has an dependency on an optional output then it must be declared for all graph entries, but I can’t quite understand what that means in the context of `a => b?`.

`a` will always trigger `b`, regardless of whether it has optional outputs.

Sorry if I am being a bit dim here !!! 😃

---

<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 12, 2023, 11:13am UTC](https://cylc.discourse.group/t/optional-outputs/650/4 "2023-05-12T11:13:36Z")

</div>

Not dim at all, it’s quite a change from Cylc 7!

The arrows (rather obviously) set the dependence of the downstream task on a particular output of the upstream one.

But additionally, in Cylc 8, every appearance of a task in the graph states - whether explicitly or implicitly - the optional or required nature of the relevant task output, and that goes for the downstream task as well.

Every reference to a particular task output has to be marked optional if any are, to avoid ambiguity - so you can look at (say) `b` (or `b?`) anywhere in the graph and instantly see if that its success is required (or optional).

Even if there is nothing downstream of a task, this matters. This (below) says, if `foo` succeeds, trigger `bar`. It also says **both** `foo` and `bar` are required to succeed (if they run at all) in order for the workflow to finish successfully:

```auto
foo => bar 

```

If `foo` fails, `bar` will not trigger, and `foo` will be marked as an incomplete task (that did not complete its required outputs), and the as a result the workflow will stall with a warning rather than shut down as finished if there is nothing else to do.

This (below) also says, if `foo` fails `bar` will not trigger and `foo` will be marked as incomplete. BUT this time, if `foo` succeeds and `bar` runs, success of `bar` is optional (i.e. we expect that sometimes `bar` might fail and that is OK - either it doesn’t matter, or we have another path in the graph to handle the failure) and the workflow can shut down as complete successfully either way:

```auto
foo => bar?

```

I hope that makes a bit more sense?

---

<div class="post-metadata">

**Author:** ![ukmo-ccbunney](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/ukmo-ccbunney/32/251_2.png) [@ukmo-ccbunney](https://cylc.discourse.group/u/ukmo-ccbunney)\
**Post date:** [May 12, 2023, 11:55am UTC](https://cylc.discourse.group/t/optional-outputs/650/6 "2023-05-12T11:55:18Z")

</div>

Thanks @hilary.j.oliver for the detailed explanation.

Yes - I can see how that makes sense now.

The pertinent bit that I was not appreciating is that not having `b` as optional, even when it has no downstream tasks, was implying that `b` could not fail…

I think I have this straight in my head now. Many thanks for taking the time to answer! 🙂

---

<div class="post-metadata">

**Author:** ![MetRonnie](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/metronnie/32/125_2.png) [@MetRonnie](https://cylc.discourse.group/u/MetRonnie)\
**Post date:** [May 15, 2023, 10:09am UTC](https://cylc.discourse.group/t/optional-outputs/650/7 "2023-05-15T10:09:27Z")

</div>

One thing to remember is that `foo => bar` is short for `foo:succeed => bar:succeed`, so Cylc expects `bar` to succeed and therefore failure is not an option, unless you add the question mark to `bar:succeed?`

---

<div class="post-metadata">

**Author:** ![ukmo-ccbunney](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/ukmo-ccbunney/32/251_2.png) [@ukmo-ccbunney](https://cylc.discourse.group/u/ukmo-ccbunney)\
**Post date:** [May 16, 2023, 8:05am UTC](https://cylc.discourse.group/t/optional-outputs/650/8 "2023-05-16T08:05:50Z")

</div>

> [@MetRonnie](#):
>
> failure is not an option

Ha - that’s my take away from this thread! 😀
