From e1844aeef74135178f01114ba5820f49c6b536a5 Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Thu, 20 Sep 2018 19:21:45 +0200 Subject: [PATCH 1/9] testing out some of the new logic in bank verifier --- .../pycbc_make_bank_verifier_workflow | 60 +++++++++++++++---- pycbc/workflow/jobsetup.py | 7 ++- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 6ce78dce514..4bc60b86688 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -26,6 +26,7 @@ template bank. from __future__ import division import os import argparse +import logging from glue import segments @@ -34,6 +35,7 @@ import pycbc.workflow as wf import pycbc.workflow.pegasus_workflow as pwf from pycbc.results import create_versioning_page, static_table, layout from pycbc.workflow import LalappsInspinjExecutable +from pycbc.workflow import PycbcCreateInjectionsExecutable from pycbc.workflow import setup_splittable_dax_generated # Boiler-plate stuff @@ -148,7 +150,7 @@ class BanksimTablePointInjsExecutable(wf.Executable): # Argument parsing and setup of workflow -# Use the standard workflow command-line parsing routines. Things like a +# Use the standard workflow command-line parsing routines. Things like a # configuration file are specified within the "workflow command line group" # so run this with --help to see what options are added. _desc = __doc__[1:] @@ -158,9 +160,15 @@ parser.add_argument("--workflow-name", type=str, default='bank_verifier', help="Descriptive name of the analysis.") parser.add_argument("-d", "--output-dir", default=None, help="Path to output directory.") + +parser.add_argument("--verbose", action="store_true", default=False, + help="Print logging messages.") + wf.add_workflow_command_line_group(parser) args = parser.parse_args() +pycbc.init_logging(args.verbose) + # Create the workflow object workflow = wf.Workflow(args, args.workflow_name) @@ -182,16 +190,48 @@ inp_bank.description='TEMPLATEBANK' inp_bank.ifo_list=(['H1','L1','V1']) inp_bank.segment = workflow.analysis_time -# Inspinj job -inspinj_job = LalappsInspinjExecutable(workflow.cp, 'injection', out_dir='.', - ifos='HL', tags=[]) - -def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks): +# Injection Job +# determine which executable will be used to generate injections +injection_generator = workflow.cp.get('workflow', 'injection-generator') + +supported_injection_generators = ['inspinj', 'pycbc_create_injections'] + +if injection_generator not in supported_injection_generators: + err_msg = """'injection-generator = {}' is not supported. \ +Please choose from = {} +""".format(injection_generator,supported_injection_generators) + raise ValueError(err_msg) +logging.info("Running with injection_generator = {}".format(injection_generator)) + +if injection_generator == "inspinj": + sec_name = "inspinj_injection" + injection_job = LalappsInspinjExecutable(workflow.cp, sec_name, out_dir='.', + ifos='HL', tags=[]) +elif injection_generator == "pycbc_create_injections": + sec_name = "pycbc_injection" + injection_job = PycbcCreateInjectionsExecutable( + workflow.cp, sec_name, out_dir=".", ifo="HL", tags=[]) + +def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, + injection_generator): """Add a group of jobs that does a complete banksim. """ - inspinj_job.update_current_tags(curr_tags) - t_seg = segments.segment([1000000000, 1000000000+int(num_injs)]) - node = inspinj_job.create_node(t_seg) + injection_job.update_current_tags(curr_tags) + start_time = 1000000000 + end_time = 1000000000+int(num_injs) + t_seg = segments.segment([start_time, end_time]) + if injection_generator == "inspinj": + node = injection_job.create_node(t_seg) + elif injection_generator == "pycbc_create_injections": + # PycbcCreateInjectionsExecutable gets the segment length + # from the 'workflow' section of the ini file. + # Here we override the values from the ini file as they don't + # get used for anything else. + workflow.cp.set("workflow", "start-time", str(start_time)) + workflow.cp.set("workflow", "end-time", str(end_time)) + inj_file_ext = workflow.cp.get("pycbc_injection", "output-file-format") + node = injection_job.create_node(workflow.cp, ext=inj_file_ext) + workflow += node inj_file = node.output_file split_injs = setup_splittable_dax_generated(workflow, [inj_file], @@ -244,7 +284,7 @@ for file_tag, num_injs in workflow.cp.items('workflow-pointinjs'): output_pointinjs[file_tag] = curr_file curr_tags = ['broadinjbanksplit'] -split_banks = setup_splittable_dax_generated(workflow, [inp_bank], +split_banks = setup_splittable_dax_generated(workflow, [inp_bank], 'splitbankfiles', curr_tags) output_broadinjs = {} diff --git a/pycbc/workflow/jobsetup.py b/pycbc/workflow/jobsetup.py index 318f3890d04..f223c8d0d99 100644 --- a/pycbc/workflow/jobsetup.py +++ b/pycbc/workflow/jobsetup.py @@ -1627,7 +1627,7 @@ def __init__(self, cp, exe_name, ifo=None, out_dir=None, super(PycbcCreateInjectionsExecutable, self).__init__( cp, exe_name, universe, ifo, out_dir, tags) - def create_node(self, config_file=None, seed=None, tags=None): + def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf"): """ Set up a CondorDagmanNode class to run ``pycbc_create_injections``. Parameters @@ -1639,6 +1639,9 @@ def create_node(self, config_file=None, seed=None, tags=None): Seed to use for generating injections. tags : list A list of tags to include in filenames. + ext : str + Output file extension. Use '.hdf' or '.xml' for sim_inspiral table + ( Default = '.hdf' ) Returns -------- @@ -1660,7 +1663,7 @@ def create_node(self, config_file=None, seed=None, tags=None): if seed: node.add_opt("--seed", seed) injection_file = node.new_output_file_opt(analysis_time, - ".hdf", "--output-file", + ext, "--output-file", tags=tags) return node, injection_file From c4f3a21c10acb31212d33ffeda6dedd66149ae8b Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Thu, 20 Sep 2018 19:26:58 +0200 Subject: [PATCH 2/9] add missing arg --- bin/workflows/pycbc_make_bank_verifier_workflow | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 4bc60b86688..0841a685248 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -280,7 +280,7 @@ output_pointinjs = {} for file_tag, num_injs in workflow.cp.items('workflow-pointinjs'): curr_tags = ['shortinjs', file_tag] curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, - split_banks) + split_banks, injection_generator) output_pointinjs[file_tag] = curr_file curr_tags = ['broadinjbanksplit'] @@ -291,7 +291,7 @@ output_broadinjs = {} for file_tag, num_injs in workflow.cp.items('workflow-broadinjs'): curr_tags = ['broadinjs', file_tag] curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, - split_banks) + split_banks, injection_generator) output_broadinjs[file_tag] = curr_file plotting_nodes = [] From 79e26ee03b120149af2a2dd6f50ebd110a3677ec Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Thu, 20 Sep 2018 19:41:29 +0200 Subject: [PATCH 3/9] file input outside - this breaks backward comp --- pycbc/workflow/jobsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycbc/workflow/jobsetup.py b/pycbc/workflow/jobsetup.py index f223c8d0d99..8b38f9c7b27 100644 --- a/pycbc/workflow/jobsetup.py +++ b/pycbc/workflow/jobsetup.py @@ -1622,6 +1622,7 @@ class PycbcCreateInjectionsExecutable(Executable): """ current_retention_level = Executable.ALL_TRIGGERS + file_input_options = ["--config-file"] def __init__(self, cp, exe_name, ifo=None, out_dir=None, universe=None, tags=None): super(PycbcCreateInjectionsExecutable, self).__init__( @@ -1659,7 +1660,6 @@ def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf"): # make node for running executable node = Node(self) - node.add_input_opt("--config-file", config_file) if seed: node.add_opt("--seed", seed) injection_file = node.new_output_file_opt(analysis_time, From 89f914efa5429cedd8b12da5d4773c821abc3c08 Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Thu, 20 Sep 2018 11:07:53 -0700 Subject: [PATCH 4/9] modify inj file logic --- bin/workflows/pycbc_make_bank_verifier_workflow | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 0841a685248..462e501ee4f 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -222,6 +222,7 @@ def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, t_seg = segments.segment([start_time, end_time]) if injection_generator == "inspinj": node = injection_job.create_node(t_seg) + inj_file = node.output_file elif injection_generator == "pycbc_create_injections": # PycbcCreateInjectionsExecutable gets the segment length # from the 'workflow' section of the ini file. @@ -230,10 +231,9 @@ def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, workflow.cp.set("workflow", "start-time", str(start_time)) workflow.cp.set("workflow", "end-time", str(end_time)) inj_file_ext = workflow.cp.get("pycbc_injection", "output-file-format") - node = injection_job.create_node(workflow.cp, ext=inj_file_ext) + node, inj_file = injection_job.create_node(ext=inj_file_ext) workflow += node - inj_file = node.output_file split_injs = setup_splittable_dax_generated(workflow, [inj_file], 'splitinjfiles', curr_tags) # Banksim job From 3358c79caf91aede0efb27c79295c22ac9eb1d93 Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Sat, 22 Sep 2018 12:12:05 +0200 Subject: [PATCH 5/9] possible working version with pycbc injections --- .../pycbc_make_bank_verifier_workflow | 81 ++++++++++++------- pycbc/workflow/jobsetup.py | 19 ++++- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 462e501ee4f..47d5d5548ee 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -39,7 +39,8 @@ from pycbc.workflow import PycbcCreateInjectionsExecutable from pycbc.workflow import setup_splittable_dax_generated # Boiler-plate stuff -__author__ = "Ian Harry " +__author__ = "Ian Harry and \ +Sebastian Khan " __version__ = pycbc.version.git_verbose_msg __date__ = pycbc.version.date __program__ = "pycbc_make_bank_verifier_workflow" @@ -172,15 +173,6 @@ pycbc.init_logging(args.verbose) # Create the workflow object workflow = wf.Workflow(args, args.workflow_name) -wf.makedir(args.output_dir) -os.chdir(args.output_dir) -args.output_dir = '.' - -rdir = layout.SectionNumber('results', ['point_injection_sets', - 'broad_injection_sets', - 'workflow']) -wf.makedir(rdir.base) -wf.makedir(rdir['workflow']) # Input bank file inp_bank = workflow.cp.get('workflow', 'input-bank') @@ -188,13 +180,16 @@ inp_bank = wf.File.from_path(inp_bank) inp_bank.tags = [] inp_bank.description='TEMPLATEBANK' inp_bank.ifo_list=(['H1','L1','V1']) +# seems strange to hardcode this to 3 IFO +# maybe derive this from [workflow-ifos] inp_bank.segment = workflow.analysis_time # Injection Job # determine which executable will be used to generate injections injection_generator = workflow.cp.get('workflow', 'injection-generator') -supported_injection_generators = ['inspinj', 'pycbc_create_injections'] +# these names are the fields in ini file that point to the executable also. +supported_injection_generators = ['inspinj_injection', 'pycbc_injection'] if injection_generator not in supported_injection_generators: err_msg = """'injection-generator = {}' is not supported. \ @@ -204,34 +199,45 @@ Please choose from = {} logging.info("Running with injection_generator = {}".format(injection_generator)) if injection_generator == "inspinj": - sec_name = "inspinj_injection" - injection_job = LalappsInspinjExecutable(workflow.cp, sec_name, out_dir='.', - ifos='HL', tags=[]) -elif injection_generator == "pycbc_create_injections": - sec_name = "pycbc_injection" + injection_job = LalappsInspinjExecutable(workflow.cp, + injection_generator, out_dir='.', ifos='HL', tags=[]) +elif injection_generator == "pycbc_injection": injection_job = PycbcCreateInjectionsExecutable( - workflow.cp, sec_name, out_dir=".", ifo="HL", tags=[]) + workflow.cp, injection_generator, out_dir=".", ifo="HL", tags=[]) def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, injection_generator): """Add a group of jobs that does a complete banksim. """ + if injection_generator == "pycbc_injection": + # had to put this near the top of this function + # so othat num_injs would get set in the dax for all cases. + # some voodoo. + workflow.cp.set("pycbc_injection", "ninjections", num_injs) + + # curr_tags are like [section_heading, injection_set_name] injection_job.update_current_tags(curr_tags) + start_time = 1000000000 end_time = 1000000000+int(num_injs) - t_seg = segments.segment([start_time, end_time]) + if injection_generator == "inspinj": + + t_seg = segments.segment([start_time, end_time]) node = injection_job.create_node(t_seg) inj_file = node.output_file - elif injection_generator == "pycbc_create_injections": - # PycbcCreateInjectionsExecutable gets the segment length - # from the 'workflow' section of the ini file. - # Here we override the values from the ini file as they don't - # get used for anything else. - workflow.cp.set("workflow", "start-time", str(start_time)) - workflow.cp.set("workflow", "end-time", str(end_time)) - inj_file_ext = workflow.cp.get("pycbc_injection", "output-file-format") - node, inj_file = injection_job.create_node(ext=inj_file_ext) + + elif injection_generator == "pycbc_injection": + + inj_file_ext = workflow.cp.get("pycbc_injection-extra", "output-file-format") + injection_config_file = workflow.cp.get("pycbc_injection"+"-"+curr_tags[1], "config-file") + print("injection_config_file = {}".format(injection_config_file)) + injection_cp = wf.File.from_path(injection_config_file) + node, inj_file = \ + injection_job.create_node(config_file=injection_cp, + ext=inj_file_ext, + start_time=start_time, + end_time=end_time) workflow += node split_injs = setup_splittable_dax_generated(workflow, [inj_file], @@ -255,6 +261,8 @@ def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, currinj_banksim_files = wf.FileList([]) for bank_idx, split_bank in enumerate(split_banks): bank_tag = 'BANK{}'.format(bank_idx) + # does this need to be here? + # seems redundent with a few lines above. inj_tag = 'INJ{}'.format(inj_idx) node = banksim_job.create_node(workflow.analysis_time, split_inj, split_bank, @@ -279,6 +287,7 @@ split_banks = setup_splittable_dax_generated(workflow, [inp_bank], output_pointinjs = {} for file_tag, num_injs in workflow.cp.items('workflow-pointinjs'): curr_tags = ['shortinjs', file_tag] + logging.info("working curr_tags = {}".format(curr_tags)) curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, injection_generator) output_pointinjs[file_tag] = curr_file @@ -290,10 +299,28 @@ split_banks = setup_splittable_dax_generated(workflow, [inp_bank], output_broadinjs = {} for file_tag, num_injs in workflow.cp.items('workflow-broadinjs'): curr_tags = ['broadinjs', file_tag] + logging.info("working curr_tags = {}".format(curr_tags)) curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, injection_generator) output_broadinjs[file_tag] = curr_file +### +# moved the making and moving or directory until the end +# because we are parsing in extra config files that are +# defined in the main ini file +### + +wf.makedir(args.output_dir) +os.chdir(args.output_dir) +args.output_dir = '.' + +rdir = layout.SectionNumber('results', ['point_injection_sets', + 'broad_injection_sets', + 'workflow']) +wf.makedir(rdir.base) +wf.makedir(rdir['workflow']) + + plotting_nodes = [] out_dir = rdir.base diff --git a/pycbc/workflow/jobsetup.py b/pycbc/workflow/jobsetup.py index 8b38f9c7b27..66179e0bf73 100644 --- a/pycbc/workflow/jobsetup.py +++ b/pycbc/workflow/jobsetup.py @@ -1622,13 +1622,15 @@ class PycbcCreateInjectionsExecutable(Executable): """ current_retention_level = Executable.ALL_TRIGGERS + # This might be plural i.e. "--config-files" file_input_options = ["--config-file"] def __init__(self, cp, exe_name, ifo=None, out_dir=None, universe=None, tags=None): super(PycbcCreateInjectionsExecutable, self).__init__( cp, exe_name, universe, ifo, out_dir, tags) - def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf"): + def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf", + start_time=None, end_time=None): """ Set up a CondorDagmanNode class to run ``pycbc_create_injections``. Parameters @@ -1643,6 +1645,14 @@ def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf"): ext : str Output file extension. Use '.hdf' or '.xml' for sim_inspiral table ( Default = '.hdf' ) + start_time : int + Use this to override the value of the 'start-time' given in + the 'config_file' [workflow] section + ( Default = None ) + end_time : int + Use this to override the value of the 'end-time' given in + the 'config_file' [workflow] section + ( Default = None ) Returns -------- @@ -1654,12 +1664,15 @@ def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf"): tags = [] if tags is None else tags # get analysis start and end time - start_time = self.cp.get("workflow", "start-time") - end_time = self.cp.get("workflow", "end-time") + if start_time is None: + start_time = self.cp.get("workflow", "start-time") + if end_time is None: + end_time = self.cp.get("workflow", "end-time") analysis_time = segments.segment(int(start_time), int(end_time)) # make node for running executable node = Node(self) + # node.add_input_opt("--config-file", config_file) if seed: node.add_opt("--seed", seed) injection_file = node.new_output_file_opt(analysis_time, From 9c3be1d67acde3acf191a18c6d516cc6c56e5b25 Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Sat, 22 Sep 2018 12:23:32 +0200 Subject: [PATCH 6/9] remove print statement --- bin/workflows/pycbc_make_bank_verifier_workflow | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 47d5d5548ee..304de8e6baf 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -231,7 +231,6 @@ def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, inj_file_ext = workflow.cp.get("pycbc_injection-extra", "output-file-format") injection_config_file = workflow.cp.get("pycbc_injection"+"-"+curr_tags[1], "config-file") - print("injection_config_file = {}".format(injection_config_file)) injection_cp = wf.File.from_path(injection_config_file) node, inj_file = \ injection_job.create_node(config_file=injection_cp, From 2e1ad46595611b4a18729b181ef974669b9c9f88 Mon Sep 17 00:00:00 2001 From: Sebastian Khan Date: Sun, 23 Sep 2018 10:26:35 +0200 Subject: [PATCH 7/9] move mkdir back up --- .../pycbc_make_bank_verifier_workflow | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 304de8e6baf..51de9708b4f 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -173,6 +173,15 @@ pycbc.init_logging(args.verbose) # Create the workflow object workflow = wf.Workflow(args, args.workflow_name) +wf.makedir(args.output_dir) +os.chdir(args.output_dir) +args.output_dir = '.' + +rdir = layout.SectionNumber('results', ['point_injection_sets', + 'broad_injection_sets', + 'workflow']) +wf.makedir(rdir.base) +wf.makedir(rdir['workflow']) # Input bank file inp_bank = workflow.cp.get('workflow', 'input-bank') @@ -303,23 +312,6 @@ for file_tag, num_injs in workflow.cp.items('workflow-broadinjs'): split_banks, injection_generator) output_broadinjs[file_tag] = curr_file -### -# moved the making and moving or directory until the end -# because we are parsing in extra config files that are -# defined in the main ini file -### - -wf.makedir(args.output_dir) -os.chdir(args.output_dir) -args.output_dir = '.' - -rdir = layout.SectionNumber('results', ['point_injection_sets', - 'broad_injection_sets', - 'workflow']) -wf.makedir(rdir.base) -wf.makedir(rdir['workflow']) - - plotting_nodes = [] out_dir = rdir.base From 61518af482d2a09aa1502179b8ed757cecad64bb Mon Sep 17 00:00:00 2001 From: Ian Harry Date: Mon, 24 Sep 2018 16:21:29 +0200 Subject: [PATCH 8/9] Edits to Seb's changes --- .../pycbc_make_bank_verifier_workflow | 75 ++++++++----------- pycbc/workflow/jobsetup.py | 19 +++-- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/bin/workflows/pycbc_make_bank_verifier_workflow b/bin/workflows/pycbc_make_bank_verifier_workflow index 51de9708b4f..70c9c6e97bc 100644 --- a/bin/workflows/pycbc_make_bank_verifier_workflow +++ b/bin/workflows/pycbc_make_bank_verifier_workflow @@ -39,8 +39,8 @@ from pycbc.workflow import PycbcCreateInjectionsExecutable from pycbc.workflow import setup_splittable_dax_generated # Boiler-plate stuff -__author__ = "Ian Harry and \ -Sebastian Khan " +__author__ = "Ian Harry and " +__author__ += "Sebastian Khan " __version__ = pycbc.version.git_verbose_msg __date__ = pycbc.version.date __program__ = "pycbc_make_bank_verifier_workflow" @@ -194,58 +194,50 @@ inp_bank.ifo_list=(['H1','L1','V1']) inp_bank.segment = workflow.analysis_time # Injection Job -# determine which executable will be used to generate injections -injection_generator = workflow.cp.get('workflow', 'injection-generator') +injection_exe = workflow.cp.get('executables', 'injection') +injection_exe = os.path.basename(injection_exe) +logging.info("Using {} for injection generation.".format(injection_exe)) -# these names are the fields in ini file that point to the executable also. -supported_injection_generators = ['inspinj_injection', 'pycbc_injection'] - -if injection_generator not in supported_injection_generators: - err_msg = """'injection-generator = {}' is not supported. \ -Please choose from = {} -""".format(injection_generator,supported_injection_generators) - raise ValueError(err_msg) -logging.info("Running with injection_generator = {}".format(injection_generator)) - -if injection_generator == "inspinj": +if injection_exe == "lalapps_inspinj": injection_job = LalappsInspinjExecutable(workflow.cp, - injection_generator, out_dir='.', ifos='HL', tags=[]) -elif injection_generator == "pycbc_injection": + 'injection', out_dir='.', ifos='HL', tags=[]) +elif injection_exe == "pycbc_create_injections": injection_job = PycbcCreateInjectionsExecutable( - workflow.cp, injection_generator, out_dir=".", ifo="HL", tags=[]) + workflow.cp, 'injection', out_dir=".", ifo="HL", tags=[]) +else: + err_msg = "Injection executable {} is not supported.".format(injection_exe) + err_msg += " Please use, lalapps_inspinj or pycbc_create_injections." + raise ValueError(err_msg) + -def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, - injection_generator): +def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks): """Add a group of jobs that does a complete banksim. """ - if injection_generator == "pycbc_injection": - # had to put this near the top of this function - # so othat num_injs would get set in the dax for all cases. - # some voodoo. - workflow.cp.set("pycbc_injection", "ninjections", num_injs) - # curr_tags are like [section_heading, injection_set_name] injection_job.update_current_tags(curr_tags) start_time = 1000000000 end_time = 1000000000+int(num_injs) - if injection_generator == "inspinj": - + if injection_exe == "lalapps_inspinj": t_seg = segments.segment([start_time, end_time]) node = injection_job.create_node(t_seg) inj_file = node.output_file - elif injection_generator == "pycbc_injection": - - inj_file_ext = workflow.cp.get("pycbc_injection-extra", "output-file-format") - injection_config_file = workflow.cp.get("pycbc_injection"+"-"+curr_tags[1], "config-file") - injection_cp = wf.File.from_path(injection_config_file) - node, inj_file = \ - injection_job.create_node(config_file=injection_cp, - ext=inj_file_ext, - start_time=start_time, - end_time=end_time) + elif injection_exe == "pycbc_create_injections": + # Set a default value. When .hdf is supported this should be .hdf + inj_file_ext = ".xml" + # Allow overrides from config file + if workflow.cp.has_option_tags("workflow-injection", + "output-file-format", curr_tags): + inj_file_ext = workflow.cp.get_option_tags("workflow-injection", + "output-file-format", + curr_tags) + node = injection_job.create_node(ext=inj_file_ext, + start_time=start_time, + end_time=end_time, + num_injs=num_injs) + inj_file = node.output_file workflow += node split_injs = setup_splittable_dax_generated(workflow, [inj_file], @@ -269,9 +261,6 @@ def add_banksim_set(workflow, file_tag, num_injs, curr_tags, split_banks, currinj_banksim_files = wf.FileList([]) for bank_idx, split_bank in enumerate(split_banks): bank_tag = 'BANK{}'.format(bank_idx) - # does this need to be here? - # seems redundent with a few lines above. - inj_tag = 'INJ{}'.format(inj_idx) node = banksim_job.create_node(workflow.analysis_time, split_inj, split_bank, extra_tags=[bank_tag,inj_tag]) @@ -297,7 +286,7 @@ for file_tag, num_injs in workflow.cp.items('workflow-pointinjs'): curr_tags = ['shortinjs', file_tag] logging.info("working curr_tags = {}".format(curr_tags)) curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, - split_banks, injection_generator) + split_banks) output_pointinjs[file_tag] = curr_file curr_tags = ['broadinjbanksplit'] @@ -309,7 +298,7 @@ for file_tag, num_injs in workflow.cp.items('workflow-broadinjs'): curr_tags = ['broadinjs', file_tag] logging.info("working curr_tags = {}".format(curr_tags)) curr_file = add_banksim_set(workflow, file_tag, num_injs, curr_tags, - split_banks, injection_generator) + split_banks) output_broadinjs[file_tag] = curr_file plotting_nodes = [] diff --git a/pycbc/workflow/jobsetup.py b/pycbc/workflow/jobsetup.py index 66179e0bf73..4922d929bc4 100644 --- a/pycbc/workflow/jobsetup.py +++ b/pycbc/workflow/jobsetup.py @@ -1629,15 +1629,12 @@ def __init__(self, cp, exe_name, ifo=None, out_dir=None, super(PycbcCreateInjectionsExecutable, self).__init__( cp, exe_name, universe, ifo, out_dir, tags) - def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf", - start_time=None, end_time=None): + def create_node(self, seed=None, tags=None, ext=".hdf", + start_time=None, end_time=None, num_injs=None): """ Set up a CondorDagmanNode class to run ``pycbc_create_injections``. Parameters ---------- - config_file : pycbc.workflow.core.File - A ``pycbc.workflow.core.File`` for inference configuration file - to be used with ``--config-files`` option. seed : int Seed to use for generating injections. tags : list @@ -1653,6 +1650,12 @@ def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf", Use this to override the value of the 'end-time' given in the 'config_file' [workflow] section ( Default = None ) + num_injs : int + Use this to specify the number of injections (the --ninjections + command line argument). If not provided (or set to None), this + command line argument is not set and it is assumed this will be + specified in the configuration file. + ( Default = None ) Returns -------- @@ -1670,16 +1673,18 @@ def create_node(self, config_file=None, seed=None, tags=None, ext=".hdf", end_time = self.cp.get("workflow", "end-time") analysis_time = segments.segment(int(start_time), int(end_time)) + if num_injs is not None: + node.add_opt("--ninjections", num_injs) + # make node for running executable node = Node(self) - # node.add_input_opt("--config-file", config_file) if seed: node.add_opt("--seed", seed) injection_file = node.new_output_file_opt(analysis_time, ext, "--output-file", tags=tags) - return node, injection_file + return node class PycbcInferenceExecutable(Executable): """ The class responsible for creating jobs for ``pycbc_inference``. From 2d8b193a6d363051698d171020432cd6ddff3a73 Mon Sep 17 00:00:00 2001 From: Ian Harry Date: Mon, 24 Sep 2018 16:30:56 +0200 Subject: [PATCH 9/9] Missed this --- pycbc/workflow/jobsetup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pycbc/workflow/jobsetup.py b/pycbc/workflow/jobsetup.py index 4922d929bc4..a129ba9f9e2 100644 --- a/pycbc/workflow/jobsetup.py +++ b/pycbc/workflow/jobsetup.py @@ -1622,8 +1622,7 @@ class PycbcCreateInjectionsExecutable(Executable): """ current_retention_level = Executable.ALL_TRIGGERS - # This might be plural i.e. "--config-files" - file_input_options = ["--config-file"] + file_input_options = ["--config-files"] def __init__(self, cp, exe_name, ifo=None, out_dir=None, universe=None, tags=None): super(PycbcCreateInjectionsExecutable, self).__init__(