Hi! I'm wondering if someone can help me understan...
# hamilton-help
e
Hi! I'm wondering if someone can help me understand whether Hamilton is suited for my use case. My workflows commonly have nodes that are repeated for each item in a dynamic set that depends on user input. In some cases, the underlying functions take in multiple arguments that vary according to the same dynamic set of values. Here is a contrived example:
Copy code
def create_text_file(text, target_path):
    with open(target_path, 'w') as f:
        f.write(text)

USER_DEFINED_COLORS = ['blue', 'purple', 'yellow']
for color in USER_DEFINED_COLORS:
    # create a graph node corresponding to this function call:
    create_text_file(color, f'{color[0]}.txt')
so that if the user-defined set of colors is
['blue', 'purple', 'yellow']
, then I would get a graph containing 3 nodes representing the function calls
Copy code
create_text_file('blue', 'b.txt')
create_text_file('purple', 'p.txt')
create_text_file('yellow', 'y.txt')
With some other workflow tools, I can do this by programmatically creating a graph node within the for-loop. I'm wondering if/how this is possible with Hamilton, or is it "too declarative" for this purpose? I've read a bit about
Parallelizable
but I'm not sure if multiple arguments can be
Parallelizable
or how Hamilton would zip them together. E.g. in the above example, if both the
text
argument and the
target_path
argument are
Parallelizable
, yielding values of
['blue', 'purple', 'yellow']
and
['b.txt', 'p.txt', 'y.txt']
respectively, can Hamilton know to "zip" them together such that
'blue'
goes with
'b.txt'
and so on? Much appreciate any input on this, thanks!
e
Yes this is supported in parallelizable
Copy code
def option_sets(user_colors: List[str], files: List[str]) -> Parallelizable[Tuple[str, str]]
   for item in zip(user_colors, files):
      yield item
😯 1
So it's exactly what you want -- uprely dynamic!