APIs for updating underlying function of a node (2 part question) #1397
Replies: 1 comment 10 replies
-
| Hey, cool ideas. 
 
 At the moment Hamilton does everything via modules (there's things brewing to enable directly passing functions in, but not there yet).  There is a way to override  # new_module.py
@config.when(name='B', use_alternative_b=True)
def B(C: int, D: int) -> int:
    return C + Dand # main.py
def A(B: int, C: int) -> int:
    return B + C
def B(D: int) -> int:
    return D + 1
def C(D: int) -> int:
    return D + 2
def D() -> int:
    return 7
if __name__ == "__main__":
    import __main__ as main
    import new_module
    dr = driver.Builder().with_modules(main, new_module).allow_module_overrides().build()
    dr.execute('A')A word of warning, if you use multiple modules and have in them defined functions with the same name Hamilton will throw an error. However, with the  
 
 I am not sure a fully understand the second part,  but I can give it a go and let me know if I missed something. Hamilton will create the full graph, but it will only walk / execute nodes that are relevant for a specified output (in your case  
 | 
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
(1) Updating function logic
For reference consider the following DAG
If I want to update the logic of
Bin the DAG with some functionalternative_B, the best way I've found to do so is to do the following:Which is a bit cumbersome, since it requires modifying source code and adding configuration primitives to enable the ability.
An alternative way to do this is how the fn_graph library handles this (https://fn-graph.readthedocs.io/en/latest/usage.html#building-up-logic), which provides a similar ability to update the implementation of a node by allowing you to make updates on your "driver" (called composer in fn_graph). For example to achieve the same ability in fn_graph you can do this, no decorators or additional config entities needed:
Questions:
(2) Updating function logic in a specific branch
Similar to the above consider when you want to update the implementation for a function, but only when the path from that function to the root executed function passes through another specific node/function.
For example if I want to update
DtoD__primebut only in the path that includesB, in Hamilton I could achieve that like so:But this has a couple problems: (a) if I want to later update all references to
DwithD__prime(not just throughB) I'll need to add anotherD__prime2with aconfig.when(name='D', ...)and a new config parameter, which is again pretty cumbersome. And more importantly (b) this method breaks down when the branch specific replacement happens behind a converging point, for example:If I want to replace
Xin the path ofBwith this method I would need to bifurcate all my functions starting at the converging point (D_thru_B,X_thru_B,D_thru_C,X_thru_C, etc), which would be prohibitive for anything more than a very simple example.Questions:
ParallelizableandCollectmechanism which can already dynamically generate new nodes to add to the graph, and which could be used to do the bifurcation I mentioned?driver.update(X=X__prime, in_path=['B'])Beta Was this translation helpful? Give feedback.
All reactions