Slackbot
02/20/2024, 1:33 PMThierry Jean
02/20/2024, 1:57 PMhamilton.plugins.h_experiments.ExperimentTracker
, I implemented a utility function to get the default parameters of a node (i.e., the function has a: int = 1
instead of a: int)
. (see here)
If you're comfortable, you could start with that and try some custom viz styles?Thierry Jean
02/20/2024, 2:00 PMRoel Bertens
02/21/2024, 6:07 PMElijah Ben Izzy
02/21/2024, 6:10 PMRoel Bertens
02/21/2024, 6:32 PMRoel Bertens
02/22/2024, 9:40 AM_get_default_input
now indeed to check this but since this method is not expected to be used outside the module it might be good to make it clear that you can actually use this method (i.e. a publicly available method).Thierry Jean
02/22/2024, 12:47 PMgraph_types.HamiltonNode
, then it simply inspects the function the underlying function signature.
@Elijah Ben Izzy We could move it to graph_utils
? or make it a property of HamiltonNode
? Similarly, we could move hash_source_code()
from to a property.Thierry Jean
02/22/2024, 12:51 PMdef A(external: int = 7) -> float:
return external / 2
# call 1
dr.execute(["A"])
# call 2
dr.execute(["A"], inputs={"external": 5})
For call 1 an call 2, external
should be is_external_input
(from the dataflow's POV) and they will have value 7 and 5 respectively.
In the experiment tracker, I disambiguate the two using
inputs = dict() # from .execute()
logged_inputs = []
# graph is graph_types.HamiltonGraph
# node is graph_types.HamiltonNode
for node in graph.nodes:
# filter out config nodes which are external but no origin
elif node.is_external_input and node.originating_functions:
self.logged_inputs.append(
dict(
name=node.name,
value=inputs.get(node.name), # value from execute
default_value=_get_default_input(node), # value from function signature
)
)
which would lead to call 1 {name: A, value: 7, default_value: None}
and call 2 {name: A, value: 5, default_value: 7}
Elijah Ben Izzy
02/22/2024, 2:41 PM_get_default_input
is largely correct but might run into some issues (it assumes 1:1 mapping of fn -> node)… I’d like to add in defaults
value. It’ll be a dict of str
-> value
. @Roel Bertens in the meanwhile you can use the optional_dependencies to know which ones are defaults, and use the logic in get_default_input
.Elijah Ben Izzy
02/22/2024, 3:03 PMRoel Bertens
02/23/2024, 9:06 AMRoel Bertens
03/01/2024, 1:48 PMdef _is_input_node_with_default(node) -> bool:
"""Return True if the input node has a default value specified
NOTE: also return True if the default is None
"""
if node.is_external_input and node.originating_functions is not None: # exclude config nodes
origin_function = node.originating_functions[0]
param = inspect.signature(origin_function).parameters[node.name]
return False if param.default is inspect._empty else True
return False
Based on this I want to style these input nodes differently but I notice they are not reachable via the custom_style
function which I pass to display_all_functions
. How can I change their look?Thierry Jean
03/01/2024, 4:29 PMRoel Bertens
03/01/2024, 5:17 PM%%cell_to_module -m my_module --display
def test(a: int, b: int = 2) -> int:
return a+b
Roel Bertens
03/01/2024, 5:17 PMRoel Bertens
03/01/2024, 5:28 PMdef custom_style_function(
*, node: graph_types.HamiltonNode, node_class: str
) -> Tuple[dict, Optional[str], Optional[str]]:
if _is_input_node_with_default(node):
style = ({"fillcolor": "#c1f5cf"}, node_class, "optional")
else:
style = ({}, node_class, None)
return style
And then run
dr.display_all_functions(custom_style_function=custom_style_function))
Thierry Jean
03/01/2024, 6:10 PMRoel Bertens
03/01/2024, 7:04 PMThierry Jean
03/01/2024, 7:06 PMRoel Bertens
03/04/2024, 7:44 AMRoel Bertens
03/04/2024, 7:47 AMThierry Jean
03/04/2024, 4:27 PMlabel
attribute (see Graphviz docs). These tables use a HTML-like syntax specific to Graphviz. To style individual inputs of a grouped input, we would need to expose the node label
attribute
On the opposite, creating an individual node for each inputs, and potentially using subgraphs to group them, creates messier layouts generally and a lot more entropy/variations between reruns of the same viz since it's non-deterministic.Roel Bertens
03/04/2024, 4:41 PMThierry Jean
03/04/2024, 4:52 PMdeduplicate_inputs
which is sometimes unintuitive
2. create new logic to identify default inputs (you could style or hide it):
◦ in short, the ad hoc logic we shared earlier in this thread to identify default inputs wouldn't work. I can give you an example workaround, but the API will likely change when we'll decide how to support default valuesThierry Jean
03/04/2024, 5:48 PMThreadScribe
03/04/2024, 5:48 PMThreadScribe
03/04/2024, 5:48 PMhamilton.plugins.h_experiments.ExperimentTracker
to get the default parameters of a node. This function inspects the function signature to distinguish default values for inputs.
- The team also discussed the possibility of surfacing all the configuration keys, required inputs, and optional inputs to automatically generate a "configuration space" of all possible DAGs. This could potentially help with ML experiments or enable DAG authors to constrain the input space to valid configurations for downstream users.
- Discussions included moving certain methods to different modules or properties for better accessibility and usage.
- Sample code snippets were shared for identifying and styling input nodes with default values, along with the challenges and options for applying different styles to input nodes.
- Short-term solutions were discussed, including support for ungrouping input nodes and creating new logic to identify default inputs for styling or hiding.
- Graphviz limitations were highlighted, along with the potential challenges in implementing certain display options.
- It was noted that excluding optional inputs from the DAG displayed a complex set of challenges and limitations, particularly in relation to Graphviz and the current API logic.
The team also agreed to summarize the discussion into a structured GitHub issue to further track the progress of the potential changes.
Feel free to refer to the complete discussion for additional context.ThreadScribe
03/04/2024, 5:48 PMThierry Jean
03/04/2024, 5:48 PM