Example #1
0
def shell_tail(argv):
    if len(argv) < 1:
        err("tail requires a file arg.")

    opts = argv[:-1]
    apath = argv[-1]

    afile = resolve_apath(apath)

    if afile == None:
        err("cannot locate file %s" % apath)

    if afile.type == 'gzip':
        # we want to do zcat | tail, but I don't know of a shell-agnostic
        # way to get the exit value of the zcat. bash has PIPESTATUS...
        tmp = '%s/abstractfile.tail.%s' % (tempfile.gettempdir(), os.getpid())
        cmd = 'zcat "%s" > "%s"' % (afile.cpath, tmp)
        exitval = os.system(cmd)
        if exitval == 0:
            cmd = 'tail %s "%s"' % (' '.join(opts), tmp)
            exitval = os.system(cmd)
            os.remove(tmp)
    else:
        cmd = 'tail %s "%s"' % (' '.join(opts), afile.cpath)
        exitval = os.system(cmd)

    return exitval
Example #2
0
def analyze_recent_dir(recent_dir):

    print "- recent directory='%s'" % (recent_dir)

    #-----------------------------------------------------------------------------------
    #--
    #-- Find epoch/timestep directories
    #--
    #-----------------------------------------------------------------------------------
    timesteps = []
    # list all of the timesteps, make sure they are all integers (and directories), then sort them by number.
    for potential_timestep in os.listdir(recent_dir):
        if not potential_timestep.isdigit():
            continue  # if timestep isn't a digit, skip it.
        if not os.path.isdir(os.path.join(recent_dir, potential_timestep)):
            continue  # if the timestep isn't a directory, skip it.

        timesteps.append(int(potential_timestep))  # add timestep to our list

    if len(timesteps) == 0:
        err('No epochs found. Not a valid recent directory.')

    timesteps.sort()  # sort the timesteps, lowest numbers come first.

    print "Processing:",
    for t in timesteps:
        analyze_epoch_dir(recent_dir, str(t))
def analyze_recent_dir(recent_dir):
	
	print "- recent directory='%s'" %(recent_dir)

	#-----------------------------------------------------------------------------------
	#--
	#-- Find epoch/timestep directories
	#--
	#-----------------------------------------------------------------------------------
	timesteps = []
	# list all of the timesteps, make sure they are all integers (and directories), then sort them by number.
	for potential_timestep in os.listdir( recent_dir ):
		if not potential_timestep.isdigit():
			continue	# if timestep isn't a digit, skip it.
		if not os.path.isdir( os.path.join(recent_dir, potential_timestep) ):
			continue	# if the timestep isn't a directory, skip it.
		
		timesteps.append( int(potential_timestep) )						# add timestep to our list
	
	if len(timesteps) == 0:
		err('No epochs found. Not a valid recent directory.')

	timesteps.sort()									# sort the timesteps, lowest numbers come first.
	
	print "Processing:",
	for t in timesteps:
		analyze_epoch_dir(recent_dir, str(t))
Example #4
0
def shell_tail( argv ):
    if len(argv) < 1:
        err( "tail requires a file arg." )

    opts = argv[:-1]
    apath = argv[-1]

    afile = resolve_apath( apath )

    if afile == None:
        err( "cannot locate file %s" % apath )

    if afile.type == 'gzip':
        # we want to do zcat | tail, but I don't know of a shell-agnostic
        # way to get the exit value of the zcat. bash has PIPESTATUS...
        tmp = '%s/abstractfile.tail.%s' % (tempfile.gettempdir(), os.getpid())
        cmd = 'zcat "%s" > "%s"' % (afile.cpath, tmp)
        exitval = os.system( cmd )
        if exitval == 0:
            cmd = 'tail %s "%s"' % (' '.join(opts), tmp)
            exitval = os.system( cmd )
            os.remove( tmp )
    else:
        cmd = 'tail %s "%s"' % (' '.join(opts), afile.cpath)
        exitval = os.system( cmd )

    return exitval
Example #5
0
    def pbarrierpos( name ):
        label, val = __line()
        if len(val) != 4:
            err( "expecting barrierkeyframe with 4 elements for %s, found (%s,%s)" % (name, label, val) )
        val = map( float, val )

        local.container.add( name, 'barrierpos', val )

        return val
Example #6
0
    def pbarrierkeyframe( name ):
        label, val = __line()
        if len(val) != 5:
            err( "expecting barrierkeyframe with 5 elements for %s, found (%s,%s)" % (name, label, val) )
        val = [int(val[0])] + map( float, val[1:] )

        local.container.add( name, 'barrierkeyframe', val )

        return val
Example #7
0
    def pbarrierkeyframe(name):
        label, val = __line()
        if len(val) != 5:
            err("expecting barrierkeyframe with 5 elements for %s, found (%s,%s)"
                % (name, label, val))
        val = [int(val[0])] + map(float, val[1:])

        local.container.add(name, 'barrierkeyframe', val)

        return val
Example #8
0
    def pbarrierpos(name):
        label, val = __line()
        if len(val) != 4:
            err("expecting barrierkeyframe with 4 elements for %s, found (%s,%s)"
                % (name, label, val))
        val = map(float, val)

        local.container.add(name, 'barrierpos', val)

        return val
Example #9
0
def proputil( *args ):
    proputil = pw_env( 'proputil' )

    cmd = [proputil] + list(args)

    exitval, stdout = get_cmd_stdout( cmd )
    
    if exitval != 0:
        err( "Failed executing '%s'. exit=%s" % (cmd,exitval) )

    return stdout.strip()
Example #10
0
def open(apath, mode='r'):
    afile = resolve_apath(apath)
    if afile == None:
        err("Cannot locate abstract file %s" % apath)
    if afile.isAmbiguous():
        err("ambiguous abstract file %s" % apath)

    if afile.type == 'gzip':
        return gzip.GzipFile(afile.cpath, mode)
    else:
        return __builtin__.open(afile.cpath, mode)
Example #11
0
def open( apath, mode = 'r' ):
    afile = resolve_apath( apath )
    if afile == None:
        err( "Cannot locate abstract file %s" % apath )
    if afile.isAmbiguous():
        err( "ambiguous abstract file %s" % apath )

    if afile.type == 'gzip':
        return gzip.GzipFile( afile.cpath, mode )
    else:
        return __builtin__.open( afile.cpath, mode )
Example #12
0
def proputil(*args):
    proputil = pw_env('proputil')

    cmd = [proputil] + list(args)

    exitval, stdout = get_cmd_stdout(cmd)

    if exitval != 0:
        err("Failed executing '%s'. exit=%s" % (cmd, exitval))

    return stdout.strip()
Example #13
0
    def __scalar( name, version, default, type, func_parse ):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != 1:
                err( "expecting scalar for %s, found (%s,%s)" % (name, label, val) )
            val = func_parse( val[0] )

            local.container.add( name, type, val )
        else:
            val = default

        return val
Example #14
0
    def __tuple( name, count, version, default, type, func_parse ):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != count:
                err( "expecting tuple with %d elements for %s, found (%s,%s)" % (count, name, label, val) )
            val = map( func_parse, val )

            local.container.add( name, type, val )
        else:
            val = default


        return val
Example #15
0
    def __tuple(name, count, version, default, type, func_parse):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != count:
                err("expecting tuple with %d elements for %s, found (%s,%s)" %
                    (count, name, label, val))
            val = map(func_parse, val)

            local.container.add(name, type, val)
        else:
            val = default

        return val
Example #16
0
    def __scalar(name, version, default, type, func_parse):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != 1:
                err("expecting scalar for %s, found (%s,%s)" %
                    (name, label, val))
            val = func_parse(val[0])

            local.container.add(name, type, val)
        else:
            val = default

        return val
Example #17
0
def ensure_proplib_worldfile(path_worldfile_or_run):
    if not os.path.isdir(path_worldfile_or_run):
        path_run = os.path.dirname(path_worldfile_or_run)
    else:
        path_run = path_worldfile_or_run

    if not isrundir(path_worldfile_or_run):
        err("ensure_proplib_worldfile can only operate within a run directory")

    path_proplib = path_worldfile(path_run)

    if not os.path.exists(path_proplib):
        path_legacy = path_worldfile(path_run, legacy=True)

        if not os.path.exists(path_legacy):
            err("Cannot locate proplib or legacy worldfile in rundir " +
                path_run)

        exitval, stdout = get_cmd_stdout(
            ['wfutil.py', 'conv', '-l', path_legacy])
        if exitval != 0:
            err("Cannot convert worldfile in rundir " + path_run)

        __tofile('/tmp/converted.wf', stdout)

        if not os.path.exists(path_schema()):
            err("Cannot find schema. Expected at '%s'" % path_schema())

        __tofile(path_proplib,
                 proputil('-w', 'apply', path_schema(), '/tmp/converted.wf'))

        shutil.copy(path_schema(), path_run)

    return path_proplib
Example #18
0
def ensure_proplib_worldfile( path_worldfile_or_run ):
    if not os.path.isdir( path_worldfile_or_run ):
        path_run = os.path.dirname( path_worldfile_or_run )
    else:
        path_run = path_worldfile_or_run

    if not isrundir( path_worldfile_or_run ):
        err( "ensure_proplib_worldfile can only operate within a run directory" )

    path_proplib = path_worldfile(path_run)

    if not os.path.exists( path_proplib ):
        path_legacy = path_worldfile( path_run, legacy = True )

        if not os.path.exists( path_legacy ):
            err( "Cannot locate proplib or legacy worldfile in rundir " + path_run )

        exitval, stdout = get_cmd_stdout( ['wfutil.py', 'conv', '-l', path_legacy] )
        if exitval != 0:
            err( "Cannot convert worldfile in rundir " + path_run )

        __tofile( '/tmp/converted.wf', stdout )

        if not os.path.exists( path_schema() ):
            err( "Cannot find schema. Expected at '%s'" % path_schema() )

        __tofile( path_proplib, proputil('-w', 'apply', path_schema(), '/tmp/converted.wf') )

        shutil.copy( path_schema(), path_run )

    return path_proplib
Example #19
0
def shell_ln(argv):
    queries = argv

    if len(argv) != 2:
        err('ln requires 2 args')

    srcapath = argv[0]
    dstapath = argv[1]

    src = resolve_apath(srcapath)

    if src == None:
        err('cannot locate src file %s' % srcapath)
    if src.isAmbiguous():
        err('ambigous src file %s' % src.apath)

    if os.path.isdir(dstapath):
        dstapath = os.path.join(dstapath, src.basename())

    dst = resolve_apath(dstapath)

    if dst != None:
        err('dst file already exists: %s' % dst.apath)

    dst = AbstractFile(src.type, dstapath)

    os.link(src.cpath, dst.cpath)
Example #20
0
def shell_ln( argv ):
    queries = argv

    if len(argv) != 2:
        err( 'ln requires 2 args' )

    srcapath = argv[0]
    dstapath = argv[1]

    src = resolve_apath( srcapath )

    if src == None:
        err( 'cannot locate src file %s' % srcapath )
    if src.isAmbiguous():
        err( 'ambigous src file %s' % src.apath )

    if os.path.isdir( dstapath ):
        dstapath = os.path.join( dstapath, src.basename() )

    dst = resolve_apath( dstapath )

    if dst != None:
        err( 'dst file already exists: %s' % dst.apath )

    dst = AbstractFile( src.type, dstapath )

    os.link( src.cpath, dst.cpath )
Example #21
0
    def __line():
        while True:
            l = f.readline()

            tokens = l.split()
            n = len(tokens)
            if n == 1:
                err("unexpected format: '%s'" % l)

            if DEBUG:
                print 'READ LINE:', l

            if n > 0:
                return tokens[-1], tokens[:-1]
Example #22
0
    def __line():
        while True:
            l = f.readline()

            tokens = l.split()
            n = len(tokens)
            if n == 1:
                err( "unexpected format: '%s'" % l )

            if DEBUG:
                print 'READ LINE:', l

            if n > 0:
                return tokens[-1], tokens[:-1]
Example #23
0
def main():
    
    argv = sys.argv[1:]

    if len(argv) == 0:
        usage()

    mode = argv[0]

    if mode == "conv":
        shell_conv( argv[1:] )
    elif mode == "edit":
        shell_edit( argv[1:] )
    else:
        err( "invalid mode (%s)" % mode )
Example #24
0
def main():

    argv = sys.argv[1:]

    if len(argv) == 0:
        usage()

    mode = argv[0]

    if mode == "conv":
        shell_conv(argv[1:])
    elif mode == "edit":
        shell_edit(argv[1:])
    else:
        err("invalid mode (%s)" % mode)
Example #25
0
def ls(queries, returnConcrete=True):
    for query in queries:
        if os.path.isdir(query):
            query = os.path.join(query, '*')

        if '*' in query:
            afiles = aglob(query)
        else:
            afile = resolve_apath(query)
            if afile == None:
                err("no such file: %s" % query)
            afiles = [afile]

        for afile in afiles:
            if afile.isAmbiguous():
                err("multiple concrete files for %s" % afile.apath)

        return map(lambda x: x.cpath if returnConcrete else x.apath, afiles)
Example #26
0
def aglob( query ):
    dir = os.path.dirname( query )
    wildcard_pattern = os.path.basename( query )

    if '*' in dir:
        err( 'Wildcards in directories not yet supported' )

    regex_pattern = ('^' + re.escape(wildcard_pattern) + '$').replace('\\*', '.*' )

    afiles = []

    for cpath in os.listdir( dir ):
        afile = resolve_cpath( os.path.join(dir, cpath) )

        if re.match( regex_pattern, afile.basename() ):
            afiles.append( afile )

    return afiles
Example #27
0
def aglob(query):
    dir = os.path.dirname(query)
    wildcard_pattern = os.path.basename(query)

    if '*' in dir:
        err('Wildcards in directories not yet supported')

    regex_pattern = ('^' + re.escape(wildcard_pattern) + '$').replace(
        '\\*', '.*')

    afiles = []

    for cpath in os.listdir(dir):
        afile = resolve_cpath(os.path.join(dir, cpath))

        if re.match(regex_pattern, afile.basename()):
            afiles.append(afile)

    return afiles
Example #28
0
def ls( queries, returnConcrete = True ):
    for query in queries:
        if os.path.isdir( query ):
            query = os.path.join( query, '*' )

        if '*' in query:
            afiles = aglob( query )
        else:
            afile = resolve_apath(query)
            if afile == None:
                err( "no such file: %s" % query )
            afiles = [afile]

        for afile in afiles:
            if afile.isAmbiguous():
                err( "multiple concrete files for %s" % afile.apath )

        return map( lambda x: x.cpath if returnConcrete else x.apath,
                    afiles )
Example #29
0
	    
	complexities_remaining = list_difference(complexities, complexities_read)
	
	print "  AlreadyHave =", complexities_read
	print "  ComplexitiesToGet =", complexities_remaining
	
	# --- Compute complexities not already found on the file system
	if complexities_remaining:
		# --- Execute CalcComplexity on all brainFunction files in the timestep dir
		query = os.path.join(timestep_directory, "brainFunction*.txt")
		brainFunction_files = abstractfile.ls([query], returnConcrete = False)
		brainFunction_files.sort(lambda x, y: cmp(int(os.path.basename(x)[14:-4]),
							  int(os.path.basename(y)[14:-4])))

		if len(brainFunction_files) == 0:
			err('No brainfunction files found in %s' % timestep_directory)

		cmd="%s brainfunction --bare --list %s -- %s" % ( CALC_COMPLEXITY,
								  ' '.join(brainFunction_files),
								  ' '.join(complexities_remaining))
		cmd = shlex.split(cmd)
		proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
		stdout = proc.communicate()[0]
		complexity_all = filter(lambda x: len(x), stdout.split('\n'))
		if proc.returncode != 0:
			err('Failed executing CalcComplexity, exit=%d' % exitvalue)
	
		colnames = ['AgentNumber', 'Complexity']
		coltypes = ['int', 'float']
		tables = dict([(type, datalib.Table(type, colnames, coltypes))
			       for type in complexities_remaining])
Example #30
0
def parsePreProplib( path ):
    f = open( path, 'r' )

    def __line():
        while True:
            l = f.readline()

            tokens = l.split()
            n = len(tokens)
            if n == 1:
                err( "unexpected format: '%s'" % l )

            if DEBUG:
                print 'READ LINE:', l

            if n > 0:
                return tokens[-1], tokens[:-1]

    class local:
        container = Container()

    def push( name, childContainer ):
        local.container.add( name, 'container', childContainer )
        local.container = childContainer
        return childContainer

    def pop( name ):
        assert( name == local.container.name )
        local.container = local.container.parent

    wfversion = -1

    def __scalar( name, version, default, type, func_parse ):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != 1:
                err( "expecting scalar for %s, found (%s,%s)" % (name, label, val) )
            val = func_parse( val[0] )

            local.container.add( name, type, val )
        else:
            val = default

        return val

    def __tuple( name, count, version, default, type, func_parse ):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != count:
                err( "expecting tuple with %d elements for %s, found (%s,%s)" % (count, name, label, val) )
            val = map( func_parse, val )

            local.container.add( name, type, val )
        else:
            val = default


        return val

    def pint( name, version = None, default = None ):
        return __scalar(name, version, default, 'int', int)

    def pfloat( name, version = None, default = None ):
        return __scalar(name, version, default, 'float', float)

    def pbool( name, version = None, default = None ):
        return __scalar(name, version, default, 'bool', lambda x: x != '0' )

    def penum( name, values, version = None, default = None, values_new = None ):
        if values_new == None:
            values_new = values
        type = 'enum(' + ','.join(values_new) + ')'
        val =  __scalar(name, version, default, type, lambda x: values_new[values.index(x)] )
        assert( val in values_new )
        
        return val

    def pcolor( name, version = None, default = None ):
        return __tuple( name, 3, version, default, 'color', float )

    def pbarrierkeyframe( name ):
        label, val = __line()
        if len(val) != 5:
            err( "expecting barrierkeyframe with 5 elements for %s, found (%s,%s)" % (name, label, val) )
        val = [int(val[0])] + map( float, val[1:] )

        local.container.add( name, 'barrierkeyframe', val )

        return val

    def pbarrierpos( name ):
        label, val = __line()
        if len(val) != 4:
            err( "expecting barrierkeyframe with 4 elements for %s, found (%s,%s)" % (name, label, val) )
        val = map( float, val )

        local.container.add( name, 'barrierpos', val )

        return val

    def pignore( name ):
        __line()

            

    try:
        wfversion = pint( 'Version' )
    except:
        wfversion = 0

    if (wfversion < 1) or (wfversion > 55):
        err( "Invalid pre-proplib worldfile (didn't find version on first line)" )

    pbool( 'PassiveLockstep', 25, False )
    pint( 'MaxSteps', 18, 0 )
    pbool( 'EndOnPopulationCrash', 48, False )
    pignore( 'DoCpuWork' )
    pint( 'CheckPointFrequency' )
    pint( 'StatusFrequency' )
    pbool( 'Edges' )
    pbool( 'WrapAround' )
    pbool( 'Vision' )
    pbool( 'ShowVision' )
    pbool( 'StaticTimestepGeometry', 34, False )
    pbool( 'ParallelInitAgents', 55, False )
    pbool( 'ParallelInteract', 55, False )
    pbool( 'ParallelBrains', 55, True )
    pint( 'RetinaWidth' )
    pfloat( 'MaxVelocity' )
    pint( 'MinAgents' )
    pint( 'MaxAgents' )
    pint( 'InitAgents' )
    pint( 'SeedAgents', 9, 0 )
    pfloat( 'SeedMutationProbability', 9, 0.0 )
    pbool( 'SeedGenomeFromRun', 45, False )
    pbool( 'SeedPositionFromRun', 49, False )
    pint( 'MiscegenationDelay' )

    if wfversion >= 32:
        pint( 'InitFood' )
        pint( 'MinFood' )
        pint( 'MaxFood' )
        pint( 'MaxFoodGrown' )
        pfloat( 'FoodGrowthRate' )

    pfloat( 'FoodRemoveEnergy', 46, 0.0 )
    pint( 'PositionSeed' )
    pint( 'InitSeed' )
    pint( 'SimulationSeed', 44, 0 )
    
    if wfversion < 32:
        pint( 'MinFood' )
        pint( 'MaxFood' )
        pint( 'MaxFoodGrown' )
        pint( 'InitFood' )
        pfloat( 'FoodGrowthRate' )

    penum( 'AgentsAreFood', ['0','1','F'], values_new = ['False','True', 'Fight'] )
    pint( 'EliteFrequency' )
    pint( 'PairFrequency' )
    pint( 'NumberFittest' )
    pint( 'NumberRecentFittest', 14, 10 )
    pfloat( 'FitnessWeightEating' )
    pfloat( 'FitnessWeightMating' )
    pfloat( 'FitnessWeightMoving' )
    pfloat( 'FitnessWeightEnergyAtDeath' )
    pfloat( 'FitnessWeightLongevity' )
    pfloat( 'MinFoodEnergy' )
    pfloat( 'MaxFoodEnergy' )
    pfloat( 'FoodEnergySizeScale' )
    pfloat( 'FoodConsumptionRate' )
    penum( 'GenomeLayout', ['L','N'], 53, 'L' )
    pbool( 'EnableMateWaitFeedback', 48, False )
    pbool( 'EnableSpeedFeedback', 38, False )
    pbool( 'EnableGive', 38, False )
    pbool( 'EnableCarry', 39, False )
    pint( 'MaxCarries', 39, 0 )
    pbool( 'CarryAgents', 41, True )
    pbool( 'CarryFood', 41, True )
    pbool( 'CarryBricks', 41, True )
    pbool( 'ShieldAgents', 41, False )
    pbool( 'ShieldFood', 41, False )
    pbool( 'ShieldBricks', 41, False )
    pfloat( 'CarryPreventsEat', 41, 0.0 )
    pfloat( 'CarryPreventsFight', 41, 0.0 )
    pfloat( 'CarryPreventsGive', 41, 0.0 )
    pfloat( 'CarryPreventsMate', 41, 0.0 )
    pignore( 'MinInternalNeurons' )
    pignore( 'MaxInternalNeurons' )
    pint( 'MinVisionNeuronsPerGroup' )
    pint( 'MaxVisionNeuronsPerGroup' )
    pfloat( 'MinMutationRate' )
    pfloat( 'MaxMutationRate' )
    pint( 'MinCrossoverPoints' )
    pint( 'MaxCrossoverPoints' )
    pint( 'MinLifeSpan' )
    pint( 'MaxLifeSpan' )
    pint( 'MateWait' )
    pint( 'InitMateWait' )
    pint( 'EatMateWait', 29, 0 )
    pfloat( 'MinAgentStrength' )
    pfloat( 'MaxAgentStrength' )
    pfloat( 'MinAgentSize' )
    pfloat( 'MaxAgentSize' )
    pfloat( 'MinAgentMaxEnergy' )
    pfloat( 'MaxAgentMaxEnergy' )
    pfloat( 'MinEnergyFractionToOffspring' )
    pfloat( 'MaxEnergyFractionToOffspring' )
    pfloat( 'MinMateEnergyFraction' )
    pfloat( 'MinAgentMaxSpeed' )
    pfloat( 'MaxAgentMaxSpeed' )
    pfloat( 'MotionRate' )
    pfloat( 'YawRate' )
    pfloat( 'MinLearningRate' )
    pfloat( 'MaxLearningRate' )
    pfloat( 'MinHorizontalFieldOfView' )
    pfloat( 'MaxHorizontalFieldOfView' )
    pfloat( 'VerticalFieldOfView' )
    pfloat( 'MaxSizeFightAdvantage' )
    penum( 'BodyGreenChannel', ['I','L','$float'], 38, 'I' )
    penum( 'NoseColor', ['L','$float'], 38, 'L' )
    pfloat( 'DamageRate' )
    pfloat( 'EnergyUseEat' )
    pfloat( 'EnergyUseMate' )
    pfloat( 'EnergyUseFight' )
    pfloat( 'MinSizeEnergyPenalty', 47, 0 )
    pfloat( 'MaxSizeEnergyPenalty' )
    pfloat( 'EnergyUseMove' )
    pfloat( 'EnergyUseTurn' )
    pfloat( 'EnergyUseLight' )
    pfloat( 'EnergyUseFocus' )
    pfloat( 'EnergyUsePickup', 39, 0.5 )
    pfloat( 'EnergyUseDrop', 39, 0.001 )
    pfloat( 'EnergyUseCarryAgent', 39, 0.05 )
    pfloat( 'EnergyUseCarryAgentSize', 39, 0.05 )
    pfloat( 'EnergyUseCarryFood', 39, 0.01 )
    pfloat( 'EnergyUseCarryBrick', 39, 0.01 )
    pfloat( 'EnergyUseSynapses' )
    pfloat( 'EnergyUseFixed' )
    pfloat( 'SynapseWeightDecayRate' )
    pfloat( 'AgentHealingRate', 18, 0.0 )
    pfloat( 'EatThreshold' )
    pfloat( 'MateThreshold' )
    pfloat( 'FightThreshold' )
    pfloat( 'FightMultiplier', 43, 1.0 )
    pfloat( 'GiveThreshold', 38, 0.2 )
    pfloat( 'GiveFraction', 38, 1.0 )
    pfloat( 'PickupThreshold', 39, 0.5 )
    pfloat( 'DropThreshold', 39, 0.5 )
    pfloat( 'MiscegenationFunctionBias' )
    pfloat( 'MiscegenationFunctionInverseSlope' )
    pfloat( 'LogisticSlope' )
    pfloat( 'MaxSynapseWeight' )
    pbool( 'EnableInitWeightRngSeed', 52, False )
    pint( 'MinInitWeightRngSeed', 52, 0 )
    pint( 'MaxInitWeightRngSeed', 52, 0 )
    pfloat( 'MaxSynapseWeightInitial' )
    pfloat( 'MinInitialBitProb' )
    pfloat( 'MaxInitialBitProb' )
    pbool( 'SolidAgents', 31, False )
    pbool( 'SolidFood', 31, False )
    pbool( 'SolidBricks', 31, True )
    pfloat( 'AgentHeight' )
    pfloat( 'FoodHeight' )
    pcolor( 'FoodColor' )
    pfloat( 'BrickHeight', 47 )
    pcolor( 'BrickColor', 47, [0.6,0.2,0.2] )
    pfloat( 'BarrierHeight' )
    pcolor( 'BarrierColor' )
    pcolor( 'GroundColor' )
    pfloat( 'GroundClearance' )
    pcolor( 'CameraColor' )
    pfloat( 'CameraRadius' )
    pfloat( 'CameraHeight' )
    pfloat( 'CameraRotationRate' )
    pfloat( 'CameraAngleStart' )
    pfloat( 'CameraFieldOfView' )
    pint( 'MonitorAgentRank' )
    pignore( 'MonitorCritWinWidth' )
    pignore( 'MonitorCritWinHeight' )
    pint( 'BrainMonitorFrequency' )
    pfloat( 'WorldSize' )

    ###
    ### Barriers
    ###
    numBarriers = pint( 'NumBarriers' )
    pbool( 'RatioBarrierPositions', 47, False )

    barriers = push( 'Barriers', Container() )
    for i in range(numBarriers):
        barrier = push( i, Container() )

        if( wfversion >= 27 ):
            numKeyFrames = pint( 'NumKeyFrames' )
            keyFrames = push( 'KeyFrames', Container() )
            for j in range(numKeyFrames):
                push( j, Container() )
                pbarrierkeyframe( j )
                pop( j )
            pop( 'KeyFrames' )
        else:
            pbarrierpos( j )

        pop( i )
    pop( 'Barriers' )

    if wfversion < 2:
        return local.container

    pbool( 'MonitorGeneSeparation' )
    pbool( 'RecordGeneSeparation' )

    if wfversion < 3:
        return local.container

    pbool( 'ChartBorn' )
    pbool( 'ChartFitness' )
    pbool( 'ChartFoodEnergy' )
    pbool( 'ChartPopulation' )
    
    ###
    ### Domains
    ###
    numDomains = pint( 'NumDomains' )

    push( 'Domains', Container() )

    for i in range(numDomains):
        domain = push( i, Container() )

        if wfversion < 32:
            pint( 'MinAgents' )
            pint( 'MaxAgents' )
            pint( 'InitAgents' )
            pint( 'SeedAgents', 9, 0 )
            pfloat( 'ProbabilityOfMutatingSeeds', 9, 0.0 )

        if wfversion >= 19:
            pfloat( 'CenterX' )
            pfloat( 'CenterZ' )
            pfloat( 'SizeX' )
            pfloat( 'SizeZ' )
        
        if wfversion >= 32:
            pfloat( 'MinAgentsFraction' )
            pfloat( 'MaxAgentsFraction' )
            pfloat( 'InitAgentsFraction' )
            pfloat( 'InitSeedsFraction' )
            pfloat( 'ProbabilityOfMutatingSeeds' )
            pfloat( 'InitFoodFraction' )
            pfloat( 'MinFoodFraction' )
            pfloat( 'MaxFoodFraction' )
            pfloat( 'MaxFoodGrownFraction' )
            pfloat( 'FoodRate' )

            numFoodPatches = pint( 'NumFoodPatches' )
            numBrickPatches = pint( 'NumBrickPatches' )
        else:
            numFoodPatches = pint( 'NumFoodPatches' )
            numBrickPatches = pint( 'NumBrickPatches' )
            pfloat( 'FoodRate' )
            pint( 'InitFood' )
            pint( 'MinFood' )
            pint( 'MaxFood' )
            pint( 'MaxFoodGrownCount' )

        foodPatches = push( 'FoodPatches', Container() )

        for j in range( numFoodPatches ):
            push( j , Container() )

            pfloat( 'FoodFraction' )

            if wfversion >= 32:
                pfloat( 'InitFoodFraction' )
                pfloat( 'MinFoodFraction' )
                pfloat( 'MaxFoodFraction' )
                pfloat( 'MaxFoodGrownFraction' )
                pfloat( 'FoodRate' )
            else:
                pfloat( 'FoodRate' )
                pint( 'InitFood' )
                pint( 'MinFood' )
                pint( 'MaxFood' )
                pint( 'MaxFoodGrown' )
            
            pfloat( 'CenterX' )
            pfloat( 'CenterZ' )
            pfloat( 'SizeX' )
            pfloat( 'SizeZ' )
            penum( 'Shape', ['0','1'], values_new = ['R','E'] )
            penum( 'Distribution', ['0','1','2'], values_new = ['U','L','G'] )
            pfloat( 'NeighborhoodSize' )
            
            pint( 'Period', 26, 0 )
            pfloat( 'OnFraction', 26, 0.0 )
            pfloat( 'Phase', 26, 0.0 )
            pbool( 'RemoveFood', 26, False )

            pop( j )

        pop( 'FoodPatches' )
                

        brickPatches = push( 'BrickPatches', Container() )

        for j in range( numBrickPatches ):
            push( j, Container() )

            pfloat( 'CenterX' )
            pfloat( 'CenterZ' )
            pfloat( 'SizeX' )
            pfloat( 'SizeZ' )
            pint( 'BrickCount' )
            penum( 'Shape', ['0','1'], values_new = ['R','E'] )
            penum( 'Distribution', ['0','1','2'], values_new = ['U','L','G'] )
            pfloat( 'NeighborhoodSize' )

            pop( j )

        pop( 'BrickPatches' )
        
        pop( i )
    pop( 'Domains' )

    pbool( 'ProbabilisticFoodPatches', 17, False )

    if wfversion < 5:
        return local.container

    pbool( 'ChartGeneSeparation' )

    if wfversion < 6:
        return local.container

    penum( 'NeuronModel', ['F','S','T'], 36, 'F' )

    pfloat( 'TauMin', 50, 0.01 )
    pfloat( 'TauMax', 50, 1.0 )
    pfloat( 'TauSeed', 50, 1.0 )

    pint( 'MinInternalNeuralGroups' )
    pint( 'MaxInternalNeuralGroups' )
    pint( 'MinExcitatoryNeuronsPerGroup' )
    pint( 'MaxExcitatoryNeuronsPerGroup' )
    pint( 'MinInhibitoryNeuronsPerGroup' )
    pint( 'MaxInhibitoryNeuronsPerGroup' )
    pignore( 'MinBias' )
    pfloat( 'MaxBiasWeight' )
    pfloat( 'MinBiasLrate' )
    pfloat( 'MaxBiasLrate' )
    pfloat( 'MinConnectionDensity' )
    pfloat( 'MaxConnectionDensity' )
    pfloat( 'MinTopologicalDistortion' )
    pfloat( 'MaxTopologicalDistortion' )
    pbool( 'EnableTopologicalDistortionRngSeed', 50, False )
    pint( 'MinTopologicalDistortionRngSeed', 50, 0 )
    pint( 'MaxTopologicalDistortionRngSeed', 50, 255 )
    pfloat( 'EnergyUseNeurons' )
    pint( 'PreBirthCycles' )
    pfloat( 'SeedFightBias', 40, 0.5 )
    pfloat( 'SeedFightExcitation', 40, 1.0 )
    pfloat( 'SeedGiveBias', 40, 0.0 )

    if wfversion >= 39:
        pfloat( 'SeedPickupBias' )
        pfloat( 'SeedDropBias' )
        pfloat( 'SeedPickupExcitation' )
        pfloat( 'SeedDropExcitation' )

    pint( 'OverHeadRank' )
    pbool( 'AgentTracking' )
    pfloat( 'MinFoodEnergyAtDeath' )
    pbool( 'GrayCoding' )

    if wfversion < 7:
        return local.container

    penum( 'SmiteMode', ['L','R','O'], 21 )
    pfloat( 'SmiteFrac' )
    pfloat( 'SmiteAgeFrac' )

    pint( 'NumDepletionSteps', 23, 0 )
    pbool( 'ApplyLowPopulationAdvantage', 24, False )

    if wfversion < 8:
        return local.container

    pbool( 'RecordBirthsDeaths', 22, False )
    pbool( 'RecordPosition', 33, False )
    pbool( 'RecordContacts', 38, False )
    pbool( 'RecordCollisions', 38, False )
    pbool( 'RecordCarry', 42, False )

    pbool( 'BrainAnatomyRecordAll', 11, False )
    pbool( 'BrainFunctionRecordAll', 11, False )
    pbool( 'BrainAnatomyRecordSeeds', 12, False )
    pbool( 'BrainFunctionRecordSeeds', 12, False )
    pint( 'BestSoFarBrainAnatomyRecordFrequency', 11, False )
    pint( 'BestSoFarBrainFunctionRecordFrequency', 11, False )
    pint( 'BestRecentBrainAnatomyRecordFrequency', 14, False )
    pint( 'BestRecentBrainFunctionRecordFrequency', 14, False )
    pbool( 'RecordGeneStats', 12, False )
    pbool( 'RecordPerformanceStats', 35, False )
    pbool( 'RecordFoodPatchStats', 15, False )
    
    if wfversion >= 18:
        pbool( 'RecordComplexity' )
        if wfversion < 28:
            # this property is a bit odd in that it dramatically changed rules between versions.
            # this should probably be moved into the normalize function
            __scalar( 'ComplexityType', None, None, 'enum', lambda x: 'O' if x == '0' else 'P' )
        else:
            penum( 'ComplexityType',
                   ['O', 'P','A','I','B','D','Z'],
                   values_new = ['O', 'P','A','I','B','D','Z'] )
        if wfversion >= 30:
            pfloat( 'ComplexityFitnessWeight' )
            pfloat( 'HeuristicFitnessWeight' )
    
    pbool( 'RecordGenomes', 37, False )
    pbool( 'RecordSeparations', 38, False )
    pbool( 'RecordAdamiComplexity', 20, False )
    pint( 'AdamiComplexityRecordFrequency', 20, 0 )

    pbool( 'CompressFiles', 54, False )

    if wfversion >= 18:
        penum( 'FogFunction', ['E','L','O'] )
        pfloat( 'ExpFogDensity' )
        pint( 'LinearFogEnd' )

    pbool( 'RecordMovie' )
    
    return local.container
Example #31
0
				NUMBINS = int(value)
			except:
				show_usage("Invalid integer argument for --bins (%s)" % value)
		elif opt == 'r':
			recent_type = value
		else:
			assert(False)

	if not recent_type in common_functions.RECENT_TYPES:
		show_usage('Invalid recent type (%s).' % recent_type)

	if len(args) == 0:
		show_usage('Must specify run/run-parent directory.')

	if OverwriteEpochComplexities and LegacyMode != 'off':
		err( '-O makes no sense with -l' )

	paths = list(args)

	return complexities, recent_type, paths

####################################################################################
###
### analyze_recent_dir()
###
####################################################################################
def analyze_recent_dir(complexities, recent_dir):
	outputpath = os.path.join(recent_dir, OutputFilename);
	
	print "- recent directory='%s'" %(recent_dir)
	print "- output='%s'" % (outputpath)
Example #32
0
def parsePreProplib(path):
    f = open(path, 'r')

    def __line():
        while True:
            l = f.readline()

            tokens = l.split()
            n = len(tokens)
            if n == 1:
                err("unexpected format: '%s'" % l)

            if DEBUG:
                print 'READ LINE:', l

            if n > 0:
                return tokens[-1], tokens[:-1]

    class local:
        container = Container()

    def push(name, childContainer):
        local.container.add(name, 'container', childContainer)
        local.container = childContainer
        return childContainer

    def pop(name):
        assert (name == local.container.name)
        local.container = local.container.parent

    wfversion = -1

    def __scalar(name, version, default, type, func_parse):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != 1:
                err("expecting scalar for %s, found (%s,%s)" %
                    (name, label, val))
            val = func_parse(val[0])

            local.container.add(name, type, val)
        else:
            val = default

        return val

    def __tuple(name, count, version, default, type, func_parse):
        if version == None or version <= wfversion:
            label, val = __line()
            if len(val) != count:
                err("expecting tuple with %d elements for %s, found (%s,%s)" %
                    (count, name, label, val))
            val = map(func_parse, val)

            local.container.add(name, type, val)
        else:
            val = default

        return val

    def pint(name, version=None, default=None):
        return __scalar(name, version, default, 'int', int)

    def pfloat(name, version=None, default=None):
        return __scalar(name, version, default, 'float', float)

    def pbool(name, version=None, default=None):
        return __scalar(name, version, default, 'bool', lambda x: x != '0')

    def penum(name, values, version=None, default=None, values_new=None):
        if values_new == None:
            values_new = values
        type = 'enum(' + ','.join(values_new) + ')'
        val = __scalar(name, version, default, type,
                       lambda x: values_new[values.index(x)])
        assert (val in values_new)

        return val

    def pcolor(name, version=None, default=None):
        return __tuple(name, 3, version, default, 'color', float)

    def pbarrierkeyframe(name):
        label, val = __line()
        if len(val) != 5:
            err("expecting barrierkeyframe with 5 elements for %s, found (%s,%s)"
                % (name, label, val))
        val = [int(val[0])] + map(float, val[1:])

        local.container.add(name, 'barrierkeyframe', val)

        return val

    def pbarrierpos(name):
        label, val = __line()
        if len(val) != 4:
            err("expecting barrierkeyframe with 4 elements for %s, found (%s,%s)"
                % (name, label, val))
        val = map(float, val)

        local.container.add(name, 'barrierpos', val)

        return val

    def pignore(name):
        __line()

    try:
        wfversion = pint('Version')
    except:
        wfversion = 0

    if (wfversion < 1) or (wfversion > 55):
        err("Invalid pre-proplib worldfile (didn't find version on first line)"
            )

    pbool('PassiveLockstep', 25, False)
    pint('MaxSteps', 18, 0)
    pbool('EndOnPopulationCrash', 48, False)
    pignore('DoCpuWork')
    pint('CheckPointFrequency')
    pint('StatusFrequency')
    pbool('Edges')
    pbool('WrapAround')
    pbool('Vision')
    pbool('ShowVision')
    pbool('StaticTimestepGeometry', 34, False)
    pbool('ParallelInitAgents', 55, False)
    pbool('ParallelInteract', 55, False)
    pbool('ParallelBrains', 55, True)
    pint('RetinaWidth')
    pfloat('MaxVelocity')
    pint('MinAgents')
    pint('MaxAgents')
    pint('InitAgents')
    pint('SeedAgents', 9, 0)
    pfloat('SeedMutationProbability', 9, 0.0)
    pbool('SeedGenomeFromRun', 45, False)
    pbool('SeedPositionFromRun', 49, False)
    pint('MiscegenationDelay')

    if wfversion >= 32:
        pint('InitFood')
        pint('MinFood')
        pint('MaxFood')
        pint('MaxFoodGrown')
        pfloat('FoodGrowthRate')

    pfloat('FoodRemoveEnergy', 46, 0.0)
    pint('PositionSeed')
    pint('InitSeed')
    pint('SimulationSeed', 44, 0)

    if wfversion < 32:
        pint('MinFood')
        pint('MaxFood')
        pint('MaxFoodGrown')
        pint('InitFood')
        pfloat('FoodGrowthRate')

    penum('AgentsAreFood', ['0', '1', 'F'],
          values_new=['False', 'True', 'Fight'])
    pint('EliteFrequency')
    pint('PairFrequency')
    pint('NumberFittest')
    pint('NumberRecentFittest', 14, 10)
    pfloat('FitnessWeightEating')
    pfloat('FitnessWeightMating')
    pfloat('FitnessWeightMoving')
    pfloat('FitnessWeightEnergyAtDeath')
    pfloat('FitnessWeightLongevity')
    pfloat('MinFoodEnergy')
    pfloat('MaxFoodEnergy')
    pfloat('FoodEnergySizeScale')
    pfloat('FoodConsumptionRate')
    penum('GenomeLayout', ['L', 'N'], 53, 'L')
    pbool('EnableMateWaitFeedback', 48, False)
    pbool('EnableSpeedFeedback', 38, False)
    pbool('EnableGive', 38, False)
    pbool('EnableCarry', 39, False)
    pint('MaxCarries', 39, 0)
    pbool('CarryAgents', 41, True)
    pbool('CarryFood', 41, True)
    pbool('CarryBricks', 41, True)
    pbool('ShieldAgents', 41, False)
    pbool('ShieldFood', 41, False)
    pbool('ShieldBricks', 41, False)
    pfloat('CarryPreventsEat', 41, 0.0)
    pfloat('CarryPreventsFight', 41, 0.0)
    pfloat('CarryPreventsGive', 41, 0.0)
    pfloat('CarryPreventsMate', 41, 0.0)
    pignore('MinInternalNeurons')
    pignore('MaxInternalNeurons')
    pint('MinVisionNeuronsPerGroup')
    pint('MaxVisionNeuronsPerGroup')
    pfloat('MinMutationRate')
    pfloat('MaxMutationRate')
    pint('MinCrossoverPoints')
    pint('MaxCrossoverPoints')
    pint('MinLifeSpan')
    pint('MaxLifeSpan')
    pint('MateWait')
    pint('InitMateWait')
    pint('EatMateWait', 29, 0)
    pfloat('MinAgentStrength')
    pfloat('MaxAgentStrength')
    pfloat('MinAgentSize')
    pfloat('MaxAgentSize')
    pfloat('MinAgentMaxEnergy')
    pfloat('MaxAgentMaxEnergy')
    pfloat('MinEnergyFractionToOffspring')
    pfloat('MaxEnergyFractionToOffspring')
    pfloat('MinMateEnergyFraction')
    pfloat('MinAgentMaxSpeed')
    pfloat('MaxAgentMaxSpeed')
    pfloat('MotionRate')
    pfloat('YawRate')
    pfloat('MinLearningRate')
    pfloat('MaxLearningRate')
    pfloat('MinHorizontalFieldOfView')
    pfloat('MaxHorizontalFieldOfView')
    pfloat('VerticalFieldOfView')
    pfloat('MaxSizeFightAdvantage')
    penum('BodyGreenChannel', ['I', 'L', '$float'], 38, 'I')
    penum('NoseColor', ['L', '$float'], 38, 'L')
    pfloat('DamageRate')
    pfloat('EnergyUseEat')
    pfloat('EnergyUseMate')
    pfloat('EnergyUseFight')
    pfloat('MinSizeEnergyPenalty', 47, 0)
    pfloat('MaxSizeEnergyPenalty')
    pfloat('EnergyUseMove')
    pfloat('EnergyUseTurn')
    pfloat('EnergyUseLight')
    pfloat('EnergyUseFocus')
    pfloat('EnergyUsePickup', 39, 0.5)
    pfloat('EnergyUseDrop', 39, 0.001)
    pfloat('EnergyUseCarryAgent', 39, 0.05)
    pfloat('EnergyUseCarryAgentSize', 39, 0.05)
    pfloat('EnergyUseCarryFood', 39, 0.01)
    pfloat('EnergyUseCarryBrick', 39, 0.01)
    pfloat('EnergyUseSynapses')
    pfloat('EnergyUseFixed')
    pfloat('SynapseWeightDecayRate')
    pfloat('AgentHealingRate', 18, 0.0)
    pfloat('EatThreshold')
    pfloat('MateThreshold')
    pfloat('FightThreshold')
    pfloat('FightMultiplier', 43, 1.0)
    pfloat('GiveThreshold', 38, 0.2)
    pfloat('GiveFraction', 38, 1.0)
    pfloat('PickupThreshold', 39, 0.5)
    pfloat('DropThreshold', 39, 0.5)
    pfloat('MiscegenationFunctionBias')
    pfloat('MiscegenationFunctionInverseSlope')
    pfloat('LogisticSlope')
    pfloat('MaxSynapseWeight')
    pbool('EnableInitWeightRngSeed', 52, False)
    pint('MinInitWeightRngSeed', 52, 0)
    pint('MaxInitWeightRngSeed', 52, 0)
    pfloat('MaxSynapseWeightInitial')
    pfloat('MinInitialBitProb')
    pfloat('MaxInitialBitProb')
    pbool('SolidAgents', 31, False)
    pbool('SolidFood', 31, False)
    pbool('SolidBricks', 31, True)
    pfloat('AgentHeight')
    pfloat('FoodHeight')
    pcolor('FoodColor')
    pfloat('BrickHeight', 47)
    pcolor('BrickColor', 47, [0.6, 0.2, 0.2])
    pfloat('BarrierHeight')
    pcolor('BarrierColor')
    pcolor('GroundColor')
    pfloat('GroundClearance')
    pcolor('CameraColor')
    pfloat('CameraRadius')
    pfloat('CameraHeight')
    pfloat('CameraRotationRate')
    pfloat('CameraAngleStart')
    pfloat('CameraFieldOfView')
    pint('MonitorAgentRank')
    pignore('MonitorCritWinWidth')
    pignore('MonitorCritWinHeight')
    pint('BrainMonitorFrequency')
    pfloat('WorldSize')

    ###
    ### Barriers
    ###
    numBarriers = pint('NumBarriers')
    pbool('RatioBarrierPositions', 47, False)

    barriers = push('Barriers', Container())
    for i in range(numBarriers):
        barrier = push(i, Container())

        if (wfversion >= 27):
            numKeyFrames = pint('NumKeyFrames')
            keyFrames = push('KeyFrames', Container())
            for j in range(numKeyFrames):
                push(j, Container())
                pbarrierkeyframe(j)
                pop(j)
            pop('KeyFrames')
        else:
            pbarrierpos(j)

        pop(i)
    pop('Barriers')

    if wfversion < 2:
        return local.container

    pbool('MonitorGeneSeparation')
    pbool('RecordGeneSeparation')

    if wfversion < 3:
        return local.container

    pbool('ChartBorn')
    pbool('ChartFitness')
    pbool('ChartFoodEnergy')
    pbool('ChartPopulation')

    ###
    ### Domains
    ###
    numDomains = pint('NumDomains')

    push('Domains', Container())

    for i in range(numDomains):
        domain = push(i, Container())

        if wfversion < 32:
            pint('MinAgents')
            pint('MaxAgents')
            pint('InitAgents')
            pint('SeedAgents', 9, 0)
            pfloat('ProbabilityOfMutatingSeeds', 9, 0.0)

        if wfversion >= 19:
            pfloat('CenterX')
            pfloat('CenterZ')
            pfloat('SizeX')
            pfloat('SizeZ')

        if wfversion >= 32:
            pfloat('MinAgentsFraction')
            pfloat('MaxAgentsFraction')
            pfloat('InitAgentsFraction')
            pfloat('InitSeedsFraction')
            pfloat('ProbabilityOfMutatingSeeds')
            pfloat('InitFoodFraction')
            pfloat('MinFoodFraction')
            pfloat('MaxFoodFraction')
            pfloat('MaxFoodGrownFraction')
            pfloat('FoodRate')

            numFoodPatches = pint('NumFoodPatches')
            numBrickPatches = pint('NumBrickPatches')
        else:
            numFoodPatches = pint('NumFoodPatches')
            numBrickPatches = pint('NumBrickPatches')
            pfloat('FoodRate')
            pint('InitFood')
            pint('MinFood')
            pint('MaxFood')
            pint('MaxFoodGrownCount')

        foodPatches = push('FoodPatches', Container())

        for j in range(numFoodPatches):
            push(j, Container())

            pfloat('FoodFraction')

            if wfversion >= 32:
                pfloat('InitFoodFraction')
                pfloat('MinFoodFraction')
                pfloat('MaxFoodFraction')
                pfloat('MaxFoodGrownFraction')
                pfloat('FoodRate')
            else:
                pfloat('FoodRate')
                pint('InitFood')
                pint('MinFood')
                pint('MaxFood')
                pint('MaxFoodGrown')

            pfloat('CenterX')
            pfloat('CenterZ')
            pfloat('SizeX')
            pfloat('SizeZ')
            penum('Shape', ['0', '1'], values_new=['R', 'E'])
            penum('Distribution', ['0', '1', '2'], values_new=['U', 'L', 'G'])
            pfloat('NeighborhoodSize')

            pint('Period', 26, 0)
            pfloat('OnFraction', 26, 0.0)
            pfloat('Phase', 26, 0.0)
            pbool('RemoveFood', 26, False)

            pop(j)

        pop('FoodPatches')

        brickPatches = push('BrickPatches', Container())

        for j in range(numBrickPatches):
            push(j, Container())

            pfloat('CenterX')
            pfloat('CenterZ')
            pfloat('SizeX')
            pfloat('SizeZ')
            pint('BrickCount')
            penum('Shape', ['0', '1'], values_new=['R', 'E'])
            penum('Distribution', ['0', '1', '2'], values_new=['U', 'L', 'G'])
            pfloat('NeighborhoodSize')

            pop(j)

        pop('BrickPatches')

        pop(i)
    pop('Domains')

    pbool('ProbabilisticFoodPatches', 17, False)

    if wfversion < 5:
        return local.container

    pbool('ChartGeneSeparation')

    if wfversion < 6:
        return local.container

    penum('NeuronModel', ['F', 'S', 'T'], 36, 'F')

    pfloat('TauMin', 50, 0.01)
    pfloat('TauMax', 50, 1.0)
    pfloat('TauSeed', 50, 1.0)

    pint('MinInternalNeuralGroups')
    pint('MaxInternalNeuralGroups')
    pint('MinExcitatoryNeuronsPerGroup')
    pint('MaxExcitatoryNeuronsPerGroup')
    pint('MinInhibitoryNeuronsPerGroup')
    pint('MaxInhibitoryNeuronsPerGroup')
    pignore('MinBias')
    pfloat('MaxBiasWeight')
    pfloat('MinBiasLrate')
    pfloat('MaxBiasLrate')
    pfloat('MinConnectionDensity')
    pfloat('MaxConnectionDensity')
    pfloat('MinTopologicalDistortion')
    pfloat('MaxTopologicalDistortion')
    pbool('EnableTopologicalDistortionRngSeed', 50, False)
    pint('MinTopologicalDistortionRngSeed', 50, 0)
    pint('MaxTopologicalDistortionRngSeed', 50, 255)
    pfloat('EnergyUseNeurons')
    pint('PreBirthCycles')
    pfloat('SeedFightBias', 40, 0.5)
    pfloat('SeedFightExcitation', 40, 1.0)
    pfloat('SeedGiveBias', 40, 0.0)

    if wfversion >= 39:
        pfloat('SeedPickupBias')
        pfloat('SeedDropBias')
        pfloat('SeedPickupExcitation')
        pfloat('SeedDropExcitation')

    pint('OverHeadRank')
    pbool('AgentTracking')
    pfloat('MinFoodEnergyAtDeath')
    pbool('GrayCoding')

    if wfversion < 7:
        return local.container

    penum('SmiteMode', ['L', 'R', 'O'], 21)
    pfloat('SmiteFrac')
    pfloat('SmiteAgeFrac')

    pint('NumDepletionSteps', 23, 0)
    pbool('ApplyLowPopulationAdvantage', 24, False)

    if wfversion < 8:
        return local.container

    pbool('RecordBirthsDeaths', 22, False)
    pbool('RecordPosition', 33, False)
    pbool('RecordContacts', 38, False)
    pbool('RecordCollisions', 38, False)
    pbool('RecordCarry', 42, False)

    pbool('BrainAnatomyRecordAll', 11, False)
    pbool('BrainFunctionRecordAll', 11, False)
    pbool('BrainAnatomyRecordSeeds', 12, False)
    pbool('BrainFunctionRecordSeeds', 12, False)
    pint('BestSoFarBrainAnatomyRecordFrequency', 11, False)
    pint('BestSoFarBrainFunctionRecordFrequency', 11, False)
    pint('BestRecentBrainAnatomyRecordFrequency', 14, False)
    pint('BestRecentBrainFunctionRecordFrequency', 14, False)
    pbool('RecordGeneStats', 12, False)
    pbool('RecordPerformanceStats', 35, False)
    pbool('RecordFoodPatchStats', 15, False)

    if wfversion >= 18:
        pbool('RecordComplexity')
        if wfversion < 28:
            # this property is a bit odd in that it dramatically changed rules between versions.
            # this should probably be moved into the normalize function
            __scalar('ComplexityType', None, None, 'enum', lambda x: 'O'
                     if x == '0' else 'P')
        else:
            penum('ComplexityType', ['O', 'P', 'A', 'I', 'B', 'D', 'Z'],
                  values_new=['O', 'P', 'A', 'I', 'B', 'D', 'Z'])
        if wfversion >= 30:
            pfloat('ComplexityFitnessWeight')
            pfloat('HeuristicFitnessWeight')

    pbool('RecordGenomes', 37, False)
    pbool('RecordSeparations', 38, False)
    pbool('RecordAdamiComplexity', 20, False)
    pint('AdamiComplexityRecordFrequency', 20, 0)

    pbool('CompressFiles', 54, False)

    if wfversion >= 18:
        penum('FogFunction', ['E', 'L', 'O'])
        pfloat('ExpFogDensity')
        pint('LinearFogEnd')

    pbool('RecordMovie')

    return local.container
Example #33
0
def analyze_recent_dir(complexities, recent_dir):
    outputpath = os.path.join(recent_dir, OutputFilename)

    print "- recent directory='%s'" % (recent_dir)
    print "- output='%s'" % (outputpath)

    #-----------------------------------------------------------------------------------
    #--
    #-- Find epoch/timestep directories
    #--
    #-----------------------------------------------------------------------------------
    timesteps = []
    # list all of the timesteps, make sure they are all integers (and directories), then sort them by number.
    for potential_timestep in os.listdir(recent_dir):
        if not potential_timestep.isdigit():
            continue  # if timestep IS NOT a digit (note, 0 is considered a digit), skip.
        if not os.path.isdir(os.path.join(recent_dir, potential_timestep)):
            continue  # if the timestep isn't a directory, skip it.

        timesteps.append(int(potential_timestep))  # add timestep to our list

    if len(timesteps) == 0:
        err('No epochs found. Not a valid recent directory.')

    timesteps.sort()  # sort the timesteps, lowest numbers come first.

    #-----------------------------------------------------------------------------------
    #--
    #-- Compute complexities for all timesteps
    #--
    #-- (store values to file in timestep dir)
    #--
    #-----------------------------------------------------------------------------------
    DATA = {}

    print "Final Timestep: %s" % (max(timesteps))
    print datetime.datetime.now()
    print "Processing:",

    for t in timesteps:
        timestep_directory = os.path.join(recent_dir, str(t))
        print '%s at %s...' % (t, datetime.datetime.now())
        sys.stdout.flush()

        DATA[t] = tdata = {}

        complexities_remaining = complexities

        if LegacyMode != 'off':
            complexities_read = read_legacy_complexities(
                complexities_remaining, timestep_directory, tdata)
            complexities_remaining = list_difference(complexities_remaining,
                                                     complexities_read)
            if len(complexities_remaining) != 0:
                if LegacyMode == 'force':
                    err('Failed to find data for %s' %
                        ','.join(complexities_remaining))

            print '  Legacy =', complexities_read

        if len(complexities_remaining) > 0:
            complexities_computed = compute_complexities(
                complexities_remaining, t, timestep_directory, tdata)
            complexities_remaining = list_difference(complexities_remaining,
                                                     complexities_computed)

        assert (len(complexities_remaining) == 0)

    #-----------------------------------------------------------------------------------
    #--
    #-- Create 'Avr' File
    #--
    #-----------------------------------------------------------------------------------
    AVR = algorithms.avr_table(DATA, complexities, timesteps)

    datalib.write(outputpath, AVR, append=True)

    #-----------------------------------------------------------------------------------
    #--
    #-- Create 'Norm' file
    #--
    #-----------------------------------------------------------------------------------
    tables = compute_bins(DATA, timesteps, complexities, AVR,
                          lambda row: row.get('min'),
                          lambda row: row.get('max'))

    outputpath = os.path.join(recent_dir,
                              OutputFilename2.replace('.', 'Norm.'))

    datalib.write(outputpath, tables)

    #-----------------------------------------------------------------------------------
    #--
    #-- Create 'Raw' file
    #--
    #-----------------------------------------------------------------------------------
    MAXGLOBAL = dict([(type, float('-inf')) for type in complexities])
    MINGLOBAL = dict([(type, float('inf')) for type in complexities])

    for avr_table in AVR.values():
        for row in avr_table.rows():
            type = avr_table.name

            MAXGLOBAL[type] = max(MAXGLOBAL[type], row.get('max'))
            MINGLOBAL[type] = min(MINGLOBAL[type], row.get('min'))

    tables = compute_bins(DATA, timesteps, complexities, AVR,
                          lambda row: MINGLOBAL[row.table.name],
                          lambda row: MAXGLOBAL[row.table.name])

    outputpath = os.path.join(recent_dir, OutputFilename2.replace('.', 'Raw.'))

    datalib.write(outputpath, tables)
