if opts.verbose: print >> sys.stdout, "Initialized the template bank to seed with %d precomputed templates." % len( bank) # # check for saved work # if opts.checkpoint and os.path.exists(opts.output_filename + "_checkpoint.gz"): xmldoc = utils.load_filename(opts.output_filename + "_checkpoint.gz", contenthandler=ContentHandler) tbl = lsctables.SnglInspiralTable.get_table(xmldoc) [ bank.insort(t) for t in Bank.from_sngls( tbl, tmplt_class, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max) ] if opts.verbose: print >> sys.stdout, "Found checkpoint file %s with %d precomputed templates." % (
bank.add_from_hdf(hdf_fp) hdf_fp.close() if opts.verbose: print("Initialized the template bank to seed with %d precomputed templates." % len(bank)) # # check for saved work # if opts.checkpoint and os.path.exists( opts.output_filename + "_checkpoint.gz" ): xmldoc = utils.load_filename(opts.output_filename + "_checkpoint.gz", contenthandler=ContentHandler) tbl = lsctables.SnglInspiralTable.get_table(xmldoc) [bank.insort(t) for t in Bank.from_sngls(tbl, tmplt_class, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max)] if opts.verbose: print("Found checkpoint file %s with %d precomputed templates." % (opts.output_filename + "_checkpoint.gz", len(tbl))) print("Resuming from checkpoint with %d total templates..." % len(bank)) # reset rng state rng_state = np.load(opts.output_filename + "_checkpoint.rng.npz") rng1 = rng_state["state1"] rng2 = rng_state["state2"] rng3 = rng_state["state3"] rng4 = rng_state["state4"] np.random.mtrand.set_state( ("MT19937", rng1, rng2, rng3, rng4) ) else: if opts.output_filename.endswith(('.xml', '.xml.gz')):
# get the correct generator proposal = proposals[opts.approximant](opts.flow, **params) # For robust convergence, ensure that an average of kmax/len(ks) of # the last len(ks) proposals have been rejected by SBank. ks = deque(10*[0], maxlen=10) k = 0 # k is nprop per iteration nprop = 1 # count total number of proposed templates status_format = "bank size: %d\tproposed: %d\t" + "\t".join("%s: %s" % name_format for name_format in zip(waveform.param_names, waveform.param_formats)) while (k + float(sum(ks)))/len(ks) < opts.convergence_threshold: tmplt = waveform(*proposal.next(), bank=bank) k += 1 nprop += 1 if not bank.covers(tmplt, opts.match_min): bank.insort(tmplt) if opts.verbose: print >>sys.stdout, status_format % ((len(bank), k) + tmplt.params) ks.append(k) k = 0 # clear the proposal template if caching is not enabled if not opts.cache_waveforms: tmplt.clear() print "total number of proposed templates: %d" % nprop print "total number of match calculations: %d" % bank._nmatch print "final bank size: %d" % len(bank) bank.clear() # clear caches
bank = Bank.from_sngls(sngl_inspiral, waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max) tmpdoc.unlink() del sngl_inspiral, tmpdoc if opts.verbose: print>>sys.stdout,"Initialized the template bank to seed file %s with %d precomputed templates." % (opts.bank_seed, len(bank)) # # check for saved work # if opts.checkpoint and os.path.exists( fout + "_checkpoint.gz" ): xmldoc = utils.load_filename(fout + "_checkpoint.gz", contenthandler=ContentHandler) tbl = table.get_table(xmldoc, lsctables.SnglInspiralTable.tableName) [bank.insort(t) for t in Bank.from_sngls(tbl, waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max)] if opts.verbose: print >>sys.stdout,"Found checkpoint file %s with %d precomputed templates." % (fout + "_checkpoint.gz", len(tbl)) print >>sys.stdout, "Resuming from checkpoint with %d total templates..." % len(bank) # reset rng state rng_state = np.load(fout + "_checkpoint.rng.npz") rng1 = rng_state["state1"] rng2 = rng_state["state2"] rng3 = rng_state["state3"] rng4 = rng_state["state4"] np.random.mtrand.set_state( ("MT19937", rng1, rng2, rng3, rng4) ) else:
tmpdoc.unlink() del sngl_inspiral, tmpdoc if opts.verbose: print>>sys.stdout,"\tseed bank size: %d"%len(bank) print>>sys.stdout,"Filling regions of parameter space not covered by bank seed..." # # check for saved work # if opts.checkpoint and os.path.exists( fout + "_checkpoint.gz" ): xmldoc = utils.load_filename(fout + "_checkpoint.gz", contenthandler=ContentHandler) tbl = table.get_table(xmldoc, lsctables.SnglInspiralTable.tableName) [bank.insort(t) for t in Bank.from_sngls(tbl, waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param)] if opts.verbose: print >>sys.stdout,"Found checkpoint file with %d precomputed templates." % len(tbl) print >>sys.stdout, "Resuming from checkpoint with %d total templates..." % len(bank) # reset rng state rng_state = np.load(fout + "_checkpoint.rng.npz") rng1 = rng_state["state1"] rng2 = rng_state["state2"] rng3 = rng_state["state3"] rng4 = rng_state["state4"] np.random.mtrand.set_state( ("MT19937", rng1, rng2, rng3, rng4) ) else: