Slackbot
04/19/2023, 5:16 AMElijah Ben Izzy
04/19/2023, 3:59 PMElijah Ben Izzy
04/19/2023, 4:17 PM@resolve
references the config items by name. So, what you want is (I think)
@resolve(
when=ResolveAt.CONFIG_AVAILABLE,
decorate_with=lambda names: parameterize_values("name", {(name, doc_string): name for name in names})
)
The way to read this is that, when the config is available, we get the names
field from it and utilize it to build the paramterize_values
decorator, which then gets applied to create_obj
.
2. The variables to driver
get called as a list dr.execute(['name1')
I’ve gotten your example to work (using @parameterize
instead but its basically the same. Code should be able to run!
from hamilton.function_modifiers import resolve, ResolveAt, parameterize, value
from hamilton.ad_hoc_utils import create_temporary_module
from hamilton import driver
from hamilton.base import SimplePythonGraphAdapter, DictResult
import dataclasses
@dataclasses.dataclass
class MyObject:
name: str
@resolve(
when=ResolveAt.CONFIG_AVAILABLE,
decorate_with=lambda names: parameterize(
**{name : {"name" : value(name)} for name in names}
)
)
def create_obj(name: str) -> MyObject:
return MyObject(name)
mod = create_temporary_module(create_obj)
adapter = SimplePythonGraphAdapter(DictResult())
dr = driver.Driver(
{
"hamilton.enable_power_user_mode" : True,
"names" : ["name1", "name2"]
},
mod,
adapter=SimplePythonGraphAdapter(DictResult())
)
print(dr.execute(["name1"]))
Elijah Ben Izzy
04/19/2023, 4:20 PMsubdag
. subdag
+ @parameterize_subdag
allow just that:
• https://hamilton.readthedocs.io/en/latest/reference/api-reference/decorators.html#subdag
• https://hamilton.readthedocs.io/en/latest/reference/api-reference/decorators.html#parameterized-subdag
That said, you’ve jumpted straight to power-user mode, so I’d be careful. Other options are:
1. Have the config hardcoded if you dont want to change it that much
2. Have a for-loop inside your functionJan Hurst
04/20/2023, 2:44 AM@resolve
and @parameterized_subdag
and got some things up and running.
the bit i got stuck on was figuring out how to "ask" for a specific output in a subdag, i.e. i didn't understand the name1.subdag_step
output naming. this was compounded a bit by not being able to get the visualization stuff to work very well
im also now exploring if i can do something outside of the DAG to setup a better config. one of the important things I am looking for is to have very atomic nodes so that i can farm out to Dask (which incidentally was a snap to use)Elijah Ben Izzy
04/20/2023, 2:50 AM@subdag(
*modules,
inputs={...},
config={...}
)
def some_fn(subdag_output: ...) -> ...:
return do_something_with(subdag_output)
the subdag produced will be namespaced by some_fn
and contain a final element called subdag_output
. That will then be passed to some_fn
which will be a node in the DAG. So, it’ll be:
… -> some_fn.subdag_output -> some_fn -> …
Makes sense? Would love to make this clearer in the documentation if possible.Elijah Ben Izzy
04/20/2023, 2:51 AMElijah Ben Izzy
04/20/2023, 2:51 AM