Slackbot
12/20/2023, 7:03 PMRoel Bertens
12/21/2023, 8:17 AMElijah Ben Izzy
12/21/2023, 6:11 PMThierry Jean
12/21/2023, 6:45 PMdisplay_
• infer file type from name/path
• pipe graphviz to avoid generating a DOT file
• create a structured object HamiltonDisplayConfig
that's well documented and type-annotated that encompasses all of the public interface (args, kwargs, render_kwargs, graph_kwargs)
• advanced: provide string alias for long type annotations
• advanced: enable theming (requires structured objects and config)miek
12/25/2023, 7:29 PMArthur Andres
12/29/2023, 9:22 AMStefan Krawczyk
12/29/2023, 5:08 PMdeduplicate_inputs=True
Stefan Krawczyk
12/29/2023, 5:10 PMRoel Bertens
01/09/2024, 7:10 AMElijah Ben Izzy
01/09/2024, 3:30 PMRoel Bertens
01/09/2024, 3:52 PMRoel Bertens
01/09/2024, 3:53 PMThierry Jean
01/09/2024, 5:01 PM# main.py
import graphviz
from hamilton import driver
import functions
# customize graphviz render: <https://graphviz.org/docs/nodes/>
# careful with overwriting string attributes; fillcolor should be safe
level_stylesheet = dict(
intermediate=dict(
level="intermediate", # add arbitrary metadata to the DOT file; could collide with graphviz attributes
fillcolor="royalblue", # edits the style
),
final=dict(
level="final",
fillcolor="aquamarine",
)
)
dr = driver.Builder().with_modules(functions).build()
g: graphviz.Digraph = dr.display_all_functions()
for v in dr.list_available_variables():
if level := v.tags.get("level"):
g.node(v.name, **level_stylesheet[level])
Stefan Krawczyk
01/09/2024, 5:43 PMRoel Bertens
01/09/2024, 5:52 PMStefan Krawczyk
01/09/2024, 5:58 PMThierry Jean
01/09/2024, 6:14 PMfor v in dr.list_available_variables():
if level := v.tags.get("level"):
g.node(v.name, **level_stylesheet[level])
continue
# the style used for Function nodes
default_node_style = dict(
shape="rectangle",
margin="0.15",
style="rounded,filled",
fillcolor="#b4d8e4",
fontname="Helvetica",
)
# `cluster__legend` is the name of the legend subgraph
with g.subgraph(name='cluster__legend') as legend_subgraph:
for level, style in level_stylesheet.items():
legend_node = dict(**default_node_style) # set default style
legend_node.update(**style) # update default style with stylesheet
legend_subgraph.node(level, label=level, **legend_node)
Roel Bertens
01/09/2024, 6:33 PMThierry Jean
01/09/2024, 6:35 PMStefan Krawczyk
01/09/2024, 6:38 PMRoel Bertens
01/09/2024, 7:00 PMto_remove = '\t\tfunction [fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]\n'
g.body = [l for l in g.body if l != to_remove]
Thierry Jean
01/09/2024, 7:12 PMRoel Bertens
01/09/2024, 7:29 PMThierry Jean
01/09/2024, 7:31 PMdriver.what_is_upstream_of(VAR_NAME_1, VAR_NAME_2, ...)
, which returns variables objects like list_available_variables()
. There is also what_is_downstream_of()
and what_is_path_between()
Stefan Krawczyk
01/15/2024, 11:26 PMThierry Jean
01/15/2024, 11:35 PM