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