Coverage for python/lsst/ctrl/mpexec/cli/script/qgraph.py: 38%
14 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-25 09:43 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-25 09:43 +0000
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
23from types import SimpleNamespace
25from lsst.pipe.base.graphBuilder import DatasetQueryConstraintVariant
27from ... import CmdLineFwk
29_log = logging.getLogger(__name__)
32def qgraph( # type: ignore
33 pipelineObj,
34 qgraph,
35 qgraph_id,
36 qgraph_node_id,
37 qgraph_datastore_records,
38 skip_existing_in,
39 skip_existing,
40 save_qgraph,
41 save_single_quanta,
42 qgraph_dot,
43 butler_config,
44 input,
45 output,
46 output_run,
47 extend_run,
48 replace_run,
49 prune_replaced,
50 data_query,
51 show,
52 save_execution_butler,
53 clobber_execution_butler,
54 target_datastore_root,
55 transfer,
56 clobber_outputs,
57 dataset_query_constraint,
58 show_qgraph_header=False,
59 mock=False,
60 unmocked_dataset_types=(),
61 mock_failure=(),
62 **kwargs,
63):
64 """Implement the command line interface `pipetask qgraph` subcommand.
66 Should only be called by command line tools and unit test code that test
67 this function.
69 Parameters
70 ----------
71 pipelineObj : `lsst.pipe.base.Pipeline` or None.
72 The pipeline object used to generate a qgraph. If this is not `None`
73 then `qgraph` should be `None`.
74 qgraph : `str` or `None`
75 URI location for a serialized quantum graph definition as a pickle
76 file. If this option is not None then `pipeline` should be `None`.
77 qgraph_id : `str` or `None`
78 Quantum graph identifier, if specified must match the identifier of the
79 graph loaded from a file. Ignored if graph is not loaded from a file.
80 qgraph_node_id : `list` of `int`, optional
81 Only load a specified set of nodes if graph is loaded from a file,
82 nodes are identified by integer IDs.
83 qgraph_datastore_records : `bool`
84 If True then include datastore records into generated quanta.
85 skip_existing_in : `list` [ `str` ]
86 Accepts list of collections, if all Quantum outputs already exist in
87 the specified list of collections then that Quantum will be excluded
88 from the QuantumGraph.
89 skip_existing : `bool`
90 Appends output RUN collection to the ``skip_existing_in`` list.
91 save_qgraph : `str` or `None`
92 URI location for storing a serialized quantum graph definition as a
93 pickle file.
94 save_single_quanta : `str` or `None`
95 Format string of URI locations for storing individual quantum graph
96 definition (pickle files). The curly brace {} in the input string will
97 be replaced by a quantum number.
98 qgraph_dot : `str` or `None`
99 Path location for storing GraphViz DOT representation of a quantum
100 graph.
101 butler_config : `str`, `dict`, or `lsst.daf.butler.Config`
102 If `str`, `butler_config` is the path location of the gen3
103 butler/registry config file. If `dict`, `butler_config` is key value
104 pairs used to init or update the `lsst.daf.butler.Config` instance. If
105 `Config`, it is the object used to configure a Butler.
106 input : `list` [ `str` ]
107 List of names of the input collection(s).
108 output : `str`
109 Name of the output CHAINED collection. This may either be an existing
110 CHAINED collection to use as both input and output (if `input` is
111 `None`), or a new CHAINED collection created to include all inputs
112 (if `input` is not `None`). In both cases, the collection's children
113 will start with an output RUN collection that directly holds all new
114 datasets (see `output_run`).
115 output_run : `str`
116 Name of the new output RUN collection. If not provided then `output`
117 must be provided and a new RUN collection will be created by appending
118 a timestamp to the value passed with `output`. If this collection
119 already exists then `extend_run` must be passed.
120 extend_run : `bool`
121 Instead of creating a new RUN collection, insert datasets into either
122 the one given by `output_run` (if provided) or the first child
123 collection of `output` (which must be of type RUN).
124 replace_run : `bool`
125 Before creating a new RUN collection in an existing CHAINED collection,
126 remove the first child collection (which must be of type RUN). This can
127 be used to repeatedly write to the same (parent) collection during
128 development, but it does not delete the datasets associated with the
129 replaced run unless `prune-replaced` is also True. Requires `output`,
130 and `extend_run` must be `None`.
131 prune_replaced : `str` or `None`
132 If not `None`, delete the datasets in the collection replaced by
133 `replace_run`, either just from the datastore ("unstore") or by
134 removing them and the RUN completely ("purge"). Requires
135 ``replace_run`` to be `True`.
136 data_query : `str`
137 User query selection expression.
138 show : `lsst.ctrl.mpexec.showInfo.ShowInfo`
139 Descriptions of what to dump to stdout.
140 save_execution_butler : `str` or `None`
141 URI location for storing an execution Butler build from the
142 QuantumGraph.
143 clobber_execution_butler : `bool`
144 It True overwrite existing execution butler files if present.
145 target_datastore_root : `str` or `None`
146 URI location for the execution butler's datastore.
147 transfer : `str` or `None`
148 Transfer mode for execution butler creation. This should be a
149 ``transfer`` string recognized by
150 :func:`lsst.resources.ResourcePath.transfer_from`.
151 clobber_outputs : `bool`
152 Remove outputs from previous execution of the same quantum before new
153 execution. If ``skip_existing`` is also passed, then only failed
154 quanta will be clobbered.
155 dataset_query_constraint : `str`
156 Control constraining graph building using pre-existing dataset types.
157 Valid values are off, all, or a comma separated list of dataset type
158 names.
159 show_qgraph_header : bool, optional
160 Controls if the headerData of a QuantumGraph should be printed to the
161 terminal. Defaults to False.
162 mock : `bool`, optional
163 If True, use a mocked version of the pipeline.
164 unmocked_dataset_types : `collections.abc.Sequence` [ `str` ], optional
165 List of overall-input dataset types that should not be mocked.
166 mock_failure : `~collections.abc.Sequence`, optional
167 List of quanta that should raise exceptions.
168 kwargs : `dict` [`str`, `str`]
169 Ignored; click commands may accept options for more than one script
170 function and pass all the option kwargs to each of the script functions
171 which ignore these unused kwargs.
173 Returns
174 -------
175 qgraph : `lsst.pipe.base.QuantumGraph`
176 The qgraph object that was created.
177 """
178 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint)
179 args = SimpleNamespace(
180 qgraph=qgraph,
181 qgraph_id=qgraph_id,
182 qgraph_node_id=qgraph_node_id,
183 qgraph_datastore_records=qgraph_datastore_records,
184 save_qgraph=save_qgraph,
185 save_single_quanta=save_single_quanta,
186 qgraph_dot=qgraph_dot,
187 butler_config=butler_config,
188 input=input,
189 output=output,
190 output_run=output_run,
191 extend_run=extend_run,
192 replace_run=replace_run,
193 prune_replaced=prune_replaced,
194 data_query=data_query,
195 skip_existing_in=skip_existing_in,
196 skip_existing=skip_existing,
197 execution_butler_location=save_execution_butler,
198 clobber_execution_butler=clobber_execution_butler,
199 target_datastore_root=target_datastore_root,
200 transfer=transfer,
201 clobber_outputs=clobber_outputs,
202 dataset_query_constraint=dataset_query_constraint,
203 show_qgraph_header=show_qgraph_header,
204 mock=mock,
205 unmocked_dataset_types=list(unmocked_dataset_types),
206 mock_failure=mock_failure,
207 )
209 f = CmdLineFwk()
210 qgraph = f.makeGraph(pipelineObj, args)
212 if qgraph is None:
213 return None
215 # optionally dump some info.
216 show.show_graph_info(qgraph, args)
218 return qgraph