def logretr(): log = helper.read(globals.logfile) if log is None: print 'Contest log not found' return False sys.stdout.write(log) return True
def parse(fname: str) -> Tuple[List[int], List[int]]: content = helper.read(fname) part1, part2 = content.split("\n\n") p1 = [int(x) for x in part1.splitlines()[1:]] p2 = [int(x) for x in part2.splitlines()[1:]] return p1, p2
def write_back(): if setup.flag == 0: if setup.op_code != 10: setup.registers[setup.destination] = setup.result print("WRITEBACK: write %d to R%d \n" % (setup.result, setup.destination)) helper.write_to_out("WRITEBACK: write "+str(setup.result)+" to R"+str(setup.destination)+" \n") setup.gui.editor("WRITEBACK: write "+str(setup.result)+" to R"+str(setup.destination)+" \n") else: print("WRITEBACK: no writeback required \n") helper.write_to_out("WRITEBACK: no writeback required \n") setup.gui.editor("WRITEBACK: no writeback required \n") elif setup.flag == 1: if setup.op_code == 25: setup.registers[setup.destination] = setup.result print("WRITEBACK: write %d to R%d \n" % (setup.result, setup.destination)) helper.write_to_out("WRITEBACK: write "+str(setup.result)+" to R"+str(setup.destination)+" \n") setup.gui.editor("WRITEBACK: write "+str(setup.result)+" to R"+str(setup.destination)+" \n") elif setup.op_code == 24: k = setup.secondOperand//4 setup.temp.get(setup.firstOperand)[k] = setup.registers[setup.destination] print("WRITEBACK: write %d to memory array" % setup.temp.get(setup.firstOperand)[k]) helper.write_to_out("WRITEBACK: write "+str(setup.temp.get(setup.firstOperand)[k])+" to memory array \n") setup.gui.editor("WRITEBACK: write "+str(setup.temp.get(setup.firstOperand)[k])+" to memory array \n") elif setup.flag == 2: print("WRITEBACK: No writeback operation required \n") helper.write_to_out("WRITEBACK: No writeback operation required \n") setup.gui.editor("WRITEBACK: No writeback operation required \n") elif setup.flag == 3: mask = int(setup.inst[4:], 0) & 0xFF if mask == 0x11: print("EXIT: \n") helper.write_to_out("EXIT: \n") setup.gui.editor("EXIT: \n") elif mask == 0x6C: helper.read() print("WRITEBACK: %s is Read from Console and stored in Register 0" % str(setup.registers[0])) helper.write_to_out("WRITEBACK: %s is Read from File and stored in Register 0" % str(setup.registers[0])) setup.gui.editor("WRITEBACK: %s is Read from File and stored in Register 0" % str(setup.registers[0])) elif mask == 0x6B: helper.write() print("WRITEBACK: %s is Written to Console from Register 1" % str(setup.registers[1])) helper.write_to_out("WRITEBACK: %s is Written to Console from Register 1" % str(setup.registers[1])) setup.gui.editor("WRITEBACK: %s is Written to Console from Register 1" % str(setup.registers[1])) setup.gui.registers()
def make (): print 'Creating {} source file for problem {}'.format(settings.langexts[globals.getext()], globals.getprob()) template = helper.read(os.path.join(globals.templatedir, globals.getmode() + '.' + globals.getext())) if template is None: print '{}.{} template file not found (add it to templates folder)'.format(globals.getmode(), globals.getext()) return False helper.write(os.path.join(globals.working, globals.getsrc()), pattern.convert(template)) print 'Source file created: ' + globals.getsrc() return True
def addmsg(msg, system=True): logstr = helper.read(globals.logfile) if logstr is None: return False lines = logstr.split('\n') time = (datetime.datetime.now() - datetime.datetime.strptime(lines[1].split('started ')[1], formatstr)) timestr = '{:d}:{:02d}'.format(time.seconds / 3600, (time.seconds % 3600) / 60) logstr += '> {:>5} - {:>4}: {}'.format(timestr, 'pcu' if system else 'user', msg) if not msg.endswith('\n'): logstr += '\n' helper.write(globals.logfile, logstr) return True
def main() -> None: # fname = "example.txt" fname = "input.txt" rules, lines = helper.read(fname).split("\n\n") reg = RegExp(rules) # pprint(reg.d) # pprint(reg.regexp) result = sum(1 for line in lines.splitlines() if re.match(reg.regexp, line)) print(result)
def make(): print 'Creating {} source file for problem {}'.format( settings.langexts[globals.getext()], globals.getprob()) template = helper.read( os.path.join(globals.templatedir, globals.getmode() + '.' + globals.getext())) if template is None: print '{}.{} template file not found (add it to templates folder)'.format( globals.getmode(), globals.getext()) return False helper.write(os.path.join(globals.working, globals.getsrc()), pattern.convert(template)) print 'Source file created: ' + globals.getsrc() log.addmsg('Creating {} source file for problem {}'.format( settings.langexts[globals.getext()], globals.getprob())) return True
def getfile (ext): file = parse.parseopts()['filename'] type = exttotype[ext] testid = globals.gettestid() print 'Getting test case {} {} for problem {}'.format(testid, type, globals.getprob()) output = helper.read(os.path.join(globals.probdir, testid + ext)) if output is None: print 'Did not find {} file'.format(type) return False if file is None: print 'File found: {} below'.format(type) print settings.smalldivider print output + ('' if settings.eof is None else settings.eof) else: try: file.write(output) file.close() print 'Wrote {} to {}'.format(type, file.name) except IOError: print 'Unable to write to ' + file.name return False return True
def getfile(ext): file = parse.parseopts()['filename'] type = exttotype[ext] testid = globals.gettestid() print 'Getting test case {} {} for problem {}'.format( testid, type, globals.getprob()) output = helper.read(os.path.join(globals.probdir, testid + ext)) if output is None: print 'Did not find {} file'.format(type) return False if file is None: print 'File found: {} below'.format(type) print settings.smalldivider print output + ('' if settings.eof is None else settings.eof) else: try: file.write(output) file.close() print 'Wrote {} to {}'.format(type, file.name) except IOError: print 'Unable to write to ' + file.name return False return True
def run(): if not globals.commands['comp'](): return False print settings.meddivider stdio = globals.getmode() == 'stdio' print 'Executing problem {} in {} I/O mode'.format(globals.getprob(), globals.getmode()) files = os.listdir(globals.probdir) cases = [] for file in files: if file.endswith('.in'): cases.append(file[:-3]) print '{} test inputs found'.format(len(cases)) sandboxin = os.path.join(globals.sandboxdir, pattern.convert(settings.inputfile)) sandboxout = os.path.join(globals.sandboxdir, pattern.convert(settings.outputfile)) execcommand = pattern.convert( settings.execcommands[settings.langexts[globals.getext()]]) langlim = settings.timeconstraints[settings.langexts[globals.getext()]] outcomes = collections.OrderedDict([('Correct', 0), ('Runtime Error', 0), ('Time Limit Exceeded', 0), ('Presentation Error', 0), ('Wrong Answer', 0), ('No Output Produced', 0), ('No Answer File', 0)]) print 'Time limit per input: {:.2f} seconds'.format(langlim) for case in cases: print settings.meddivider print 'Test input ' + case helper.copy(os.path.join(globals.probdir, case + '.in'), sandboxin) input = helper.read(sandboxin) execresult = helper.runproc(execcommand, globals.sandboxdir, stdin=(input if stdio else None), timelim=langlim) output = execresult[2] if stdio else helper.read(sandboxout) ans = helper.read(os.path.join(globals.probdir, case + '.ans')) wronganswer = False if execresult[0] is None: # Time limit exceeded print 'Execution time limit exceeded' outcomes['Time Limit Exceeded'] += 1 else: print 'Execution time: {:.2f} seconds'.format(execresult[1]) if execresult[0] != 0: print 'Runtime error: exit code ' + repr(execresult[0]) outcomes['Runtime Error'] += 1 elif output is None or len(output) == 0: print 'Program did not produce output' outcomes['No Output Produced'] += 1 elif ans is None: print 'No answer file provided' outcomes['No Answer File'] += 1 elif ans == output or \ (''.join(ans.split()) == ''.join(output.split()) and settings.acceptformatting): print 'Correct' outcomes['Correct'] += 1 elif ''.join(ans.split()) == ''.join(output.split()): print 'Presentation Error (extra/missing whitespace)' outcomes['Presentation Error'] += 1 wronganswer = True else: print 'Wrong Answer' outcomes['Wrong Answer'] += 1 wronganswer = True if settings.printinput: helper.printdesc(input, 'Input', settings.smalldivider) if settings.printoutput: helper.printdesc(output, 'Output', settings.smalldivider) if wronganswer and settings.printexpected: helper.printdesc(ans, 'Expected Output', settings.smalldivider) if settings.printstdout and not stdio: helper.printdesc(execresult[2], 'Stdout', settings.smalldivider) if settings.printstderr: helper.printdesc(execresult[3], 'Stderr', settings.smalldivider) helper.write(os.path.join(globals.probdir, case + '.out'), output) if not stdio: helper.write(os.path.join(globals.probdir, case + '.stdout'), execresult[2]) helper.write(os.path.join(globals.probdir, case + '.stderr'), execresult[3]) if settings.printsummary: print settings.meddivider print 'Results Summary' for outcome in outcomes: print '{:2d} | {:<20}'.format(outcomes[outcome], outcome) print 'Total Score: {:.1f}'.format( (100.0 * outcomes['Correct']) / max(1, len(cases))) log.addmsg('Executed problem {} in {} I/O mode with score {:.1f}'.format( globals.getprob(), globals.getmode(), (100.0 * outcomes['Correct']) / max(1, len(cases)))) return True
# Lendo os arquivos de configurações e objetos f = open(file, 'r') for line in f: # Pulando linhas em branco if len(line) < 2: continue words = line.split() line_type = words[0] ## Tipo da linha values = words[1:] ## Valores do objeto ou propriedade if line_type == '#': pass elif line_type in obj_types_list: new_objs_list = (read(line_type, values)) obj_list = obj_list + new_objs_list elif line_type in prop_types_list: prop_dict[line_type] = (read(line_type, values)) else: print("Tipo não encontrado") print(line_type) FILENAME = str(prop_dict['output']) #print("Lista de objetos: ", obj_list) #print("Lista de propriedades: ", prop_dict) #Create Camera eye = Vector3D(prop_dict['eye'][0], prop_dict['eye'][1], prop_dict['eye'][2]) #higher z = more narrow view
def run (): if not globals.commands['comp'](): return False print settings.meddivider stdio = globals.getmode() == 'stdio' print 'Executing problem {} in {} I/O mode'.format(globals.getprob(), globals.getmode()) files = os.listdir(globals.probdir) cases = [] for file in files: if file.endswith('.in'): cases.append(file[:-3]) print '{} test inputs found'.format(len(cases)) sandboxin = os.path.join(globals.sandboxdir, pattern.convert(settings.inputfile)) sandboxout = os.path.join(globals.sandboxdir, pattern.convert(settings.outputfile)) execcommand = pattern.convert(settings.execcommands[settings.langexts[globals.getext()]]) langlim = settings.timeconstraints[settings.langexts[globals.getext()]] outcomes = collections.OrderedDict([ ('Correct', 0), ('Runtime Error', 0), ('Time Limit Exceeded', 0), ('Presentation Error', 0), ('Wrong Answer', 0), ('No Output Produced', 0), ('No Answer File', 0) ]) print 'Time limit per input: {:.2f} seconds'.format(langlim) for case in cases: print settings.meddivider print 'Test input ' + case helper.copy(os.path.join(globals.probdir, case + '.in'), sandboxin) input = helper.read(sandboxin) execresult = helper.runproc(execcommand, globals.sandboxdir, stdin=(input if stdio else None), timelim=langlim) output = execresult[2] if stdio else helper.read(sandboxout) ans = helper.read(os.path.join(globals.probdir, case + '.ans')) wronganswer = False if execresult[0] is None: # Time limit exceeded print 'Execution time limit exceeded' outcomes['Time Limit Exceeded'] += 1 else: print 'Execution time: {:.2f} seconds'.format(execresult[1]) if execresult[0] != 0: print 'Runtime error: exit code ' + repr(execresult[0]) outcomes['Runtime Error'] += 1 elif output is None or len(output) == 0: print 'Program did not produce output' outcomes['No Output Produced'] += 1 elif ans is None: print 'No answer file provided' outcomes['No Answer File'] += 1 elif ans == output: print 'Correct' outcomes['Correct'] += 1 elif ''.join(ans.split()) == ''.join(output.split()): print 'Presentation Error (extra/missing whitespace)' outcomes['Presentation Error'] += 1 wronganswer = True else: print 'Wrong Answer' outcomes['Wrong Answer'] += 1 wronganswer = True if settings.printinput: helper.printdesc(input, 'Input', settings.smalldivider) if settings.printoutput: helper.printdesc(output, 'Output', settings.smalldivider) if wronganswer and settings.printexpected: helper.printdesc(ans, 'Expected Output', settings.smalldivider) if settings.printstdout and not stdio: helper.printdesc(execresult[2], 'Stdout', settings.smalldivider) if settings.printstderr: helper.printdesc(execresult[3], 'Stderr', settings.smalldivider) helper.write(os.path.join(globals.probdir, case + '.out'), output) if not stdio: helper.write(os.path.join(globals.probdir, case + '.stdout'), execresult[2]) helper.write(os.path.join(globals.probdir, case + '.stderr'), execresult[3]) if settings.printsummary: print settings.meddivider print 'Results Summary' for outcome in outcomes: print '{:2d} | {:<20}'.format(outcomes[outcome], outcome) print 'Total Score: {:.1f}'.format((100.0 * outcomes['Correct']) / len(cases)); return True
def parse(fname: str) -> List[str]: content: str = helper.read(fname).strip() return content.split("\n\n")
# Plot the memory access latency for each warp in a few of the SMs import sys import helper import matplotlib.pyplot as plt import numpy as np filename = sys.argv[1] out = sys.argv[2] start, end, smID, blocks = helper.read(filename) i = 0 num_warps = 0 min_latency = 1e10 max_latency = 0 avg_latency = 0 for idx in range(4): SM_blocks = blocks[smID == idx] block_names = set(SM_blocks) first = 1 for si, ei, bi in zip(start[smID == idx], end[smID == idx], SM_blocks): latency = ei - si min_latency = min(min_latency, latency) max_latency = max(max_latency, latency) avg_latency += latency if bi in block_names: color = "k-" block_names.remove(bi) else: color = "C%d-" % idx plt.plot([si, ei], [i, i], color)