https://dagster.io/ logo
Title
v

Valentin Stauber

02/17/2022, 5:41 PM
Hey folks, new here 👋 I have a question about multiple dynamic op outputs: If I have a single dynamic output, I would decorate with e.g.
@op(out=DynamicOut(str))
def create_inputs():
    for i in range(3):
        yield DynamicOutput(value=f"value{i}", mapping_key=f"output{i}")

@graph
def process(inp: str):
    res = another_op(inp)
    ...

@job
def my_job():
    inputs = create_inputs()
    inputs.map(process)
now suppose I want to map to a graph that takes several input arguments, which might get passed to different ops inside
@graph
def process(inp1: str, inp2: int, inp3: float):
    res1 = another_op1(inp1)
    res2 = another_op2(inp2)
    res3 = another_op3(inp3)
    ...
how would I annotated and implement a
create_inputs
op that would yield "dynamic Tuple[str, int, float]s", s.t. I can still use
inputs = create_inputs()
    inputs.map(process)
in my job, together with correct annotations on the graph in dagit (with names and all)? Thanks a bunch 🙏
a

alex

02/17/2022, 6:00 PM
There may not be a way to achieve exactly what you desire. if you have the dynamic output be
Tuple[str, int, float]
you could just have
process
take the tuple and then add an
op
that splits it out in to multiple outputs.
@graph
def process(tuple_val: Tuple[str, int float]):
    inp1, inp2, inp3 = split(tuple_val)
    res1 = another_op1(inp1)
    res2 = another_op2(inp2)
    res3 = another_op3(inp3)
    ...
The
@graph
/
@job
functions dont execute at runtime, only at init time to build the dependency structure, so data manipulation has to happen in an
@op
v

Valentin Stauber

02/17/2022, 6:06 PM
I see, thanks for the quick reply! I might go with the splitting op, thanks for the advice!
c

Charlie Bini

02/17/2022, 11:19 PM
omg I think this thread solved something that I've been banging my head against the wall about
❤️ 1
v

Valentin Stauber

02/18/2022, 9:42 AM
@alex just as a follow up, for python builtin or multiprocessing, besides the
map
function, that passes single parameters unaltered to the eval function, there is also starmap which passes unpacked tuples to the eval function to be able to use multiple input parameters. Would it be worthwhile to consider adding a
starmap
method to
DynamicOutput
?
👆 1
a

alex

02/18/2022, 3:27 PM
Hmm, it would likely be a big lift to support something like that. The data values that are passed between ops are opaque to the orchestration process and subject to a few user pluggable systems like
IOManager
. I encourage you to file an issue if you think it would be useful. Including some context on use case / motivation always helpful.
v

Valentin Stauber

02/18/2022, 4:48 PM
I see. Thanks, I'll consider it 🙂
y

yuhan

06/20/2022, 4:12 PM
@Dagster Bot discussion Multiple dynamic op outputs
d

Dagster Bot

06/20/2022, 4:12 PM
Question in the thread has been surfaced to GitHub Discussions for future discoverability: https://github.com/dagster-io/dagster/discussions/8485