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

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-11 09:04 +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/>. 

21 

22import logging 

23from types import SimpleNamespace 

24 

25from lsst.pipe.base.graphBuilder import DatasetQueryConstraintVariant 

26 

27from ... import CmdLineFwk 

28 

29_log = logging.getLogger(__name__) 

30 

31 

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 **kwargs, 

62): 

63 """Implement the command line interface `pipetask qgraph` subcommand. 

64 

65 Should only be called by command line tools and unit test code that test 

66 this function. 

67 

68 Parameters 

69 ---------- 

70 pipelineObj : `lsst.pipe.base.Pipeline` or None. 

71 The pipeline object used to generate a qgraph. If this is not `None` 

72 then `qgraph` should be `None`. 

73 qgraph : `str` or `None` 

74 URI location for a serialized quantum graph definition as a pickle 

75 file. If this option is not None then `pipeline` should be `None`. 

76 qgraph_id : `str` or `None` 

77 Quantum graph identifier, if specified must match the identifier of the 

78 graph loaded from a file. Ignored if graph is not loaded from a file. 

79 qgraph_node_id : `list` of `int`, optional 

80 Only load a specified set of nodes if graph is loaded from a file, 

81 nodes are identified by integer IDs. 

82 qgraph_datastore_records : `bool` 

83 If True then include datastore records into generated quanta. 

84 skip_existing_in : `list` [ `str` ] 

85 Accepts list of collections, if all Quantum outputs already exist in 

86 the specified list of collections then that Quantum will be excluded 

87 from the QuantumGraph. 

88 skip_existing : `bool` 

89 Appends output RUN collection to the ``skip_existing_in`` list. 

90 save_qgraph : `str` or `None` 

91 URI location for storing a serialized quantum graph definition as a 

92 pickle file. 

93 save_single_quanta : `str` or `None` 

94 Format string of URI locations for storing individual quantum graph 

95 definition (pickle files). The curly brace {} in the input string will 

96 be replaced by a quantum number. 

97 qgraph_dot : `str` or `None` 

98 Path location for storing GraphViz DOT representation of a quantum 

99 graph. 

100 butler_config : `str`, `dict`, or `lsst.daf.butler.Config` 

101 If `str`, `butler_config` is the path location of the gen3 

102 butler/registry config file. If `dict`, `butler_config` is key value 

103 pairs used to init or update the `lsst.daf.butler.Config` instance. If 

104 `Config`, it is the object used to configure a Butler. 

105 input : `list` [ `str` ] 

106 List of names of the input collection(s). 

107 output : `str` 

108 Name of the output CHAINED collection. This may either be an existing 

109 CHAINED collection to use as both input and output (if `input` is 

110 `None`), or a new CHAINED collection created to include all inputs 

111 (if `input` is not `None`). In both cases, the collection's children 

112 will start with an output RUN collection that directly holds all new 

113 datasets (see `output_run`). 

114 output_run : `str` 

115 Name of the new output RUN collection. If not provided then `output` 

116 must be provided and a new RUN collection will be created by appending 

117 a timestamp to the value passed with `output`. If this collection 

118 already exists then `extend_run` must be passed. 

119 extend_run : `bool` 

120 Instead of creating a new RUN collection, insert datasets into either 

121 the one given by `output_run` (if provided) or the first child 

122 collection of `output` (which must be of type RUN). 

123 replace_run : `bool` 

124 Before creating a new RUN collection in an existing CHAINED collection, 

125 remove the first child collection (which must be of type RUN). This can 

126 be used to repeatedly write to the same (parent) collection during 

127 development, but it does not delete the datasets associated with the 

128 replaced run unless `prune-replaced` is also True. Requires `output`, 

129 and `extend_run` must be `None`. 

130 prune_replaced : `str` or `None` 

131 If not `None`, delete the datasets in the collection replaced by 

132 `replace_run`, either just from the datastore ("unstore") or by 

133 removing them and the RUN completely ("purge"). Requires 

134 ``replace_run`` to be `True`. 

135 data_query : `str` 

136 User query selection expression. 

137 show : `lsst.ctrl.mpexec.showInfo.ShowInfo` 

138 Descriptions of what to dump to stdout. 

139 save_execution_butler : `str` or `None` 

140 URI location for storing an execution Butler build from the 

141 QuantumGraph. 

142 clobber_execution_butler : `bool` 

143 It True overwrite existing execution butler files if present. 

144 target_datastore_root : `str` or `None` 

145 URI location for the execution butler's datastore. 

146 transfer : `str` or `None` 

147 Transfer mode for execution butler creation. This should be a 

148 ``transfer`` string recognized by 

149 :func:`lsst.resources.ResourcePath.transfer_from`. 

150 clobber_outputs : `bool` 

151 Remove outputs from previous execution of the same quantum before new 

152 execution. If ``skip_existing`` is also passed, then only failed 

153 quanta will be clobbered. 

154 dataset_query_constraint : `str` 

155 Control constraining graph building using pre-existing dataset types. 

156 Valid values are off, all, or a comma separated list of dataset type 

157 names. 

158 show_qgraph_header : bool, optional 

159 Controls if the headerData of a QuantumGraph should be printed to the 

160 terminal. Defaults to False. 

161 mock : `bool`, optional 

162 If True, use a mocked version of the pipeline. 

163 unmocked_dataset_types : `collections.abc.Sequence` [ `str` ], optional 

164 List of overall-input dataset types that should not be mocked. 

165 kwargs : `dict` [`str`, `str`] 

166 Ignored; click commands may accept options for more than one script 

167 function and pass all the option kwargs to each of the script functions 

168 which ignore these unused kwargs. 

169 

170 Returns 

171 ------- 

172 qgraph : `lsst.pipe.base.QuantumGraph` 

173 The qgraph object that was created. 

174 """ 

175 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

176 args = SimpleNamespace( 

177 qgraph=qgraph, 

178 qgraph_id=qgraph_id, 

179 qgraph_node_id=qgraph_node_id, 

180 qgraph_datastore_records=qgraph_datastore_records, 

181 save_qgraph=save_qgraph, 

182 save_single_quanta=save_single_quanta, 

183 qgraph_dot=qgraph_dot, 

184 butler_config=butler_config, 

185 input=input, 

186 output=output, 

187 output_run=output_run, 

188 extend_run=extend_run, 

189 replace_run=replace_run, 

190 prune_replaced=prune_replaced, 

191 data_query=data_query, 

192 skip_existing_in=skip_existing_in, 

193 skip_existing=skip_existing, 

194 execution_butler_location=save_execution_butler, 

195 clobber_execution_butler=clobber_execution_butler, 

196 target_datastore_root=target_datastore_root, 

197 transfer=transfer, 

198 clobber_outputs=clobber_outputs, 

199 dataset_query_constraint=dataset_query_constraint, 

200 show_qgraph_header=show_qgraph_header, 

201 mock=mock, 

202 unmocked_dataset_types=list(unmocked_dataset_types), 

203 ) 

204 

205 f = CmdLineFwk() 

206 qgraph = f.makeGraph(pipelineObj, args) 

207 

208 if qgraph is None: 

209 return None 

210 

211 # optionally dump some info. 

212 show.show_graph_info(qgraph, args) 

213 

214 return qgraph