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 Sep 27, 2023
1 parent 8e0072f commit 0b83a1f
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 @@ -280,6 +280,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 @@ -39,6 +39,7 @@ def build( # type: ignore
pipeline_actions,
pipeline_dot,
save_pipeline,
expand_pipeline,
show,
butler_config=None,
**kwargs,
Expand Down Expand Up @@ -66,6 +67,10 @@ def build( # type: ignore
Path location of a pipeline definition file in YAML format.
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 @@ -102,6 +107,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 @@ -576,6 +576,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)

if args.pipeline_dot:
pipeline2dot(pipeline, args.pipeline_dot)

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 0b83a1f

Please sign in to comment.