Collapse and expand nodes #54
Replies: 2 comments 5 replies
-
|
AI chat. (Beware of hallucinations!) |
Beta Was this translation helpful? Give feedback.
-
expanding and collapsing function callsThe fact that we separate variable and functional nodes in a DAG is not very compliant with We'd like to be able to chose what should be an input and what should be fixed with less ackwardness. Let's have a look at a "pipeline" that one would use to visualize segments of text. from meshed import code_to_dag
@code_to_dag
def embed_process():
"""A "pipeline" that one would use to visualize segments of text.
One would need to prepare the data (so that it's easy to get metadata and text from it),
embed segments of the text (we'll hide the detals here), cluster and planerize the embeddings
(vectors of high dimension), and finally aggregate everything so it can be readily used by
a visualization function.
"""
base_data = prepper(data_src)
texts_metadata = metadata_extractor(base_data)
embeddings = embedder(base_data)
planar_vectors = planarizer(embeddings)
cluster_indices = clusterer(embeddings)
aggregate = aggregator(texts_metadata, planar_vectors, cluster_indices)
embed_process.dot_digraph()That's all fine and good, but how do I change my One answer is: By "expanding" the functions into "function callers". from meshed.scrap.collapse_and_expand import expand_function_calls
expand_function_calls(embed_process, include=['prepper', 'embedder']).dot_digraph()If you need to do the inverse to pack things a bit (for example, because it's easier to read the diagram), from meshed.scrap.collapse_and_expand import collapse_function_calls
collapse_function_calls(embed_process, include=['prepper', 'embedder']).dot_digraph() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As DAG's get more nodes, things can get quickly unwieldy. One of our tools to mitigate this is being able to collapse/expand sub-DAGs. This is no revolutionary idea. This kind of chunking (psychology term) can be found all over software objects: We group lines of code in functions, group these in other functions (and/or classes), group these in modules, modules in packages etc.
Here, we just want to have tools that do this, specialized for DAGs (and other mesh objects!).
Any sub-DAG is a DAG itself, therefore a callable itself, so could be collapsed into a single
FuncNode, as well as expanded back to the original DAG.Consideration
Consider that though collapsing sub-dags one by one will result in a partition of the DAG, there are many ways one could do that.
When we expand a collapsed node, how the expansion integrates with the rest of the DAG is problematic. Say you make a DAG with two nodes,
fandg, andgitself was a collapsed DAG. If you expand it, making a var nodexappear, thisxmight clash with a var nodexthatfhas as an input. It may not be the samex. This problem won't happen if you start with a totally expanded DAG and collapse nodes from there, but it could happen if you make a DAG withFuncNodesthat are DAGs themselves.Once we expand a collapsed node, if we don't do something extra (like having a ledger of what nodes were collapsed), we wouldn't have the required information to revert that expansion back to the collapsed form.
It may be useful to have these "ledgers" that record sets of nodes that are good candidates to be use as
FuncNodes, but these sets of nodes (i.e. DAGs) could overlap. When mapping DAG operations to a GUI, it may be useful to enable the selection and naming of sets of nodes into a ledger, that could then be used to highlight the corresponding nodes in a current DAG, and allow these to be collapsed. The same ledger could then be used to hold the sets of nodes create by expanding nodes in the DAG so we can keep the info we need to re-collapse them.Example: Rolling in (orphaned) nodes
DAG.partialhad a (not implemented)_roll_in_orphaned_nodesarguments described as such:When True, actually change the DAG so it only contains the nodes it "needs": that is, recursively remove func-nodes (and their output nodes) if their inputs are fixed.
This argument was removed because it was not clear what it should mean or how useful it would be at this juncture.
This issue is to keep track of the thinking around this. This also fits in the general thinking about what we'd like to have as far as
DAG(or other meshed data structures) operations.Considerations
In the case of rolling in nodes (which is also related to expanding nodes that are DAGs), here are some considerations:
What more do we mean the simply removing nodes (and with them, the edges attached to them) from the underlying graph?
Say we have a node representing
f(a=1, b=2): we may not want to have a and b show up in the signature, or the graphviz display, but what do we do with the value it should compute? We could compute the function, then store the result in the out node, to then be used as the default of the functions that use it. Maybe recursively doing the same with those functions.One problem with that can arise if
fis not deterministic, the resulting DAG won't be the same as our "rolled in" DAG, but this simplification and caching mechanism can still be useful in many contexts. It should be requested explicitly though.Beta Was this translation helpful? Give feedback.
All reactions