Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw mermaid flowchart Version 1 #190

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

abjjabjj
Copy link
Contributor

@abjjabjj abjjabjj commented Nov 21, 2024

Try this in jupyter

from concrete.mermaid import FlowchartDirection
from concrete.operators import *
from concrete.projects import DAGNode, Project


project = Project()
nodes = [project.add_node(node) for node in [
    DAGNode("fee", "chat", Operator(), {"message": "Hello World!"}),
    DAGNode("fi", "ask_question", Developer(), {"context": "You pass butter."}),
    DAGNode("fo", "answer_question", Executive()),
    DAGNode("fum", "generate_summary", Executive()),
]]
edges = [
    project.add_edge("fee", "fo", "context"),
    project.add_edge("fi", "fo", "question"),
    project.add_edge("fee", "fum", "summary"),
    project.add_edge("fo", "fum", "implementation"),
]

print(project.draw_mermaid())

Paste to Mermaid Live Editor

See the magic

Needs tests but it's alive

  • Few styling options, i.e. title and direction of graph.
  • Few subgraph options, i.e. can set start and end nodes.
  • Implemented generic BFS and source/sink finders for directed graphs (note not acyclic constrained)
    • Hint hint means visualization should work on unfinished DAGProjects (I haven't actually tested this yet)

@abjjabjj
Copy link
Contributor Author

end_nodes functionality is bugged (but not feature breaking) because edge processing is done post-node processing

Copy link
Contributor Author

so edge case (get it) is for parent node of end node, it will process all the edges on that layer of the BFS instead of just the one connecting parent to end

Copy link
Contributor Author

actually there’s a bunch of other cases that will probably be buggy since there are no checks on end nodes

Copy link
Contributor Author

e.g. all the end nodes could be upstream of the start nodes if graph is a DAG

Copy link
Contributor Author

could change implementation to backtracking instead. I think that should solve the problems

@MichaelDeng03
Copy link
Contributor

I think your link to mermaid live editor is borked - it seems to be linking to github diffs

@MichaelDeng03
Copy link
Contributor

Otherwise, very neat!
Could you add a placeholder/templating to children nodes, it's not clear that answer_question can accept context/question.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants