Coverage for python/lsst/ctrl/mpexec/cli/script/qgraph.py : 15%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of ctrl_mpexec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22import logging
24from lsst.daf.butler.cli.cliLog import CliLog
25from ... import CmdLineFwk
27_log = logging.getLogger(__name__.partition(".")[2])
30def qgraph(pipeline=None, log_level=(), qgraph=None, skip_existing=False, save_qgraph=None,
31 save_single_quanta=None, qgraph_dot=None, butler_config=None, input=list(), output=None,
32 output_run=None, extend_run=False, replace_run=False, prune_replaced=None, data_query="",
33 show=None):
34 """Implements the command line interface `pipetask qgraph` subcommand,
35 should only be called by command line tools and unit test code that test
36 this function.
38 Parameters
39 ----------
40 pipeline : `pipe.base.Pipeline` or None.
41 The pipeline object used to generate a qgraph. If this is not `None`
42 then `qgraph` should be `None`.
43 log_level : `list` of `tuple`
44 per-component logging levels, each item in the list is a tuple
45 (component, level), `component` is a logger name or an empty string
46 or `None` for root logger, `level` is a logging level name, one of
47 CRITICAL, ERROR, WARNING, INFO, DEBUG (case insensitive).
48 qgraph : `str` or `None`
49 Path location for a serialized quantum graph definition as a pickle
50 file. If this option is not None then `pipeline` should be `None`.
51 skip_existing : `bool`
52 If all Quantum outputs already exist in the output RUN collection then
53 that Quantum will be excluded from the QuantumGraph. Will only be used
54 if `extend_run` flag is set.
55 save_qgraph : `str` or `None`
56 Path location for storing a serialized quantum graph definition as a
57 pickle file.
58 save_single_quanta : `str` or `None`
59 Format string of locations for storing individual quantum graph
60 definition (pickle files). The curly brace {} in the input string will
61 be replaced by a quantum number.
62 qgraph_dot : `str` or `None`
63 Path location for storing GraphViz DOT representation of a quantum graph.
64 butler_config : `str`, `dict`, or `lsst.daf.butler.Config`
65 If `str`, `butler_config` is the path location of the gen3
66 butler/registry config file. If `dict`, `butler_config` is key value
67 pairs used to init or update the `lsst.daf.butler.Config` instance. If
68 `Config`, it is the object used to configure a Butler.
69 input : `str`
70 Comma-separated names of the input collection(s). Entries may include a
71 colon (:), the first string is a dataset type name that restricts the
72 search in that collection.
73 output : `str`
74 Name of the output CHAINED collection. This may either be an existing
75 CHAINED collection to use as both input and output (if `input` is
76 `None`), or a new CHAINED collection created to include all inputs
77 (if `input` is not `None`). In both cases, the collection's children
78 will start with an output RUN collection that directly holds all new
79 datasets (see `output_run`).
80 output_run : `str`
81 Name of the new output RUN collection. If not provided then `output`
82 must be provided and a new RUN collection will be created by appending
83 a timestamp to the value passed with `output`. If this collection
84 already exists then `extend_run` must be passed.
85 extend_run : `bool`
86 Instead of creating a new RUN collection, insert datasets into either
87 the one given by `output_run` (if provided) or the first child
88 collection of `output` (which must be of type RUN).
89 replace_run : `bool`
90 Before creating a new RUN collection in an existing CHAINED collection,
91 remove the first child collection (which must be of type RUN). This can
92 be used to repeatedly write to the same (parent) collection during
93 development, but it does not delete the datasets associated with the
94 replaced run unless `prune-replaced` is also True. Requires `output`,
95 and `extend_run` must be `None`.
96 prune_replaced : "unstore", "purge", or `None`.
97 If not `None`, delete the datasets in the collection replaced by
98 `replace_run`, either just from the datastore ("unstore") or by
99 removing them and the RUN completely ("purge"). Requires `replace_run`.
100 data_query : `str`
101 User query selection expression.
102 show : `list` [`str`] or `None`
103 Descriptions of what to dump to stdout.
105 Returns
106 -------
107 qgraph : `lsst.pipe.base.QuantumGraph`
108 The qgraph object that was created.
109 """
110 # if pipeline is not None and qgraph is not None:
111 # raise ClickException(
112 # "Do not pass '--qgraph' file location if running 'build' command before 'qgraph'.")
113 # if pipeline is None and qgraph is None:
114 # raise ClickException( # or, could make an anonymous pipeline...?
115 # "Run 'build' command before 'qgraph' or provide a serialzed qgraph file location.")
117 if log_level is not None:
118 CliLog.setLogLevels(log_level)
120 class MakeGraphArgs:
121 """A container class for arguments to CmdLineFwk.makeGraph, whose
122 API (currently) is written to accept inputs from argparse in a generic
123 container class.
124 """
126 def __init__(self, qgraph, save_qgraph, save_single_quanta, qgraph_dot, butler_config, input, output,
127 output_run, extend_run, replace_run, prune_replaced, data_query, show, skip_existing):
128 self.qgraph = qgraph
129 self.save_qgraph = save_qgraph
130 self.save_single_quanta = save_single_quanta
131 self.qgraph_dot = qgraph_dot
132 self.butler_config = butler_config
133 self.input = input
134 self.output = output
135 self.output_run = output_run
136 self.extend_run = extend_run
137 self.replace_run = replace_run
138 self.prune_replaced = prune_replaced
139 self.data_query = data_query
140 self.show = show
141 self.skip_existing = skip_existing
143 args = MakeGraphArgs(qgraph=qgraph, save_qgraph=save_qgraph, save_single_quanta=save_single_quanta,
144 qgraph_dot=qgraph_dot, butler_config=butler_config, input=input, output=output,
145 output_run=output_run, extend_run=extend_run, replace_run=replace_run,
146 prune_replaced=prune_replaced, data_query=data_query, show=show,
147 skip_existing=skip_existing)
149 f = CmdLineFwk()
150 qgraph = f.makeGraph(pipeline, args)
152 # optionally dump some info.
153 if show:
154 f.showInfo(args, pipeline, qgraph)
156 return qgraph