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

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

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( 

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 clobber_outputs, 

55 dataset_query_constraint, 

56 show_qgraph_header=False, 

57 **kwargs, 

58): 

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

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

61 this function. 

62 

63 Parameters 

64 ---------- 

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

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

67 then `qgraph` should be `None`. 

68 qgraph : `str` or `None` 

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

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

71 qgraph_id : `str` or `None` 

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

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

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

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

76 nodes are identified by integer IDs. 

77 qgraph_datastore_records : `bool` 

78 If True then include datastore records into generated quanta. 

79 skip_existing_in : `list` [ `str` ] 

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

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

82 from the QuantumGraph. 

83 skip_existing : `bool` 

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

85 save_qgraph : `str` or `None` 

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

87 pickle file. 

88 save_single_quanta : `str` or `None` 

89 Format string of URI locations for storing individual quantum graph 

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

91 be replaced by a quantum number. 

92 qgraph_dot : `str` or `None` 

93 Path location for storing GraphViz DOT representation of a quantum 

94 graph. 

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

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

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

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

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

100 input : `list` [ `str` ] 

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

102 output : `str` 

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

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

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

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

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

108 datasets (see `output_run`). 

109 output_run : `str` 

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

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

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

113 already exists then `extend_run` must be passed. 

114 extend_run : `bool` 

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

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

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

118 replace_run : `bool` 

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

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

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

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

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

124 and `extend_run` must be `None`. 

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

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

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

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

129 data_query : `str` 

130 User query selection expression. 

131 show : `list` [`str`] or `None` 

132 Descriptions of what to dump to stdout. 

133 save_execution_butler : `str` or `None` 

134 URI location for storing an execution Butler build from the 

135 QuantumGraph. 

136 clobber_execution_butler : `bool` 

137 It True overwrite existing execution butler files if present. 

138 clobber_outputs : `bool` 

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

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

141 quanta will be clobbered. 

142 dataset_query_constraint : `str` 

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

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

145 names. 

146 show_qgraph_header : bool, optional 

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

148 terminal. Defaults to False. 

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

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

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

152 which ingore these unused kwargs. 

153 

154 Returns 

155 ------- 

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

157 The qgraph object that was created. 

158 """ 

159 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

160 args = SimpleNamespace( 

161 qgraph=qgraph, 

162 qgraph_id=qgraph_id, 

163 qgraph_node_id=qgraph_node_id, 

164 qgraph_datastore_records=qgraph_datastore_records, 

165 save_qgraph=save_qgraph, 

166 save_single_quanta=save_single_quanta, 

167 qgraph_dot=qgraph_dot, 

168 butler_config=butler_config, 

169 input=input, 

170 output=output, 

171 output_run=output_run, 

172 extend_run=extend_run, 

173 replace_run=replace_run, 

174 prune_replaced=prune_replaced, 

175 data_query=data_query, 

176 show=show, 

177 skip_existing_in=skip_existing_in, 

178 skip_existing=skip_existing, 

179 execution_butler_location=save_execution_butler, 

180 clobber_execution_butler=clobber_execution_butler, 

181 clobber_outputs=clobber_outputs, 

182 dataset_query_constraint=dataset_query_constraint, 

183 show_qgraph_header=show_qgraph_header, 

184 ) 

185 

186 f = CmdLineFwk() 

187 qgraph = f.makeGraph(pipelineObj, args) 

188 

189 if qgraph is None: 

190 raise RuntimeError("QuantumGraph is empty.") 

191 

192 # optionally dump some info. 

193 if show: 

194 f.showInfo(args, pipelineObj, qgraph) 

195 

196 return qgraph