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 ... import CmdLineFwk 

26 

27from lsst.pipe.base.graphBuilder import DatasetQueryConstraintVariant 

28 

29_log = logging.getLogger(__name__.partition(".")[2]) 

30 

31 

32def qgraph(pipelineObj, qgraph, qgraph_id, qgraph_node_id, skip_existing_in, skip_existing, save_qgraph, 

33 save_single_quanta, qgraph_dot, butler_config, input, output, output_run, extend_run, 

34 replace_run, prune_replaced, data_query, show, save_execution_butler, clobber_execution_butler, 

35 clobber_outputs, dataset_query_constraint, **kwargs): 

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

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

38 this function. 

39 

40 Parameters 

41 ---------- 

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

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

44 then `qgraph` should be `None`. 

45 qgraph : `str` or `None` 

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

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

48 qgraph_id : `str` or `None` 

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

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

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

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

53 nodes are identified by integer IDs. 

54 skip_existing_in : `list` [ `str` ] 

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

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

57 from the QuantumGraph. 

58 skip_existing : `bool` 

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

60 save_qgraph : `str` or `None` 

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

62 pickle file. 

63 save_single_quanta : `str` or `None` 

64 Format string of URI locations for storing individual quantum graph 

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

66 be replaced by a quantum number. 

67 qgraph_dot : `str` or `None` 

68 Path location for storing GraphViz DOT representation of a quantum 

69 graph. 

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

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

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

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

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

75 input : `list` [ `str` ] 

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

77 output : `str` 

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

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

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

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

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

83 datasets (see `output_run`). 

84 output_run : `str` 

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

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

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

88 already exists then `extend_run` must be passed. 

89 extend_run : `bool` 

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

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

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

93 replace_run : `bool` 

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

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

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

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

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

99 and `extend_run` must be `None`. 

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

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

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

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

104 data_query : `str` 

105 User query selection expression. 

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

107 Descriptions of what to dump to stdout. 

108 save_execution_butler : `str` or `None` 

109 URI location for storing an execution Butler build from the 

110 QuantumGraph. 

111 clobber_execution_butler : `bool` 

112 It True overwrite existing execution butler files if present. 

113 clobber_outputs : `bool` 

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

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

116 quanta will be clobbered. 

117 dataset_query_constraint : `str` 

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

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

120 names. 

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

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

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

124 which ingore these unused kwargs. 

125 

126 Returns 

127 ------- 

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

129 The qgraph object that was created. 

130 """ 

131 dataset_query_constraint = DatasetQueryConstraintVariant.fromExpression(dataset_query_constraint) 

132 args = SimpleNamespace(qgraph=qgraph, 

133 qgraph_id=qgraph_id, 

134 qgraph_node_id=qgraph_node_id, 

135 save_qgraph=save_qgraph, 

136 save_single_quanta=save_single_quanta, 

137 qgraph_dot=qgraph_dot, 

138 butler_config=butler_config, 

139 input=input, 

140 output=output, 

141 output_run=output_run, 

142 extend_run=extend_run, 

143 replace_run=replace_run, 

144 prune_replaced=prune_replaced, 

145 data_query=data_query, 

146 show=show, 

147 skip_existing_in=skip_existing_in, 

148 skip_existing=skip_existing, 

149 execution_butler_location=save_execution_butler, 

150 clobber_execution_butler=clobber_execution_butler, 

151 clobber_outputs=clobber_outputs, 

152 dataset_query_constraint=dataset_query_constraint, 

153 ) 

154 

155 f = CmdLineFwk() 

156 qgraph = f.makeGraph(pipelineObj, args) 

157 

158 if qgraph is None: 

159 raise RuntimeError("QuantumGraph is empty.") 

160 

161 # optionally dump some info. 

162 if show: 

163 f.showInfo(args, pipelineObj, qgraph) 

164 

165 return qgraph