def run_simulation(args): print 'simulating' assert args.parameter_dir != None and args.outfname != None assert args.n_max_queries > 0 random.seed(args.seed) n_per_proc = int(float(args.n_max_queries) / args.n_procs) all_random_ints = [] for iproc in range(args.n_procs): # have to generate these all at once, 'cause each of the subprocesses is going to reset its seed and god knows what happens to our seed at that point all_random_ints.append([random.randint(0, sys.maxint) for i in range(n_per_proc)]) for iproc in range(args.n_procs): proc = Process(target=make_events, args=(args, n_per_proc, iproc, all_random_ints[iproc])) proc.start() while len(active_children()) > 0: # print ' wait %s' % len(active_children()), sys.stdout.flush() time.sleep(1) utils.merge_csvs(args.outfname, [args.workdir + '/recombinator-' + str(iproc) + '/' + os.path.basename(args.outfname) for iproc in range(args.n_procs)], cleanup=(not args.no_clean))
def run_simulation(args): if args.outfname is None: raise Exception('have to specify --outfname for simulation') if not os.path.exists(args.parameter_dir): raise Exception('parameter dir %s d.n.e.' % args.parameter_dir) if not args.n_sim_events > 0: raise Exception('--n-sim-events has to be a positivie number') if args.slurm: raise Exception('simulator parallelization does not handle slurm') def make_events(n_events, iproc, random_ints): assert n_events > 0 # NOTE all the different seeds! this sucks but is necessary reco = Recombinator(args, seed=args.seed+iproc, sublabel=str(iproc)) for ievt in range(n_events): # print ievt, # sys.stdout.flush() failed = True itry = 0 while failed: if itry > 0: print 'try again: %d' % itry failed = not reco.combine(random_ints[ievt] + itry) itry += 1 print 'simulating' random.seed(args.seed) n_per_proc = int(float(args.n_sim_events) / args.n_procs) all_random_ints = [] for iproc in range(args.n_procs): # have to generate these all at once, 'cause each of the subprocesses is going to reset its seed and god knows what happens to our seed at that point all_random_ints.append([random.randint(0, sys.maxint) for i in range(n_per_proc)]) for iproc in range(args.n_procs): proc = Process(target=make_events, args=(n_per_proc, iproc, all_random_ints[iproc])) proc.start() while len(active_children()) > 0: # print ' wait %s' % len(active_children()), sys.stdout.flush() time.sleep(1) utils.merge_csvs(args.outfname, [args.workdir + '/recombinator-' + str(iproc) + '/' + os.path.basename(args.outfname) for iproc in range(args.n_procs)], cleanup=(not args.no_clean))