def get_minimized_fitness( genome ): infomsg( "getting minimized genome for", genome ) if not os.path.exists( genome + ".min" ): record.time( "minimize.py", check_call, [ os.path.join( root, "bin", "minimize.py" ), genprog, config, "--genome-file", genome, "--cache", genome + ".cache", "--save-binary", genome + ".bin", "--save-source", genome + ".src", "--save-genome", genome + ".min" ] ) if options.regenerate is not None: cfg = Config() cfg.load( config ) cmd = cfg[ "--test-command" ] cmd = cmd.replace( "__EXE_NAME__", genome + ".bin" ) if options.regenerate == "wall": cmd += " -j 1 --wall --repeat 100 --no-limit" with record.context( "fitness eval" ): fitnesses = list() for i in range( options.rows ): with mktemp() as fitnessfile: # use call instead of check_call because test scripts always # return non-zero status tmp = cmd.replace( "__FITNESS_FILE__", fitnessfile ) call( [ "sh", "-c", tmp ] ) with open( fitnessfile ) as fh: for line in fh: value = float( line.split()[ 0 ] ) infomsg( " ", value ) fitnesses.append( value ) break else: infomsg( "ERROR: no fitness for", genome + ".bin", file = sys.stderr ) exit( 2 ) return fitnesses else: with open( genome + ".min" ) as fh: key = " ".join( fh.readlines() ) key = " ".join( key.split() ) d = shelve.open( genome + ".cache" ) return d[ key ]
def get_localized_results( localfile, index ): storage = get_storage_dir( index ) fitness_log = "fitness%s.csv" % index cfg = Config() cfg.load( config ) run_search = False if os.path.isdir( storage ): if not os.path.exists( os.path.join( storage, fitness_log ) ): infomsg( "no such file:", os.path.join( storage, fitness_log ) ) run_search = True elif not os.path.exists( fitness_log ): infomsg( "no such file:", fitness_log ) run_search = True if run_search: cmd = [ genprog, config, "--max-evals", str( options.max_evals ), "--fitness-log", fitness_log ] if localfile is not None: cmd += [ "--fix-scheme", "line", "--fix-file", localfile, "--fault-scheme", "line", "--fault-file", localfile, ] record.time( "GenProg", check_call, cmd ) def get_repair_log( d ): if "--seed" in cfg: return os.path.join( d, "repair.debug.%s" % cfg[ "--seed" ] ) logs = glob( os.path.join( d, "repair.debug.*" ) ) if len( logs ) == 1: return logs[ 0 ] infomsg( "ERROR: could not determine repair log", file = sys.stderr ) exit( 2 ) if not os.path.isdir( storage ): repairlog = get_repair_log( "." ) os.makedirs( storage ) sources = [ fitness_log, "multi.cache", "repair.cache", repairlog ] check_call( [ "mv" ] + sources + [ storage ] ) repairlog = os.path.join( storage, repairlog ) else: repairlog = get_repair_log( storage ) return repairlog
def __init__( self, configfile ): config = Config() config.load( configfile ) lex = shlex.shlex( config[ "--test-command" ], configfile, True ) lex.whitespace_split = True args = list( lex ) if not "__FITNESS_FILE__" in args: raise ValueError( "no __FITNESS_FILE__ in " + config[ "--test-command" ] + ": cannot identify test" ) i = args.index( "__FITNESS_FILE__" ) - 1 self.prefix = map( quote, args[ :i ] ) self.input_arg = args[ i ] self.suffix = map( quote, args[ (i+1): ] )
for num, line in enumerate( fh, 1 ): if label.match( line ): print( line.rstrip(), file = out ) continue m = directive.match( line ) if not m or m.group( 1 ) not in [ "file", "loc" ]: print( '\t.loc 1 %d 0' % num, file = out ) print( line.rstrip(), file = out ) if len( fnames ) > 1: with renumber_files( fnames[ 1: ] ): yield else: yield config = Config() config.load( args[ 0 ] ) if options.compiler_command is not None: config[ "--compiler-command" ] = options.compiler_command if options.test_command is not None: config[ "--test-command" ] = options.test_command if options.pin_root is not None: os.environ[ "PIN_ROOT" ] = options.pin_root if not "PIN_ROOT" in os.environ: print( "ERROR: you must use --pin-root or set PIN_ROOT", file = sys.stderr ) exit( 1 ) pin = os.path.join( os.environ[ "PIN_ROOT" ], "pin" ) check_call( [ "make", "-C", os.path.join( root, "pintool" ) ] )
exit( status ) check_path( configfile ) check_path( srcdir ) infomsg( "checking that est-energy.py works..." ) check_path( est_energy ) check_cmd( [ est_energy, "-o", "/dev/null", "--", "true" ] ) infomsg( "pass" ) infomsg( "checking that limit command works..." ) check_path( limit ) check_cmd( [ limit, "1", "true" ] ) infomsg( "pass" ) config = Config() config.load( configfile ) with mktemp( dir = "." ) as exe: infomsg( "checking that we can compile the program..." ) compile_cmd = config[ "--compiler-command" ] compile_cmd = compile_cmd.replace( "__SOURCE_NAME__", "src/000000.s" ) compile_cmd = compile_cmd.replace( "__EXE_NAME__", exe ) status = call( [ "sh", "-c", compile_cmd ] ) if status != 0: infomsg( "ERROR: compile command failed!", file = sys.stderr ) infomsg( "ERROR:", compile_cmd, file = sys.stderr ) exit( status ) infomsg( "pass" )