Example #34
0
    long = []

    try:
        opts, args = getopt.getopt(argv, short, long)
    except getopt.GetoptError, e:
        show_usage(str(e))

    for opt, value in opts:
        opt = opt.strip('-')

        if opt == 'd':
            try:
                recent_type = common_functions.expand_abbreviations(
                    value, common_functions.RECENT_TYPES, case_sensitive=False)
            except common_functions.IllegalAbbreviationError, x:
                err(str(x))
        else:
            assert (False)

    if len(args) == 0:
        show_usage('Must specify run/run-parent directory.')

    paths = list(args)

    return recent_type, paths


####################################################################################
###
### analyze_recent_dir()
###
Example #35
0
#!/usr/bin/env python

from sys import argv, exit
from os import path

import common_functions
import wfutil

if len(argv) != 3:
           ################################################################################
    print "usage:", path.basename(argv[0]), "worldfile propname"
    exit(1)

worldfile = argv[1]
param = argv[2]

value = wfutil.get_parameter( worldfile, param, assume_run_dir = False )

if value != None:
    print value
else:
    common_functions.err( "Cannot find property '%s' in %s" % (param,worldfile) 
)
	try:
		opts, args = getopt.getopt(argv, short, long)
	except getopt.GetoptError, e:
		show_usage(str(e))

	for opt, value in opts:
		opt = opt.strip('-')

		if opt == 'd':
			try:
				recent_type = common_functions.expand_abbreviations( value,
											 common_functions.RECENT_TYPES,
											 case_sensitive = False )
			except common_functions.IllegalAbbreviationError, x:
				err(str(x))
		else:
			assert(False)

	if len(args) == 0:
		show_usage('Must specify run/run-parent directory.')
	
	paths = list(args)

	return recent_type, paths

####################################################################################
###
### analyze_recent_dir()
###
####################################################################################
Example #37
0
def analyze_recent_dir(complexities, recent_dir):
	outputpath = os.path.join(recent_dir, OutputFilename);
	
	print "- recent directory='%s'" %(recent_dir)
	print "- output='%s'" % (outputpath)
	
	#-----------------------------------------------------------------------------------
	#--
	#-- Find epoch/timestep directories
	#--
	#-----------------------------------------------------------------------------------
	timesteps = []
	# list all of the timesteps, make sure they are all integers (and directories), then sort them by number.
	for potential_timestep in os.listdir( recent_dir ):
		if not potential_timestep.isdigit(): continue					# if timestep IS NOT a digit (note, 0 is considered a digit), skip.
		if not os.path.isdir( os.path.join(recent_dir, potential_timestep) ): continue	# if the timestep isn't a directory, skip it.
	
		timesteps.append( int(potential_timestep) )						# add timestep to our list
	
	if len(timesteps) == 0:
		err('No epochs found. Not a valid recent directory.')

	timesteps.sort()									# sort the timesteps, lowest numbers come first.
	
	#-----------------------------------------------------------------------------------
	#--
	#-- Compute complexities for all timesteps
	#--
	#-- (store values to file in timestep dir)
	#--
	#-----------------------------------------------------------------------------------
	DATA={ }
	
	print "Final Timestep: %s" % ( max(timesteps) )
	print "Processing:",
	
	for t in timesteps:
		timestep_directory = os.path.join(recent_dir, str(t))
		print '%s...\n' % (t),
		sys.stdout.flush()	
	
		DATA[t] = tdata = {}

		complexities_remaining = complexities

		if LegacyMode != 'off' :
			complexities_read = read_legacy_complexities(complexities_remaining,
								     timestep_directory,
								     tdata)
			complexities_remaining = list_difference(complexities_remaining,
								 complexities_read)
			if len(complexities_remaining) != 0:
				if LegacyMode == 'force':
					err('Failed to find data for %s' % ','.join(complexities_remaining))
			
			print '  Legacy =', complexities_read

		if len(complexities_remaining) > 0:
			complexities_computed = compute_complexities(complexities_remaining,
								     timestep_directory,
								     tdata)
			complexities_remaining = list_difference(complexities_remaining,
								 complexities_computed)

		assert(len(complexities_remaining) == 0)
	
	#-----------------------------------------------------------------------------------
	#--
	#-- Create 'Avr' File
	#--
	#-----------------------------------------------------------------------------------
	AVR = algorithms.avr_table(DATA,
				   complexities,
				   timesteps)
	
	datalib.write(outputpath, AVR, append=True)
	
	
	#-----------------------------------------------------------------------------------
	#--
	#-- Create 'Norm' file
	#--
	#-----------------------------------------------------------------------------------
	tables = compute_bins(DATA,
			      timesteps,
			      complexities,
			      AVR,
			      lambda row: row.get('min'),
			      lambda row: row.get('max'))
	
	outputpath = os.path.join(recent_dir, OutputFilename2.replace( '.', 'Norm.'))
	
	datalib.write(outputpath, tables)
	
	
	#-----------------------------------------------------------------------------------
	#--
	#-- Create 'Raw' file
	#--
	#-----------------------------------------------------------------------------------
	MAXGLOBAL = dict([(type, float('-inf')) for type in complexities])
	MINGLOBAL = dict([(type, float('inf')) for type in complexities])
	
	for avr_table in AVR.values():
		for row in avr_table.rows():
			type = avr_table.name
	
			MAXGLOBAL[type] = max(MAXGLOBAL[type], row.get('max'));
			MINGLOBAL[type] = min(MINGLOBAL[type], row.get('min'));
	
	tables = compute_bins(DATA,
			      timesteps,
			      complexities,
			      AVR,
			      lambda row: MINGLOBAL[row.table.name],
			      lambda row: MAXGLOBAL[row.table.name])
	
	outputpath = os.path.join(recent_dir, OutputFilename2.replace( '.', 'Raw.'))
	
	datalib.write(outputpath, tables)
Example #38
0
                NUMBINS = int(value)
            except:
                show_usage("Invalid integer argument for --bins (%s)" % value)
        elif opt == 'r':
            recent_type = value
        else:
            assert (False)

    if not recent_type in common_functions.RECENT_TYPES:
        show_usage('Invalid recent type (%s).' % recent_type)

    if len(args) == 0:
        show_usage('Must specify run/run-parent directory.')

    if OverwriteEpochComplexities and LegacyMode != 'off':
        err('-O makes no sense with -l')

    paths = list(args)

    return complexities, recent_type, paths


####################################################################################
###
### analyze_recent_dir()
###
####################################################################################
def analyze_recent_dir(complexities, recent_dir):
    outputpath = os.path.join(recent_dir, OutputFilename)

    print "- recent directory='%s'" % (recent_dir)