Skip to content

Commit

Permalink
Add cli option to show qgraph header to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Dec 2, 2021
1 parent 4a55f02 commit e97ed8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion python/lsst/ctrl/mpexec/cli/opt/optionGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def __init__(self):
ctrlMpExecOpts.qgraph_dot_option(),
ctrlMpExecOpts.save_execution_butler_option(),
ctrlMpExecOpts.clobber_execution_butler_option(),
ctrlMpExecOpts.dataset_query_constraint()]
ctrlMpExecOpts.dataset_query_constraint(),
ctrlMpExecOpts.qgraph_header_data_option()]


class butler_options(OptionGroup): # noqa: N801
Expand Down
17 changes: 11 additions & 6 deletions python/lsst/ctrl/mpexec/cli/opt/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,19 @@ def _to_int(value):
# I wanted to use default=None here to match Python API but click silently
# replaces None with an empty tuple when multiple=True.
qgraph_node_id_option = MWOptionDecorator("--qgraph-node-id",
callback=_split_commas_int,
callback=split_commas,
multiple=True,
help=unwrap("""Only load a specified set of nodes when graph is
loaded from a file, nodes are identified by integer
IDs. One or more comma-separated integers are accepted.
By default all nodes are loaded. Ignored if graph is
not loaded from a file."""))

loaded from a file, nodes are identified by UUID
values. One or more comma-separated integers are
accepted. By default all nodes are loaded. Ignored if
graph is not loaded from a file."""))

qgraph_header_data_option = MWOptionDecorator("--show-qgraph-header",
is_flag=True,
default=False,
help=unwrap("""Print the headerData for Quantum Graph to the
console"""))

qgraph_dot_option = MWOptionDecorator("--qgraph-dot",
help=unwrap("""Location for storing GraphViz DOT representation of a
Expand Down
6 changes: 5 additions & 1 deletion python/lsst/ctrl/mpexec/cli/script/qgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
def qgraph(pipelineObj, qgraph, qgraph_id, qgraph_node_id, skip_existing_in, skip_existing, save_qgraph,
save_single_quanta, qgraph_dot, butler_config, input, output, output_run, extend_run,
replace_run, prune_replaced, data_query, show, save_execution_butler, clobber_execution_butler,
clobber_outputs, dataset_query_constraint, **kwargs):
clobber_outputs, dataset_query_constraint, show_qgraph_header=False, **kwargs):
"""Implements the command line interface `pipetask qgraph` subcommand,
should only be called by command line tools and unit test code that test
this function.
Expand Down Expand Up @@ -118,6 +118,9 @@ def qgraph(pipelineObj, qgraph, qgraph_id, qgraph_node_id, skip_existing_in, ski
Control constraining graph building using pre-existing dataset types.
Valid values are off, all, or a comma separated list of dataset type
names.
show_qgraph_header : bool, optional
Controls if the headerData of a QuantumGraph should be printed to the
terminal. Defaults to False.
kwargs : `dict` [`str`, `str`]
Ignored; click commands may accept options for more than one script
function and pass all the option kwargs to each of the script functions
Expand Down Expand Up @@ -150,6 +153,7 @@ def qgraph(pipelineObj, qgraph, qgraph_id, qgraph_node_id, skip_existing_in, ski
clobber_execution_butler=clobber_execution_butler,
clobber_outputs=clobber_outputs,
dataset_query_constraint=dataset_query_constraint,
show_qgraph_header=show_qgraph_header,
)

f = CmdLineFwk()
Expand Down
6 changes: 4 additions & 2 deletions python/lsst/ctrl/mpexec/cmdLineFwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ def makeGraph(self, pipeline, args):
# pipeline can not be provided in this case
if pipeline:
raise ValueError("Pipeline must not be given when quantum graph is read from file.")

if args.show_qgraph_header:
print(QuantumGraph.readHeader(args.qgraph))
else:

# make execution plan (a.k.a. DAG) for pipeline
graphBuilder = GraphBuilder(registry,
skipExistingIn=args.skip_existing_in,
Expand All @@ -570,6 +570,8 @@ def makeGraph(self, pipeline, args):
"time": f"{datetime.datetime.now()}"}
qgraph = graphBuilder.makeGraph(pipeline, collections, run, args.data_query, metadata=metadata,
datasetQueryConstraint=args.dataset_query_constraint)
if args.show_qgraph_header:
print(qgraph.buildAndPrintHeader())

# Count quanta in graph and give a warning if it's empty and return
# None.
Expand Down

0 comments on commit e97ed8b

Please sign in to comment.