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

38 skip_existing, 

39 save_qgraph, 

40 save_single_quanta, 

41 qgraph_dot, 

42 butler_config, 

43 input, 

44 output, 

45 output_run, 

46 extend_run, 

47 replace_run, 

48 prune_replaced, 

49 data_query, 

50 show, 

51 save_execution_butler, 

52 clobber_execution_butler, 

53 clobber_outputs, 

54 dataset_query_constraint, 

55 show_qgraph_header=False, 

56 **kwargs, 

57): 

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

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

60 this function. 

61 

62 Parameters 

63 ---------- 

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

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

66 then `qgraph` should be `None`. 

67 qgraph : `str` or `None` 

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

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

70 qgraph_id : `str` or `None` 

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

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

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

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

75 nodes are identified by integer IDs. 

76 skip_existing_in : `list` [ `str` ] 

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

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

79 from the QuantumGraph. 

80 skip_existing : `bool` 

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

82 save_qgraph : `str` or `None` 

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

84 pickle file. 

85 save_single_quanta : `str` or `None` 

86 Format string of URI locations for storing individual quantum graph 

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

88 be replaced by a quantum number. 

89 qgraph_dot : `str` or `None` 

90 Path location for storing GraphViz DOT representation of a quantum 

91 graph. 

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

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

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

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

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

97 input : `list` [ `str` ] 

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

99 output : `str` 

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

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

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

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

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

105 datasets (see `output_run`). 

106 output_run : `str` 

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

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

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

110 already exists then `extend_run` must be passed. 

111 extend_run : `bool` 

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

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

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

115 replace_run : `bool` 

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

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

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

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

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

121 and `extend_run` must be `None`. 

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

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

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

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

126 data_query : `str` 

127 User query selection expression. 

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

129 Descriptions of what to dump to stdout. 

130 save_execution_butler : `str` or `None` 

131 URI location for storing an execution Butler build from the 

132 QuantumGraph. 

133 clobber_execution_butler : `bool` 

134 It True overwrite existing execution butler files if present. 

135 clobber_outputs : `bool` 

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

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

138 quanta will be clobbered. 

139 dataset_query_constraint : `str` 

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

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

142 names. 

143 show_qgraph_header : bool, optional 

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

145 terminal. Defaults to False. 

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

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

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

149 which ingore these unused kwargs. 

150 

151 Returns 

152 ------- 

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

154 The qgraph object that was created. 

155 """ 

156 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

157 args = SimpleNamespace( 

158 qgraph=qgraph, 

159 qgraph_id=qgraph_id, 

160 qgraph_node_id=qgraph_node_id, 

161 save_qgraph=save_qgraph, 

162 save_single_quanta=save_single_quanta, 

163 qgraph_dot=qgraph_dot, 

164 butler_config=butler_config, 

165 input=input, 

166 output=output, 

167 output_run=output_run, 

168 extend_run=extend_run, 

169 replace_run=replace_run, 

170 prune_replaced=prune_replaced, 

171 data_query=data_query, 

172 show=show, 

173 skip_existing_in=skip_existing_in, 

174 skip_existing=skip_existing, 

175 execution_butler_location=save_execution_butler, 

176 clobber_execution_butler=clobber_execution_butler, 

177 clobber_outputs=clobber_outputs, 

178 dataset_query_constraint=dataset_query_constraint, 

179 show_qgraph_header=show_qgraph_header, 

180 ) 

181 

182 f = CmdLineFwk() 

183 qgraph = f.makeGraph(pipelineObj, args) 

184 

185 if qgraph is None: 

186 raise RuntimeError("QuantumGraph is empty.") 

187 

188 # optionally dump some info. 

189 if show: 

190 f.showInfo(args, pipelineObj, qgraph) 

191 

192 return qgraph