Skip to content

Commit

Permalink
Initial prototype of Mermaid code generator for pipelines and quantum…
Browse files Browse the repository at this point in the history
… graphs
  • Loading branch information
enourbakhsh committed Dec 18, 2024
1 parent e4484fe commit 9b7c938
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/lsst/ctrl/mpexec/cli/opt/optionGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self) -> None:
ctrlMpExecOpts.order_pipeline_option(),
ctrlMpExecOpts.save_pipeline_option(),
ctrlMpExecOpts.pipeline_dot_option(),
ctrlMpExecOpts.pipeline_mermaid_option(),
pipeBaseOpts.instrument_option(help=instrumentOptionHelp, metavar="instrument", multiple=True),
ctrlMpExecOpts.butler_config_option(required=False),
]
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(self) -> None:
ctrlMpExecOpts.save_qgraph_option(),
ctrlMpExecOpts.save_single_quanta_option(),
ctrlMpExecOpts.qgraph_dot_option(),
ctrlMpExecOpts.qgraph_mermaid_option(),
ctrlMpExecOpts.summary_option(),
ctrlMpExecOpts.save_execution_butler_option(),
ctrlMpExecOpts.clobber_execution_butler_option(),
Expand Down
13 changes: 13 additions & 0 deletions python/lsst/ctrl/mpexec/cli/opt/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@
)


pipeline_mermaid_option = MWOptionDecorator(
"--pipeline-mermaid",
help="Location for storing Mermaid representation of a pipeline.",
type=MWPath(writable=True, file_okay=True, dir_okay=False),
)


profile_option = MWOptionDecorator(
"--profile", help="Dump cProfile statistics to file name.", type=MWPath(file_okay=True, dir_okay=False)
)
Expand Down Expand Up @@ -266,6 +273,12 @@
type=MWPath(writable=True, file_okay=True, dir_okay=False),
)

qgraph_mermaid_option = MWOptionDecorator(
"--qgraph-mermaid",
help="Location for storing Mermaid representation of a quantum graph.",
type=MWPath(writable=True, file_okay=True, dir_okay=False),
)


replace_run_option = MWOptionDecorator(
"--replace-run",
Expand Down
11 changes: 11 additions & 0 deletions python/lsst/ctrl/mpexec/cli/script/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def build( # type: ignore
pipeline,
pipeline_actions,
pipeline_dot,
pipeline_mermaid,
save_pipeline,
show,
butler_config=None,
Expand All @@ -65,6 +66,8 @@ def build( # type: ignore
A list of pipeline actions in the order they should be executed.
pipeline_dot : `str`
Path location for storing GraphViz DOT representation of a pipeline.
pipeline_mermaid : `str`
Path location for storing Mermaid representation of a pipeline.
save_pipeline : `str`
Path location for storing resulting pipeline definition in YAML format.
show : `lsst.ctrl.mpexec.showInfo.ShowInfo`
Expand Down Expand Up @@ -102,6 +105,7 @@ def build( # type: ignore
pipeline=pipeline,
pipeline_actions=pipeline_actions,
pipeline_dot=pipeline_dot,
pipeline_mermaid=pipeline_mermaid,
save_pipeline=save_pipeline,
)

Expand All @@ -124,6 +128,13 @@ def build( # type: ignore
task_classes="full",
)

if pipeline_mermaid:
with open(pipeline_mermaid, "w") as stream:
visualization.show_mermaid(
pipeline.to_graph(butler.registry if butler is not None else None, visualization_only=True),
stream,
)

show.show_pipeline_info(pipeline, butler=butler)

return pipeline
4 changes: 4 additions & 0 deletions python/lsst/ctrl/mpexec/cli/script/qgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def qgraph( # type: ignore
save_qgraph,
save_single_quanta,
qgraph_dot,
qgraph_mermaid,
butler_config,
input,
output,
Expand Down Expand Up @@ -105,6 +106,8 @@ def qgraph( # type: ignore
qgraph_dot : `str` or `None`
Path location for storing GraphViz DOT representation of a quantum
graph.
qgraph_mermaid : `str` or `None`
Path location for storing Mermaid representation of a quantum graph.
butler_config : `str`, `dict`, or `lsst.daf.butler.Config`
If `str`, `butler_config` is the path location of the gen3
butler/registry config file. If `dict`, `butler_config` is key value
Expand Down Expand Up @@ -194,6 +197,7 @@ def qgraph( # type: ignore
save_qgraph=save_qgraph,
save_single_quanta=save_single_quanta,
qgraph_dot=qgraph_dot,
qgraph_mermaid=qgraph_mermaid,
butler_config=butler_config,
input=input,
output=output,
Expand Down

0 comments on commit 9b7c938

Please sign in to comment.