def test_nooutputfiles(self): fd, file1 = tempfile.mkstemp() fd, file2 = tempfile.mkstemp() fd, file3 = tempfile.mkstemp() os.remove(file3) with open(file1, 'w') as fd: print('hello file1', file=fd) with open(file2, 'w') as fd: print('hello file2', file=fd) time.sleep(0.01) ob = taskrun.FileCleanupObserver() tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask(tm, 't1', 'false'.format(file1, file2, file3)) t1.add_condition( taskrun.FileModificationCondition([file1, file2], [file3])) tm.run_tasks() self.assertTrue(os.path.isfile(file1)) self.assertTrue(os.path.isfile(file2)) self.assertFalse(os.path.isfile(file3)) # remove all files os.remove(file1) os.remove(file2)
def test_noinputfiles(self): fd, file1 = tempfile.mkstemp() fd, file2 = tempfile.mkstemp() fd, file3 = tempfile.mkstemp() os.remove(file1) os.remove(file2) os.remove(file3) time.sleep(0.01) ob = taskrun.FileCleanupObserver() tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask(tm, 't1', 'false'.format(file1, file2, file3)) t1.add_condition( taskrun.FileModificationCondition([file1, file2], [file3])) tm.run_tasks() self.assertFalse(os.path.isfile(file1)) self.assertFalse(os.path.isfile(file2)) self.assertFalse(os.path.isfile(file3))
def main(args): # ensure rundir exists, if not make it if not os.path.isdir(args.rundir): try: os.mkdir(args.rundir) except: error('couldn\'t create {0}'.format(args.rundir)) # ensure the supersim environment exists if not os.path.isdir(args.ssenv): error('{0} does not exist'.format(args.ssenv)) # create a task manager to handle all tasks rm = taskrun.ResourceManager( taskrun.CounterResource('cpus', 9999, args.cpus), taskrun.MemoryResource('mem', 9999, args.mem)) ob = taskrun.VerboseObserver(description=args.verbose) tm = taskrun.TaskManager(resource_manager=rm, observer=ob, failure_mode=taskrun.FailureMode.ACTIVE_CONTINUE) # sweep params sweepStart = 1 sweepStop = 100 sweepStep = 9 loads = [ '{0:.02f}'.format(x / 100) for x in range(sweepStart, sweepStop + 1, sweepStep) ] # sweep load parse_tasks = [] for load in loads: runId = '{0:02d}_{1}'.format(args.queue, load) # create file names supersim_bin = os.path.join(args.ssenv, 'poem_supersim', 'bin', 'supersim') sslatency_bin = os.path.join(args.ssenv, 'sslatency', 'bin', 'sslatency') settings_json = os.path.join(args.ssenv, 'poem_supersim', 'json', 'hierarchyhyperx_iq_GlueFactory1.json') simout_log = os.path.join(args.rundir, 'simout_{0}.log'.format(runId)) messages_mpf = os.path.join(args.rundir, 'messages_{0}.mpf'.format(runId)) rates_csv = os.path.join(args.rundir, 'rates_{0}.csv'.format(runId)) channels_csv = os.path.join(args.rundir, 'channels_{0}.mpf'.format(runId)) messages_csv = os.path.join(args.rundir, 'messages_{0}.csv'.format(runId)) packets_csv = os.path.join(args.rundir, 'packets_{0}.csv'.format(runId)) aggregate_csv = os.path.join(args.rundir, 'aggregate_{0}.csv'.format(runId)) packets_png = os.path.join(args.rundir, 'packets_{0}.png'.format(runId)) # create simulation task sim_cmd = ('{0} {1} ' 'application.max_injection_rate=float={2} ' 'application.message_log.file=string={3} ' 'application.rate_log.file=string={4} ' 'network.channel_log.file=string={5} ' 'network.interface.init_credits=uint={6} ' 'network.router.input_queue_depth=uint={6} ').format( supersim_bin, settings_json, load, messages_mpf, rates_csv, channels_csv, args.queue) sim_task = taskrun.ProcessTask(tm, 'sim_{0}'.format(runId), sim_cmd) sim_task.stdout_file = simout_log sim_task.stderr_file = simout_log sim_task.resources = {'cpus': 1, 'mem': 10} sim_task.add_condition( taskrun.FileModificationCondition( [settings_json], [simout_log, messages_mpf, rates_csv, channels_csv])) # create parser task parse_cmd = '{0} -m {1} -p {2} -a {3} {4}'.format( sslatency_bin, messages_csv, packets_csv, aggregate_csv, messages_mpf) parse_task = taskrun.ProcessTask(tm, 'parse_{0}'.format(runId), parse_cmd) parse_task.resources = {'cpus': 1, 'mem': 2} parse_task.add_dependency(sim_task) parse_task.add_condition( taskrun.FileModificationCondition( [messages_mpf], [messages_csv, packets_csv, aggregate_csv])) parse_tasks.append(parse_task) # create plot task plot_cmd = 'sslqp {0} {1}'.format(packets_csv, packets_png) plot_task = taskrun.ProcessTask(tm, 'plot_{0}'.format(runId), plot_cmd) plot_task.resources = {'cpus': 1, 'mem': 2} plot_task.add_dependency(parse_task) plot_task.add_condition( taskrun.FileModificationCondition([packets_csv], [packets_png])) # create a task to make a load latency graph loadlat_file = os.path.join(args.rundir, 'load_latency_{0:02d}.png'.format(args.queue)) loadlat_cmd = ('ssllp --row Packet --title "QueueSize={0}" ' '{1} {2} {3} {4}').format(args.queue, loadlat_file, sweepStart, sweepStop + 1, sweepStep) agg_files = [] for load in loads: runId = '{0:02d}_{1}'.format(args.queue, load) aggregate_csv = os.path.join(args.rundir, 'aggregate_{0}.csv'.format(runId)) loadlat_cmd += ' {0}'.format(aggregate_csv) agg_files.append(aggregate_csv) loadlat_task = taskrun.ProcessTask(tm, 'loadlat_{0}'.format(args.queue), loadlat_cmd) loadlat_task.resources = {'cpus': 1, 'mem': 2} for dep in parse_tasks: loadlat_task.add_dependency(dep) loadlat_task.add_condition( taskrun.FileModificationCondition(agg_files, [loadlat_file])) # run all tasks tm.run_tasks()
def test_simple(self): fd, file1 = tempfile.mkstemp() fd, file2 = tempfile.mkstemp() fd, file3 = tempfile.mkstemp() with open(file1, 'w') as fd: print('hello file1', file=fd) with open(file2, 'w') as fd: print('hello file2', file=fd) time.sleep(0.01) # initial run ob = OrderCheckObserver(['@t1', '+t1', '-t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) tm.run_tasks() self.assertTrue(ob.ok()) # nothing changed ob = OrderCheckObserver(['@t1', '*t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # nothing changed ob = OrderCheckObserver(['@t1', '*t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # missing output os.remove(file3) ob = OrderCheckObserver(['@t1', '+t1', '-t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # nothing changed ob = OrderCheckObserver(['@t1', '*t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # input changed time.sleep(0.01) with open(file1, 'w') as fd: print('hello file1!', file=fd) time.sleep(0.01) ob = OrderCheckObserver(['@t1', '+t1', '-t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # nothing changed ob = OrderCheckObserver(['@t1', '*t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # input changed (test add_input) time.sleep(0.01) with open(file1, 'w') as fd: print('hello file1!', file=fd) time.sleep(0.01) ob = OrderCheckObserver(['@t1', '+t1', '-t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file2], [file3]) c1.add_input(file1) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # missing output (test add_output) os.remove(file3) ob = OrderCheckObserver(['@t1', '+t1', '-t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], []) c1.add_output(file3) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # nothing changed ob = OrderCheckObserver(['@t1', '*t1'], verbose=False) tm = taskrun.TaskManager(observers=[ob]) t1 = taskrun.ProcessTask( tm, 't1', 'cat {0} {1} > {2}'.format(file1, file2, file3)) c1 = taskrun.FileModificationCondition([file1, file2], [file3]) t1.add_condition(c1) tm.run_tasks() self.assertTrue(ob.ok()) # remove all files os.remove(file1) os.remove(file2) os.remove(file3)
def test_many(self): # create files for processes procs = 100 files = [] for proc_id in range(procs): fd, file_a = tempfile.mkstemp() fd, file_b = tempfile.mkstemp() fd, file_c = tempfile.mkstemp() files.append([file_a, file_b, file_c]) # write something into A and B files time.sleep(0.01) for proc_id in range(procs): with open(files[proc_id][0], 'w') as afile: print('hello file A from proc {0}'.format(proc_id), file=afile) with open(files[proc_id][1], 'w') as bfile: print('hello file B from proc {0}'.format(proc_id), file=bfile) # initial ob = OccurredCheckObserver([], verbose=False) tm = taskrun.TaskManager(observers=[ob]) evts = [] for proc_id in range(procs): task = taskrun.ProcessTask( tm, 't{0:04}'.format(proc_id), 'cat {0} {1} > {2}'.format(files[proc_id][0], files[proc_id][1], files[proc_id][2])) cond = taskrun.FileModificationCondition( [files[proc_id][0], files[proc_id][1]], [files[proc_id][2]]) task.add_condition(cond) evts.append('@{0}'.format(task.name)) evts.append('+{0}'.format(task.name)) evts.append('-{0}'.format(task.name)) ob.reinit(evts) tm.run_tasks() self.assertTrue(ob.ok()) # no change ob = OccurredCheckObserver([], verbose=False) tm = taskrun.TaskManager(observers=[ob]) evts = [] for proc_id in range(procs): task = taskrun.ProcessTask( tm, 't{0:04}'.format(proc_id), 'cat {0} {1} > {2}'.format(files[proc_id][0], files[proc_id][1], files[proc_id][2])) cond = taskrun.FileModificationCondition( [files[proc_id][0], files[proc_id][1]], [files[proc_id][2]]) task.add_condition(cond) evts.append('@{0}'.format(task.name)) evts.append('*{0}'.format(task.name)) ob.reinit(evts) tm.run_tasks() self.assertTrue(ob.ok()) # change some rnd = random.Random() ob = OccurredCheckObserver([], verbose=False) tm = taskrun.TaskManager(observers=[ob]) evts = [] for proc_id in range(procs): task = taskrun.ProcessTask( tm, 't{0:04}'.format(proc_id), 'cat {0} {1} > {2}'.format(files[proc_id][0], files[proc_id][1], files[proc_id][2])) cond = taskrun.FileModificationCondition( [files[proc_id][0], files[proc_id][1]], [files[proc_id][2]]) task.add_condition(cond) # randomly sabotage this task evts.append('@{0}'.format(task.name)) if bool(rnd.getrandbits(1)): evts.append('+{0}'.format(task.name)) evts.append('-{0}'.format(task.name)) # randomly select between sabotaging the input or output if bool(rnd.getrandbits(1)): # sabotage input (change input file) with open(files[proc_id][rnd.getrandbits(1)], 'w+') as ifile: print(str(rnd.getrandbits(8)), file=ifile) else: # sabotage output (delete output file) os.remove(files[proc_id][2]) else: evts.append('*{0}'.format(task.name)) ob.reinit(evts) tm.run_tasks() self.assertTrue(ob.ok()) # no change ob = OccurredCheckObserver([], verbose=False) tm = taskrun.TaskManager(observers=[ob]) evts = [] for proc_id in range(procs): task = taskrun.ProcessTask( tm, 't{0:04}'.format(proc_id), 'cat {0} {1} > {2}'.format(files[proc_id][0], files[proc_id][1], files[proc_id][2])) cond = taskrun.FileModificationCondition( [files[proc_id][0], files[proc_id][1]], [files[proc_id][2]]) task.add_condition(cond) evts.append('@{0}'.format(task.name)) evts.append('*{0}'.format(task.name)) ob.reinit(evts) tm.run_tasks() self.assertTrue(ob.ok()) # change some rnd = random.Random() ob = OccurredCheckObserver([], verbose=False) tm = taskrun.TaskManager(observers=[ob]) evts = [] for proc_id in range(procs): task = taskrun.ProcessTask( tm, 't{0:04}'.format(proc_id), 'cat {0} {1} > {2}'.format(files[proc_id][0], files[proc_id][1], files[proc_id][2])) cond = taskrun.FileModificationCondition( [files[proc_id][0], files[proc_id][1]], [files[proc_id][2]]) task.add_condition(cond) # randomly sabotage this task evts.append('@{0}'.format(task.name)) if bool(rnd.getrandbits(1)): evts.append('+{0}'.format(task.name)) evts.append('-{0}'.format(task.name)) # randomly select between sabotaging the input or output if bool(rnd.getrandbits(1)): # sabotage input (change input file) with open(files[proc_id][rnd.getrandbits(1)], 'w+') as ifile: print(str(rnd.getrandbits(8)), file=ifile) else: # sabotage output (delete output file) os.remove(files[proc_id][2]) else: evts.append('*{0}'.format(task.name)) ob.reinit(evts) tm.run_tasks() self.assertTrue(ob.ok()) # remove all files for proc_id in range(procs): for tfile in files[proc_id]: os.remove(tfile)
args.supersim, args.settings, '0.0001' if l == '0.00' else l, out_dir + '/info_' + id + '.csv', out_dir + '/channels_' + id + '.csv', out_dir + '/rates_' + id + '.csv', out_dir + '/messages_' + id + '.mpf.gz')) sim_cmd += set_routing_algorithm(a) sim_task = taskrun.ProcessTask(tm, sim_name, sim_cmd) sim_task.stdout_file = out_dir + '/simout_' + id + '.log' sim_task.stderr_file = out_dir + '/simout_' + id + '.log' sim_task.resources = {'cpus': 1, 'mem': 1} sim_task.priority = 0 sim_task.add_condition(taskrun.FileModificationCondition( [], [out_dir + '/info_' + id + '.csv', out_dir + '/channels_' + id + '.csv', out_dir + '/rates_' + id + '.csv', out_dir + '/messages_' + id + '.mpf.gz', out_dir + '/simout_' + id + '.log'])) sim_tasks[id] = sim_task # create all parse tasks parse_tasks = {} for a in routing_algorithms: for l in loads: id = a + '_' + l parse_name = 'parse_' + id parse_cmd = ('{0} ' '-l {1}/latency_{2}.csv ' '-m {1}/messages_{2}.csv.gz ' '-s 0.001 ' '{3}'