question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

conditional evaluation of nodes / sub-pipelines

See original GitHub issue

Description

Is there a way to declare a pipeline that contains nodes (sub-pipelines) that are only evaluated based on the value of a predicate?

Context

Possible Implementation

Here’s conceptually what I would like to achieve:

node_if executes pipeline_a if the predicate is true and pipeline_b otherwise.

def condition(val):
    return val < 10


def do_a1(val):
    return f"a1-{val}"

def do_a2(val):
    return f"a2-{val}"


def do_b(val):
    return f"b-{val}"

pipeline_a = Pipeline([
    node(func=do_a1, inputs=['val'], outputs='val_a1', name='do_a1'),
    node(func=do_a2, inputs=['val_a1'], outputs='val_a2', name='do_a2')
])

pipeline_b = Pipeline([
    node(func=do_b, inputs=['val'], outputs='val_b', name='do_b'),
])

pipeline = Pipeline([
    node_if(func=condition, inputs=['val'], branch_true=pipeline_a, branch_false=pipeline_b),
])

Possible Alternatives

(Optional) Describe any alternative solutions or features you’ve considered.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lorenabalancommented, Oct 9, 2019

Hi @khdlim, thank you for sharing your experience, this is invaluable feedback!! Please see my inline responses, hoping they make sense to you. Feel free to reach out otherwise!

kedro-viz only allows to use /conf/base without an --env option, but that’s a separate issue

That’s a good point and I believe it has been raised before. We’re in the process of rethinking and improving the experience of KedroContext / ProjectContext and we’ll be sure to include this type of arguments in the discussion.

but I was wondering if the user was not designed to pass arguments to create_pipeline to begin with.

That is the right question to ask. If you look at the architecture diagram you can see that Pipeline and DataCatalog don’t know about each other. You do have access to the catalog inside create_pipeline, as it’s a property on the KedroContext class. While you can access it to get some information, we don’t recommend mutating it - weird things might happen as a result.

I also saw you mention in another post that separate pipelines would be available soon, that would be a godsend

You are in luck! We released version 0.15.2 yesterday, fetch it while it’s hot. 😃 You can check out a summary of the introduced changes here.

0reactions
lorenabalancommented, Oct 11, 2019

I am closing this issue as answered, but please feel free to open a new one if there’s a need for further clarification. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

conditional evaluation of nodes / sub-pipelines #104 - GitHub
Is there a way to declare a pipeline that contains nodes (sub-pipelines) that are only evaluated based on the value of a predicate?...
Read more >
Adding conditions to the pipeline - IBM
Condition Response checks a condition on the status of the previous node. Simple condition is a no-code condition in the form of an...
Read more >
Comparing Pipelines and SGJC Controllers
For example, if your subpipeline start node is named 1start, you must rename it before overriding it with a controller method, because the...
Read more >
XProc: An XML Pipeline Language - W3C
It's possible for steps in a partially evaluated pipeline to have side effects that are visible outside the processor, even if the final...
Read more >
XProc 3.0+: An XML Pipeline Language
A pipeline must behave as if it evaluated each step each time it ... If the item is a document node, content-type "application/xml"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found