Page MenuHomePhabricator

model input selection example

Authored by alangenfeld on Oct 28 2019, 3:45 PM.
def test_toggle_pipeline():
def generate_a():
return ['A']
def generate_b():
return ['B']
def concat(a, b):
return a + b
# To mirror the approach you had, we introduce a "mux" solid that
# is responsible for choosing which input to forward based on config.
@solid(config={'selected': Field(String)})
def input_mux(context, a, b, merged):
selected = context.solid_config['selected']
if selected == 'a':
return a
elif selected == 'b':
return b
return merged
def map_to_mux(_ctx, cfg):
return {'input_mux': {'config': {'selected': cfg['selected']}}}
# We wrap all the input generation and selection in a composite to attempt to hide this complexity.
# We use the config mapping ability to make it so we dont have to provide
# config for a nested solid. This allows the composite to actually "hide"
# complexity of the choosing process.
config={'selected': Field(String)},
def generate_input():
a = generate_a()
b = generate_b()
return input_mux(a, b, concat(a, b))
def do_stuff(selected_in):
return len(selected_in)
def selective_pipeline():
# A simpler example but you get the gist
# execute a few different selections
environment_dict={'solids': {'generate_input': {'config': {'selected': 'a'}}}},
environment_dict={'solids': {'generate_input': {'config': {'selected': 'b'}}}},

Event Timeline

alangenfeld created this object with visibility "Public (No Login Required)".
alangenfeld edited the content of this paste. (Show Details)
alangenfeld edited the content of this paste. (Show Details)