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

11 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-22 09:52 +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 ... import CmdLineFwk, TaskFactory 

26 

27_log = logging.getLogger(__name__) 

28 

29 

30def run( # type: ignore 

31 pdb, 

32 graph_fixup, 

33 init_only, 

34 no_versions, 

35 processes, 

36 start_method, 

37 profile, 

38 qgraphObj, 

39 register_dataset_types, 

40 skip_init_writes, 

41 timeout, 

42 butler_config, 

43 input, 

44 output, 

45 output_run, 

46 extend_run, 

47 replace_run, 

48 prune_replaced, 

49 data_query, 

50 skip_existing_in, 

51 skip_existing, 

52 debug, 

53 fail_fast, 

54 clobber_outputs, 

55 summary, 

56 mock, 

57 unmocked_dataset_types, 

58 mock_failure, 

59 enable_implicit_threading, 

60 **kwargs, 

61): 

62 """Implement the command line interface `pipetask run` subcommand. 

63 

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

65 this function. 

66 

67 Parameters 

68 ---------- 

69 pdb : `bool` 

70 Drop into pdb on exception? 

71 graph_fixup : `str` 

72 The name of the class or factory method which makes an instance used 

73 for execution graph fixup. 

74 init_only : `bool` 

75 If true, do not actually run; just register dataset types and/or save 

76 init outputs. 

77 no_versions : `bool` 

78 If true, do not save or check package versions. 

79 processes : `int` 

80 The number of processes to use. 

81 start_method : `str` or `None` 

82 Start method from `multiprocessing` module, `None` selects the best 

83 one for current platform. 

84 profile : `str` 

85 File name to dump cProfile information to. 

86 qgraphObj : `lsst.pipe.base.QuantumGraph` 

87 A QuantumGraph generated by a previous subcommand. 

88 register_dataset_types : `bool` 

89 If true, register DatasetTypes that do not already exist in the 

90 Registry. 

91 skip_init_writes : `bool` 

92 If true, do not write collection-wide 'init output' datasets (e.g. 

93 schemas). 

94 timeout : `int` 

95 Timeout for multiprocessing; maximum wall time (sec). 

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

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

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

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

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

101 input : `list` [ `str` ] 

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

103 output : `str` 

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

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

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

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

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

109 datasets (see `output_run`). 

110 output_run : `str` 

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

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

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

114 already exists then `extend_run` must be passed. 

115 extend_run : `bool` 

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

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

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

119 replace_run : `bool` 

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

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

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

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

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

125 and `extend_run` must be `None`. 

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

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

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

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

130 data_query : `str` 

131 User query selection expression. 

132 skip_existing_in : `list` [ `str` ] 

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

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

135 from the QuantumGraph. 

136 skip_existing : `bool` 

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

138 debug : `bool` 

139 If true, enable debugging output using lsstDebug facility (imports 

140 debug.py). 

141 fail_fast : `bool` 

142 If true then stop processing at first error, otherwise process as many 

143 tasks as possible. 

144 clobber_outputs : `bool` 

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

146 execution. Only applies to failed quanta if skip_existing is also 

147 given. 

148 summary : `str` 

149 File path to store job report in JSON format. 

150 mock : `bool`, optional 

151 If `True` then run mock pipeline instead of real one. Ignored if an 

152 existing QuantumGraph is provided. 

153 unmocked_dataset_types : `collections.abc.Sequence` [ `str` ] 

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

155 Ignored if an existing QuantumGraph is provided. 

156 mock_failure : `~collections.abc.Sequence`, optional 

157 List of quanta that should raise exceptions. 

158 enable_implicit_threading : `bool`, optional 

159 If `True`, do not disable implicit threading by third-party libraries. 

160 Implicit threading is always disabled during actual quantum execution 

161 if ``processes > 1``. 

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

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

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

165 which ignore these unused kwargs. 

166 """ 

167 args = SimpleNamespace( 

168 pdb=pdb, 

169 graph_fixup=graph_fixup, 

170 init_only=init_only, 

171 no_versions=no_versions, 

172 processes=processes, 

173 start_method=start_method, 

174 profile=profile, 

175 skip_init_writes=skip_init_writes, 

176 timeout=timeout, 

177 register_dataset_types=register_dataset_types, 

178 butler_config=butler_config, 

179 input=input, 

180 output=output, 

181 output_run=output_run, 

182 extend_run=extend_run, 

183 replace_run=replace_run, 

184 prune_replaced=prune_replaced, 

185 data_query=data_query, 

186 skip_existing_in=skip_existing_in, 

187 skip_existing=skip_existing, 

188 enableLsstDebug=debug, 

189 fail_fast=fail_fast, 

190 clobber_outputs=clobber_outputs, 

191 summary=summary, 

192 # Mock options only used by qgraph. 

193 enable_implicit_threading=enable_implicit_threading, 

194 ) 

195 

196 f = CmdLineFwk() 

197 taskFactory = TaskFactory() 

198 

199 # If we have no output run specified, use the one from the graph rather 

200 # than letting a new timestamped run be created. 

201 if not args.output_run and qgraphObj.metadata and (output_run := qgraphObj.metadata.get("output_run")): 

202 args.output_run = output_run 

203 

204 f.runPipeline(qgraphObj, taskFactory, args)