Skip to content

Commit

Permalink
Add pipetask option to save pipelines in expanded form.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo authored and timj committed Aug 8, 2024
1 parent 366e7aa commit d80de8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/lsst/ctrl/mpexec/cli/opt/optionGroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self) -> None:
),
ctrlMpExecOpts.order_pipeline_option(),
ctrlMpExecOpts.save_pipeline_option(),
ctrlMpExecOpts.expand_pipeline_option(),
ctrlMpExecOpts.pipeline_dot_option(),
pipeBaseOpts.instrument_option(help=instrumentOptionHelp, metavar="instrument", multiple=True),
ctrlMpExecOpts.butler_config_option(required=False),
Expand Down
10 changes: 10 additions & 0 deletions python/lsst/ctrl/mpexec/cli/opt/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@
type=MWPath(dir_okay=False, file_okay=True, writable=True),
)

expand_pipeline_option = MWOptionDecorator(
"-s",
"--expand-pipeline",
help=unwrap(
"""Directory location for storing the fully-expanded
pipeline definition."""
),
type=MWPath(dir_okay=True, file_okay=False, writable=True),
)

save_qgraph_option = MWOptionDecorator(
"-q",
"--save-qgraph",
Expand Down
6 changes: 6 additions & 0 deletions python/lsst/ctrl/mpexec/cli/script/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def build( # type: ignore
pipeline_actions,
pipeline_dot,
save_pipeline,
expand_pipeline,
show,
butler_config=None,
**kwargs,
Expand Down Expand Up @@ -67,6 +68,10 @@ def build( # type: ignore
Path location for storing GraphViz DOT representation of a pipeline.
save_pipeline : `str`
Path location for storing resulting pipeline definition in YAML format.
expand_pipeline : `str`
Directory path location for storing the expanded pipeline definition,
with all references to other files resolved and written to config files
in the directory.
show : `lsst.ctrl.mpexec.showInfo.ShowInfo`
Descriptions of what to dump to stdout.
butler_config : `str`, `dict`, or `lsst.daf.butler.Config`, optional
Expand Down Expand Up @@ -103,6 +108,7 @@ def build( # type: ignore
pipeline_actions=pipeline_actions,
pipeline_dot=pipeline_dot,
save_pipeline=save_pipeline,
expand_pipeline=expand_pipeline,
)

f = CmdLineFwk()
Expand Down
3 changes: 3 additions & 0 deletions python/lsst/ctrl/mpexec/cmdLineFwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ def makePipeline(self, args: SimpleNamespace) -> Pipeline:
if args.save_pipeline:
pipeline.write_to_uri(args.save_pipeline)

if args.expand_pipeline:
pipeline.write_to_uri(args.expand_pipeline, expand=True)

return pipeline

def makeGraph(self, pipeline: Pipeline, args: SimpleNamespace) -> QuantumGraph | None:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cliScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def buildArgs(**kwargs):
pipeline_actions=(),
pipeline_dot=None,
save_pipeline=None,
expand_pipeline=None,
show=ShowInfo([]),
)
defaultArgs.update(kwargs)
Expand All @@ -77,6 +78,20 @@ def testSavePipeline(self):
self.assertIsInstance(pipeline, Pipeline)
self.assertEqual(len(pipeline), 0)

def testExpandPipeline(self):
"""Test expanded pipeline serialization."""
with tempfile.TemporaryDirectory() as tempdir:
# make empty pipeline and store it in a directory
directory = os.path.join(tempdir, "pipeline_dir")
pipeline = script.build(**self.buildArgs(expand_pipeline=directory))
self.assertIsInstance(pipeline, Pipeline)
self.assertTrue(os.path.isdir(directory))
# read pipeline from a directory
pipeline = script.build(**self.buildArgs(pipeline=directory))
self.assertIsInstance(pipeline, Pipeline)
self.assertIsInstance(pipeline, Pipeline)
self.assertEqual(len(pipeline), 0)

def testShowPipeline(self):
"""Test showing the pipeline."""

Expand Down

0 comments on commit d80de8e

Please sign in to comment.