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

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

13 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 

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

28 

29 

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

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

32 replace_run, prune_replaced, data_query, show, save_execution_butler, clobber_execution_butler, 

33 clobber_outputs, **kwargs): 

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

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

36 this function. 

37 

38 Parameters 

39 ---------- 

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

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

42 then `qgraph` should be `None`. 

43 qgraph : `str` or `None` 

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

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

46 qgraph_id : `str` or `None` 

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

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

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

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

51 nodes are identified by integer IDs. 

52 skip_existing_in : `list` [ `str` ] 

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

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

55 from the QuantumGraph. 

56 skip_existing : `bool` 

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

58 save_qgraph : `str` or `None` 

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

60 pickle file. 

61 save_single_quanta : `str` or `None` 

62 Format string of URI locations for storing individual quantum graph 

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

64 be replaced by a quantum number. 

65 qgraph_dot : `str` or `None` 

66 Path location for storing GraphViz DOT representation of a quantum 

67 graph. 

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

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

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

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

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

73 input : `list` [ `str` ] 

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

75 output : `str` 

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

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

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

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

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

81 datasets (see `output_run`). 

82 output_run : `str` 

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

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

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

86 already exists then `extend_run` must be passed. 

87 extend_run : `bool` 

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

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

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

91 replace_run : `bool` 

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

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

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

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

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

97 and `extend_run` must be `None`. 

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

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

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

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

102 data_query : `str` 

103 User query selection expression. 

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

105 Descriptions of what to dump to stdout. 

106 save_execution_butler : `str` or `None` 

107 URI location for storing an execution Butler build from the 

108 QuantumGraph. 

109 clobber_execution_butler : `bool` 

110 It True overwrite existing execution butler files if present. 

111 clobber_outputs : `bool` 

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

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

114 quanta will be clobbered. 

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

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

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

118 which ingore these unused kwargs. 

119 

120 Returns 

121 ------- 

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

123 The qgraph object that was created. 

124 """ 

125 args = SimpleNamespace(qgraph=qgraph, 

126 qgraph_id=qgraph_id, 

127 qgraph_node_id=qgraph_node_id, 

128 save_qgraph=save_qgraph, 

129 save_single_quanta=save_single_quanta, 

130 qgraph_dot=qgraph_dot, 

131 butler_config=butler_config, 

132 input=input, 

133 output=output, 

134 output_run=output_run, 

135 extend_run=extend_run, 

136 replace_run=replace_run, 

137 prune_replaced=prune_replaced, 

138 data_query=data_query, 

139 show=show, 

140 skip_existing_in=skip_existing_in, 

141 skip_existing=skip_existing, 

142 execution_butler_location=save_execution_butler, 

143 clobber_execution_butler=clobber_execution_butler, 

144 clobber_outputs=clobber_outputs, 

145 ) 

146 

147 f = CmdLineFwk() 

148 qgraph = f.makeGraph(pipelineObj, args) 

149 

150 if qgraph is None: 

151 raise RuntimeError("QuantumGraph is empty.") 

152 

153 # optionally dump some info. 

154 if show: 

155 f.showInfo(args, pipelineObj, qgraph) 

156 

157 return qgraph