3 # Copyright (C) 2011 Chad Hanna
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 ### This program will make create a HTCondor DAG to automate the running of
20 ### low-latency, online gstlal_inspiral jobs; see gstlal_ll_trigger_pipe
23 This program makes a dag for a gstlal inspiral low latency pipeline
26 __author__ =
'Chad Hanna <channa@caltech.edu>'
29 # import standard modules and append the lalapps prefix to the python path
36 from optparse
import OptionParser
39 # import the modules we need to build the pipeline
42 from gstlal
import inspiral
43 from gstlal
import inspiral_pipe
44 from gstlal
import dagparts
45 from gstlal
import datasource
46 from lal.utils
import CacheEntry
49 # ### Graph of the HTCondor DAG
51 # - gray boxes are optional and depend on the command line given
59 # node [shape=record fontsize=10 fontname="Verdana"];
60 # edge [fontsize=8 fontname="Verdana"];
61 # gstlal_inspiral [URL="\ref gstlal_inspiral"];
62 # gstlal_llcbcsummary [URL="\ref gstlal_llcbcsummary"];
63 # gstlal_llcbcnode [URL="\ref gstlal_llcbcnode"];
64 # gstlal_inspiral_marginalize_likelihoods_online [URL="\ref gstlal_inspiral_marginalize_likelihoods_online"];
72 def set_up_jobs(options):
76 condor_opts = {
"want_graceful_removal":
"True",
"kill_sig":
"15"}
77 if options.singularity_image:
78 condor_opts[
'+SingularityImage'] =
'"{}"'.format(options.singularity_image)
80 inspiral_condor_commands = dagparts.condor_command_dict_from_opts(options.inspiral_condor_command, condor_opts)
81 non_inspiral_condor_commands = dagparts.condor_command_dict_from_opts(options.non_inspiral_condor_command, condor_opts)
82 local_condor_commands = dagparts.condor_command_dict_from_opts(options.local_condor_command, condor_opts)
85 jobs[
'gstlalInspiral'] = dagparts.DAGJob(
'gstlal_inspiral', condor_commands = inspiral_condor_commands)
86 if options.inj_channel_dict:
87 jobs[
'gstlalInspiralInj'] = dagparts.DAGJob(
'gstlal_inspiral', tag_base =
"gstlal_inspiral_inj", condor_commands = inspiral_condor_commands)
89 # A local universe job that will run in a loop marginalizing all of the likelihoods
90 jobs[
'marg'] = dagparts.DAGJob(
'gstlal_inspiral_marginalize_likelihoods_online', condor_commands = non_inspiral_condor_commands)
92 if options.delay_uploads:
93 # event plotter that works in tandem with the event uploader
94 jobs[
'eventPlotter'] = dagparts.DAGJob(
"gstlal_ll_inspiral_event_plotter", condor_commands = non_inspiral_condor_commands)
96 # an lvalert_listen job
97 jobs[
'lvalertListen'] = dagparts.DAGJob(
'gstlal_inspiral_lvalert_uberplotter', universe =
"local", condor_commands = local_condor_commands)
100 jobs[
'agg'] = dagparts.DAGJob(
"scald", tag_base =
"scald_aggregate", condor_commands = non_inspiral_condor_commands)
101 jobs[
'aggLeader'] = dagparts.DAGJob(
"scald", tag_base =
"scald_aggregate_leader", condor_commands = non_inspiral_condor_commands)
102 jobs[
'trigagg'] = dagparts.DAGJob(
"scald", tag_base =
"scald_aggregate_triggers", condor_commands = non_inspiral_condor_commands)
103 jobs[
'trigcount'] = dagparts.DAGJob(
"gstlal_ll_inspiral_trigger_counter", condor_commands = non_inspiral_condor_commands)
106 jobs[
'dq'] = dagparts.DAGJob(
"gstlal_ll_dq", condor_commands = non_inspiral_condor_commands)
109 jobs[
'eventUploader'] = dagparts.DAGJob(
"gstlal_ll_inspiral_event_uploader", condor_commands = non_inspiral_condor_commands)
111 if options.state_backup_destination:
113 jobs[
'state'] = dagparts.DAGJob(
"gstlal_ll_inspiral_save_state", universe =
"local", condor_commands = local_condor_commands)
119 # Parse the command line
123 def parse_command_line():
124 parser = OptionParser(description = __doc__)
126 # append all the datasource specific options
127 datasource.append_options(parser)
129 parser.add_option(
"--analysis-tag", metavar =
"name", help =
"Set the name of the analysis, used to distinguish between different DAGs running simultaneously.")
130 parser.add_option(
"--psd-fft-length", metavar =
"s", default = 32, type =
"int", help =
"FFT length, default 32s. Note that 50% will be used for zero-padding.")
131 parser.add_option(
"--reference-psd", metavar =
"filename", help =
"Set the reference psd file.")
132 parser.add_option(
"--bank-cache", metavar =
"filenames", help =
"Set the bank cache files in format H1=H1.cache,H2=H2.cache, etc..")
133 parser.add_option(
"--min-instruments", metavar =
"count", type =
"int", default = 2, help =
"Set the minimum number of instruments that must contribute triggers to form a candidate (default = 2).")
134 parser.add_option(
"--inj-channel-name", metavar =
"name", default=[], action =
"append", help =
"Set the name of the injection channel to process for given mass bins (optional). 0000:0002:IFO1=CHANNEL-NAME1,IFO2=CHANNEL-NAME2 can be given multiple times.")
135 parser.add_option(
"--inj-state-channel-name", metavar =
"name", default=[], action =
"append", help =
"Set the name of the injection state channel to process (required if --inj-channel-name set).")
136 parser.add_option(
"--inj-dq-channel-name", metavar =
"name", default=[], action =
"append", help =
"Set the name of the injection DQ channel to process (required if --inj-channel-name set).")
137 parser.add_option(
"--inj-framexmit-addr", metavar =
"name", default=[], action =
"append", help =
"Set the framexmit address to process for the injection stream (required if --inj-channel-name set). IFO=ADDR:port can be given multiple times.")
138 parser.add_option(
"--inj-framexmit-iface", metavar =
"name", action =
"append", help =
"Set the interface address to process for injections (required if --inj-channel-name set).")
139 parser.add_option(
"--inj-shared-memory-partition", metavar =
"name", action =
"append", help =
"Set the name of the shared memory partition for a given instrument. Can be given multiple times as --inj-shared-memory-partition=IFO=PARTITION-NAME")
140 parser.add_option(
"--inj-shared-memory-assumed-duration", type =
"int", default = 4, help =
"Set the assumed span of files in seconds. Default = 4.")
141 parser.add_option(
"--inj-shared-memory-block-size", type =
"int", default = 4096, help =
"Set the byte size to read per buffer. Default = 4096.")
142 parser.add_option(
"--ht-gate-threshold", metavar =
"float", help =
"Set the h(t) gate threshold to reject glitches", type=
"float")
143 parser.add_option(
"--ht-gate-threshold-linear", metavar =
"mchirp_min:ht_gate_threshold_min-mchirp_max:ht_gate_threshold_max", type=
"string", help =
"Set the threshold on whitened h(t) to mark samples as gaps (glitch removal) with a linear scale of mchirp")
144 parser.add_option(
"--max-jobs", metavar =
"num", type =
"int", help =
"stop parsing the cache after reaching a certain number of jobs to limit what is submitted to the HTCondor pool")
145 parser.add_option(
"--likelihood-cache", help =
"set the cache containin likelihood files")
146 parser.add_option(
"--zerolag-likelihood-cache", help =
"set the cache containin zerolag likelihood files")
147 parser.add_option(
"--marginalized-likelihood-file", help =
"set the marginalized likelihood file, required")
148 parser.add_option(
"--activation-counts-file", metavar =
"filename", help =
"Set the name of the h5 file containing activation counts for multicomponent p-astro.")
149 parser.add_option(
"--compress-ranking-stat", action =
"store_true", help =
"Choose whether to compress the ranking stat upon start up. Only used when --ranking-stat-input is set.")
150 parser.add_option(
"--compress-ranking-stat-threshold", type =
"float", default = 0.03, help =
"Only keep horizon distance values that differ by this much, fractionally, from their neighbours (default = 0.03).")
151 parser.add_option(
"--control-peak-time", default = 4, metavar =
"secs", help =
"set the control peak time, default 4")
152 parser.add_option(
"--fir-stride", default = 4, metavar =
"secs", help =
"set the fir bank stride, default 4")
153 parser.add_option(
"--gracedb-far-threshold", type =
"float", help =
"false alarm rate threshold for gracedb (Hz), if not given gracedb events are not sent")
154 parser.add_option(
"--gracedb-search", default =
"LowMass", help =
"gracedb type, default LowMass")
155 parser.add_option(
"--gracedb-pipeline", default =
"gstlal", help =
"gracedb type, default gstlal")
156 parser.add_option(
"--gracedb-group", default =
"Test", help =
"gracedb group, default Test")
157 parser.add_option(
"--gracedb-label", action =
"append", help =
"Labels to apply to gracedb uploads. Can be applied multiple times.")
158 parser.add_option(
"--gracedb-service-url", default =
"https://gracedb.ligo.org/api/", help =
"GraceDb service url, default https://gracedb.ligo.org/api/")
159 parser.add_option(
"--lvalert-server-url", default =
"https://lvalert.cgca.uwm.edu", help =
"lvalert server url, default https://lvalert.cgca.uwm.edu")
160 parser.add_option(
"--inj-gracedb-far-threshold", type =
"float", help =
"false alarm rate threshold for gracedb (Hz), if not given gracedb events are not sent (for injection stream)")
161 parser.add_option(
"--inj-gracedb-search", default =
"LowMass", help =
"gracedb type, default LowMass (for injection stream)")
162 parser.add_option(
"--inj-gracedb-pipeline", default =
"gstlal", help =
"gracedb type, default gstlal (for injection stream)")
163 parser.add_option(
"--inj-gracedb-group", default =
"Test", help =
"gracedb group, default Test (for injection stream)")
164 parser.add_option(
"--inj-gracedb-service-url", default =
"https://simdb.cgca.uwm.edu/api/", help =
"GraceDb service url, default https://simdb.cgca.uwm.edu/api/ (for injection stream)")
165 parser.add_option(
"--veto-segments-file", metavar =
"filename", help =
"Set the name of the LIGO light-weight XML file from which to load vetoes (optional).")
166 parser.add_option(
"--veto-segments-name", metavar =
"name", help =
"Set the name of the segments to extract from the segment tables and use as the veto list.", default =
"vetoes")
167 parser.add_option(
"--inj-state-vector-on-bits", metavar =
"name", default = [], action =
"append", help =
"Set the state vector on bits to process (optional). The default is 0x7 for all detectors. Override with IFO=bits can be given multiple times (for injection stream)")
168 parser.add_option(
"--inj-state-vector-off-bits", metavar =
"name", default = [], action =
"append", help =
"Set the state vector off bits to process (optional). The default is 0x160 for all detectors. Override with IFO=bits can be given multiple times (for injection stream)")
169 parser.add_option(
"--inj-dq-vector-on-bits", metavar =
"name", default = [], action =
"append", help =
"Set the DQ vector on bits to process (optional). The default is 0x7 for all detectors. Override with IFO=bits can be given multiple times (for injection stream)")
170 parser.add_option(
"--inj-dq-vector-off-bits", metavar =
"name", default = [], action =
"append", help =
"Set the DQ vector off bits to process (optional). The default is 0x160 for all detectors. Override with IFO=bits can be given multiple times (for injection stream)")
171 parser.add_option(
"--lvalert-listener-program", action =
"append", default = [], metavar =
"program", help =
"set the programs to respond to lvalerts from this analysis, can be given multiple times")
172 parser.add_option(
"--inj-lvalert-listener-program", action =
"append", default = [], metavar =
"program", help =
"set the programs to respond to lvalerts from this analysis, can be given multiple times (for injection stream)")
173 parser.add_option(
"--coincidence-threshold", metavar =
"value", type =
"float", default = 0.005, help =
"Set the coincidence window in seconds (default = 0.005). The light-travel time between instruments will be added automatically in the coincidence test.")
174 parser.add_option(
"--likelihood-snapshot-interval", type =
"float", metavar =
"seconds", help =
"How often to reread the marginalized likelihoood data and snapshot the trigger files.")
175 parser.add_option(
"--non-inspiral-condor-command", action =
"append", default = [], metavar =
"command=value", help =
"set condor commands of the form command=value can be given multiple times")
176 parser.add_option(
"--local-condor-command", action =
"append", default = [], metavar =
"command=value", help =
"set condor commands of the form command=value can be given multiple times")
177 parser.add_option(
"--inspiral-condor-command", action =
"append", default = [], metavar =
"command=value", help =
"set condor commands of the form command=value for inspiral jobs can be given multiple times")
178 parser.add_option(
"--singularity-image", metavar =
"filename", help =
"If set, uses the Singularity image provided as the build environment and sets Singularity-specific condor options.")
179 parser.add_option(
"--injection-file", metavar =
"filename", default = [], action =
"append", help =
"The injection xml files that corresponds to the low latency injections for given mass bins: only used for making missed found plots. 0000:0002:Injection_1.xml, 0002:0004:Injection_2.xml")
180 parser.add_option(
"--state-backup-destination", metavar =
"URL", help =
"Location to back state up to, e.g. gstlalcbc@ldas-pcdev1.ligo.caltech.edu.")
181 parser.add_option(
"--web-dir", help =
"set the output path to write the ''offline'' style web page to")
182 parser.add_option(
"--time-slide-file", metavar =
"filename", help =
"Set the time slide table xml file")
183 parser.add_option(
"--far-trials-factor", metavar =
"trials", type =
"float", default = 1.0, help =
"Add trials factor to FAR before uploading to gracedb")
184 parser.add_option(
"--scald-config", metavar =
"filename", help =
"Set path to a ligo-scald configuration file, used in monitoring/aggregation jobs.")
185 parser.add_option(
"--output-kafka-server", metavar =
"addr", help =
"Set the kafka server hostname to send output data to - note, for now this must be the cluster facing ip address of the submit node. example = 10.14.0.112:9092")
186 parser.add_option(
"--delay-uploads", action =
"store_true", help =
"Choose whether to delay uploads to allow aggregation of events downstream from many gstlal_inspiral jobs (default is False).")
187 parser.add_option(
"--event-aggregator-upload-cadence-type", metavar =
"string", default =
"geometric", help =
"Choose the method [geometric|linear] in which the cadence of subsequent uploads are done. Default = geometric.")
188 parser.add_option(
"--event-aggregator-upload-cadence-factor", type =
"float", default = 4, help =
"Cadence factor T for sending out subsequent events for the same event window. For geometric cadence, first event gets sent T seconds later, second event gets sent T^2 seconds later, etc. For linear cadence, subsequent events get sent T seconds later. Default = 4.0.")
189 parser.add_option(
"--event-aggregator-far-threshold", type =
"float", default = 3.84e-07, help =
"FAR threshold considered for an event to be public, not including a trials factor. Used in the event aggregator if using --delay-uploads. Default = 1 / month.")
190 parser.add_option(
"--event-aggregator-far-trials-factor", type =
"int", default = 1, help =
"Trials factor for number of CBC pipelines uploading events to GraceDB. Used in the event aggregator if using --delay-uploads. Default = 1.")
192 options, filenames = parser.parse_args()
195 # extract data source configuration
198 datasourceinfo = datasource.GWDataSourceInfo(options)
201 for option in (
"bank_cache",):
202 if getattr(options, option) is None:
203 fail +=
"must provide option %s\n" % (option)
204 if fail: raise ValueError(fail)
206 if options.injection_file:
207 options.inj_name_dict = datasource.injection_dict_from_channel_list_with_node_range(options.injection_file)
209 options.inj_name_dict = {}
211 if options.data_source not in datasourceinfo.live_sources:
212 raise ValueError(
"datasource option not supported for online analysis. Only framexmit and lvshm are supported.")
214 #FIXME add consistency check?
215 options.bank_cache = inspiral_pipe.parse_cache_str(options.bank_cache)
216 options.channel_dict = datasourceinfo.channel_dict
217 options.state_channel_dict = datasourceinfo.state_channel_dict
218 options.dq_channel_dict = datasourceinfo.dq_channel_dict
219 options.framexmit_dict = datasourceinfo.framexmit_addr
220 options.shm_part_dict = datasourceinfo.shm_part_dict
221 options.inj_channel_dict = datasource.channel_dict_from_channel_list_with_node_range(options.inj_channel_name)
222 options.inj_state_channel_dict = datasource.channel_dict_from_channel_list(options.inj_state_channel_name)
223 options.inj_dq_channel_dict = datasource.channel_dict_from_channel_list(options.inj_dq_channel_name)
224 options.inj_framexmit_dict = datasource.framexmit_dict_from_framexmit_list(options.inj_framexmit_addr)
226 ## A dictionary for injection shared memory partition
227 options.inj_shm_part_dict = {
"H1":
"LHO_InjData",
"L1":
"LLO_InjData",
"V1":
"VIRGO_InjData"}
228 if options.inj_shared_memory_partition is not None:
229 options.inj_shm_part_dict.update( datasource.channel_dict_from_channel_list(options.inj_shared_memory_partition) )
231 options.inj_range_dict = {}
232 for tag, channel in options.inj_name_dict.items():
233 options.inj_range_dict.setdefault(channel, []).append(tag)
234 for k,v in options.inj_range_dict.items():
235 options.inj_range_dict[k] = sorted(v)
237 if options.inj_channel_dict:
238 for nodes in options.inj_channel_dict.keys():
239 if not ( set(options.inj_channel_dict[nodes].keys()) == set(options.channel_dict.keys()) ):
240 raise ValueError("Either no injection jobs must be given or the injection and non-injection channels must be specified for the same set of detectors")
242 options.state_vector_on_off_dict = datasourceinfo.state_vector_on_off_bits
243 options.dq_vector_on_off_dict = datasourceinfo.dq_vector_on_off_bits
245 options.likelihood_files = [CacheEntry(line).url for line in open(options.likelihood_cache)]
246 options.zerolag_likelihood_files = [CacheEntry(line).url for line in open(options.zerolag_likelihood_cache)]
248 return options, filenames
256 options, filenames = parse_command_line()
259 for dir_ in [
'logs',
'gracedb',
'aggregator']:
260 if not os.path.exists(dir_):
263 if options.analysis_tag:
264 dag = dagparts.DAG(
"trigger_pipe_%s" % options.analysis_tag)
266 dag = dagparts.DAG(
"trigger_pipe")
269 # setup the job classes
272 jobs = set_up_jobs(options)
275 # Setup the Node classes
278 if not options.delay_uploads:
279 # set up lvalert-based uberplotter if not use kafka for event uploads and plots
280 listenNode = dagparts.DAGNode(jobs[
'lvalertListen'], dag, [],
281 opts = {
"gracedb-service-url": options.gracedb_service_url,
"lvalert-server-url": options.lvalert_server_url},
285 # dq with
default options
286 dqNodes = inspiral_pipe.dq_monitor_layer(dag, jobs, options)
289 # loop over banks to run gstlal inspiral pre clustering and far computation
290 # FIXME by default the inspiral jobs advertise the current directory as their
291 # job tag, but this should be made to be more flexible
294 job_tags, inj_job_tags = inspiral_pipe.online_inspiral_layer(dag, jobs, options)
296 margNode = dagparts.DAGNode(jobs[
'marg'], dag, [],
298 input_files = {
"": [options.marginalized_likelihood_file] + [
"%s_registry.txt" % r
for r in job_tags]},
303 # set up aggregation jobs
306 aggNodes = inspiral_pipe.aggregator_layer(dag, jobs, options, job_tags)
309 # set up event aggregator job if needed
312 if options.delay_uploads:
313 eventNodes = inspiral_pipe.event_upload_layer(dag, jobs, options, job_tags)
314 plotNodes = inspiral_pipe.event_plotter_layer(dag, jobs, options)
316 # inspiral state backup
318 if options.state_backup_destination:
319 stateNode = dagparts.DAGNode(jobs[
'state'], dag, [],
321 input_files = {
"": [options.state_backup_destination, options.marginalized_likelihood_file] + options.likelihood_files},
327 # Write out the dag and other flies
331 dag.write_sub_files()
333 # we probably want these jobs to retry indefinitely on dedicated nodes. A user
334 # can intervene and fix a problem without having to bring the dag down and up.
335 # There are few enough total jobs that this really shouldn't bog down the
336 # scheduler. For now 10000 will be considered indefinite
337 [node.set_retry(10000)
for node in dag.get_nodes()]