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

14 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-06 02:03 -0800

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

60): 

61 """Implements the command line interface `pipetask qgraph` subcommand, 

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

63 this function. 

64 

65 Parameters 

66 ---------- 

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

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

69 then `qgraph` should be `None`. 

70 qgraph : `str` or `None` 

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

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

73 qgraph_id : `str` or `None` 

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

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

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

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

78 nodes are identified by integer IDs. 

79 qgraph_datastore_records : `bool` 

80 If True then include datastore records into generated quanta. 

81 skip_existing_in : `list` [ `str` ] 

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

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

84 from the QuantumGraph. 

85 skip_existing : `bool` 

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

87 save_qgraph : `str` or `None` 

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

89 pickle file. 

90 save_single_quanta : `str` or `None` 

91 Format string of URI locations for storing individual quantum graph 

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

93 be replaced by a quantum number. 

94 qgraph_dot : `str` or `None` 

95 Path location for storing GraphViz DOT representation of a quantum 

96 graph. 

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

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

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

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

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

102 input : `list` [ `str` ] 

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

104 output : `str` 

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

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

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

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

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

110 datasets (see `output_run`). 

111 output_run : `str` 

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

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

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

115 already exists then `extend_run` must be passed. 

116 extend_run : `bool` 

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

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

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

120 replace_run : `bool` 

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

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

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

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

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

126 and `extend_run` must be `None`. 

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

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

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

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

131 data_query : `str` 

132 User query selection expression. 

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

134 Descriptions of what to dump to stdout. 

135 save_execution_butler : `str` or `None` 

136 URI location for storing an execution Butler build from the 

137 QuantumGraph. 

138 clobber_execution_butler : `bool` 

139 It True overwrite existing execution butler files if present. 

140 target_datastore_root : `str` or `None` 

141 URI location for the execution butler's datastore. 

142 transfer : `str` or `None` 

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

144 ``transfer`` string recognized by 

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

146 clobber_outputs : `bool` 

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

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

149 quanta will be clobbered. 

150 dataset_query_constraint : `str` 

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

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

153 names. 

154 show_qgraph_header : bool, optional 

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

156 terminal. Defaults to False. 

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

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

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

160 which ingore these unused kwargs. 

161 

162 Returns 

163 ------- 

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

165 The qgraph object that was created. 

166 """ 

167 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

168 args = SimpleNamespace( 

169 qgraph=qgraph, 

170 qgraph_id=qgraph_id, 

171 qgraph_node_id=qgraph_node_id, 

172 qgraph_datastore_records=qgraph_datastore_records, 

173 save_qgraph=save_qgraph, 

174 save_single_quanta=save_single_quanta, 

175 qgraph_dot=qgraph_dot, 

176 butler_config=butler_config, 

177 input=input, 

178 output=output, 

179 output_run=output_run, 

180 extend_run=extend_run, 

181 replace_run=replace_run, 

182 prune_replaced=prune_replaced, 

183 data_query=data_query, 

184 skip_existing_in=skip_existing_in, 

185 skip_existing=skip_existing, 

186 execution_butler_location=save_execution_butler, 

187 clobber_execution_butler=clobber_execution_butler, 

188 target_datastore_root=target_datastore_root, 

189 transfer=transfer, 

190 clobber_outputs=clobber_outputs, 

191 dataset_query_constraint=dataset_query_constraint, 

192 show_qgraph_header=show_qgraph_header, 

193 ) 

194 

195 f = CmdLineFwk() 

196 qgraph = f.makeGraph(pipelineObj, args) 

197 

198 if qgraph is None: 

199 return None 

200 

201 # optionally dump some info. 

202 show.show_graph_info(qgraph, args) 

203 

204 return qgraph