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-09 02:48 -0700

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 """Implements the command line interface `pipetask qgraph` subcommand, 

64 should only be called by command line tools and unit test code that test 

65 this function. 

66 

67 Parameters 

68 ---------- 

69 pipelineObj : `pipe.base.Pipeline` or None. 

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

71 then `qgraph` should be `None`. 

72 qgraph : `str` or `None` 

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

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

75 qgraph_id : `str` or `None` 

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

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

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

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

80 nodes are identified by integer IDs. 

81 qgraph_datastore_records : `bool` 

82 If True then include datastore records into generated quanta. 

83 skip_existing_in : `list` [ `str` ] 

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

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

86 from the QuantumGraph. 

87 skip_existing : `bool` 

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

89 save_qgraph : `str` or `None` 

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

91 pickle file. 

92 save_single_quanta : `str` or `None` 

93 Format string of URI locations for storing individual quantum graph 

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

95 be replaced by a quantum number. 

96 qgraph_dot : `str` or `None` 

97 Path location for storing GraphViz DOT representation of a quantum 

98 graph. 

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

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

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

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

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

104 input : `list` [ `str` ] 

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

106 output : `str` 

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

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

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

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

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

112 datasets (see `output_run`). 

113 output_run : `str` 

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

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

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

117 already exists then `extend_run` must be passed. 

118 extend_run : `bool` 

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

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

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

122 replace_run : `bool` 

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

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

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

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

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

128 and `extend_run` must be `None`. 

129 prune_replaced : "unstore", "purge", or `None`. 

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

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

132 removing them and the RUN completely ("purge"). Requires `replace_run`. 

133 data_query : `str` 

134 User query selection expression. 

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

136 Descriptions of what to dump to stdout. 

137 save_execution_butler : `str` or `None` 

138 URI location for storing an execution Butler build from the 

139 QuantumGraph. 

140 clobber_execution_butler : `bool` 

141 It True overwrite existing execution butler files if present. 

142 target_datastore_root : `str` or `None` 

143 URI location for the execution butler's datastore. 

144 transfer : `str` or `None` 

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

146 ``transfer`` string recognized by 

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

148 clobber_outputs : `bool` 

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

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

151 quanta will be clobbered. 

152 dataset_query_constraint : `str` 

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

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

155 names. 

156 show_qgraph_header : bool, optional 

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

158 terminal. Defaults to False. 

159 mock : `bool`, optional 

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

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

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

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

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

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

166 which ingore these unused kwargs. 

167 

168 Returns 

169 ------- 

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

171 The qgraph object that was created. 

172 """ 

173 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

174 args = SimpleNamespace( 

175 qgraph=qgraph, 

176 qgraph_id=qgraph_id, 

177 qgraph_node_id=qgraph_node_id, 

178 qgraph_datastore_records=qgraph_datastore_records, 

179 save_qgraph=save_qgraph, 

180 save_single_quanta=save_single_quanta, 

181 qgraph_dot=qgraph_dot, 

182 butler_config=butler_config, 

183 input=input, 

184 output=output, 

185 output_run=output_run, 

186 extend_run=extend_run, 

187 replace_run=replace_run, 

188 prune_replaced=prune_replaced, 

189 data_query=data_query, 

190 skip_existing_in=skip_existing_in, 

191 skip_existing=skip_existing, 

192 execution_butler_location=save_execution_butler, 

193 clobber_execution_butler=clobber_execution_butler, 

194 target_datastore_root=target_datastore_root, 

195 transfer=transfer, 

196 clobber_outputs=clobber_outputs, 

197 dataset_query_constraint=dataset_query_constraint, 

198 show_qgraph_header=show_qgraph_header, 

199 mock=mock, 

200 unmocked_dataset_types=list(unmocked_dataset_types), 

201 ) 

202 

203 f = CmdLineFwk() 

204 qgraph = f.makeGraph(pipelineObj, args) 

205 

206 if qgraph is None: 

207 return None 

208 

209 # optionally dump some info. 

210 show.show_graph_info(qgraph, args) 

211 

212 return qgraph