Ejemplo n.º 1
0
Archivo: dpso.py Proyecto: bazk/srs2d
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-v", "--verbosity",        help="increase output verbosity", action="count")
    parser.add_argument("-q", "--quiet",            help="supress output (except errors)", action="store_true")
    parser.add_argument("--device-type",            help="device type (all, gpu or cpu), default is all", type=str, default='all')
    parser.add_argument("--no-save",                help="skip saving best fitness simulation", action="store_true")
    parser.add_argument("-w", "--inertia",          help="set PSO inertia (W) parameter, default is 0.9", type=float, default=0.9)
    parser.add_argument("-a", "--alfa",             help="set PSO alfa parameter, default is 2.0", type=float, default=2)
    parser.add_argument("-b", "--beta",             help="set PSO beta parameter, default is 2.0", type=float, default=2)
    parser.add_argument("--ta",                     help="number of timesteps without fitness avaliation, default is 600", type=int, default=600)
    parser.add_argument("--tb",                     help="number of timesteps with fitness avaliation, default is 5400", type=int, default=5400)
    parser.add_argument("-g", "--num-generations",  help="number of generations, default is 500", type=int, default=500)
    parser.add_argument("-r", "--num-runs",         help="number of runs, default is 3", type=int, default=3)
    parser.add_argument("-n", "--num-robots",       help="number of robots, default is 10", type=int, default=10)
    parser.add_argument("-p", "--population-size",  help="PSO population size (particles), default is 10", type=int, default=10)
    parser.add_argument("--targets-distances",      help="list of distances between target areas to be evaluated \
        each generation, default is 0.7 0.9 1.1 1.3 1.5", type=float, nargs='+', default=[0.7, 0.9, 1.1, 1.3, 1.5])
    parser.add_argument("--targets-angles",         help="list of axis angles where the target areas \
        are located each trial (between 0 and PI), default is [3*pi/4]", type=float, nargs='+', default=[2.356194490192345])
    parser.add_argument("--random-targets",         help="place targets at random position (obeying targets distances)", action="store_true")
    parser.add_argument("--symetrical-targets",     help="place targets at symetrical position", action="store_true")
    parser.add_argument("-t", "--trials",           help="number of trials per distance, default is 3", type=int, default=3)
    args = parser.parse_args()

    if args.verbosity >= 2:
        __log__.setLevel(logging.DEBUG)
    elif args.verbosity == 1:
        __log__.setLevel(logging.INFO)
    else:
        __log__.setLevel(logging.WARNING)

    if args.quiet:
        __log__.setLevel(logging.ERROR)

    uri = os.environ.get('SOLACE_URI')
    username = os.environ.get('SOLACE_USERNAME')
    password = os.environ.get('SOLACE_PASSWORD')

    try:
        git_version = subprocess.check_output('git describe --tags --long'.split(), stderr=subprocess.STDOUT).replace('\n', '')
    except:
        git_version = None

    if (uri is None) or (username is None) or (password is None):
        raise Exception('Environment variables (SOLACE_URI, SOLACE_USERNAME, SOLACE_PASSWORD) not set!')

    device_type = cl.device_type.ALL
    if args.device_type == 'cpu':
        device_type = cl.device_type.CPU
    elif args.device_type == 'gpu':
        device_type = cl.device_type.GPU

    platform = cl.get_platforms()[0]
    devices = platform.get_devices(device_type=device_type)
    context = cl.Context(devices=devices)
    queue = cl.CommandQueue(context)

    exp = solace.get_experiment(uri, username, password)
    inst = exp.create_instance(args.num_runs, {
        'W': args.inertia,
        'ALFA': args.alfa,
        'BETA': args.beta,
        'STEPS_TA': args.ta,
        'STEPS_TB': args.tb,
        'NUM_GENERATIONS': args.num_generations,
        'NUM_RUNS': args.num_runs,
        'NUM_ROBOTS': args.num_robots,
        'POPULATION_SIZE': args.population_size,
        'TARGETS_DISTANCES': args.targets_distances,
        'TARGETS_ANGLES': args.targets_angles,
        'TRIALS': args.trials,
        'RANDOM_TARGETS': 1 if args.random_targets else 0,
        'SYMETRICAL_TARGETS': 1 if args.symetrical_targets else 0
    }, code_version=git_version)

    for run in inst.runs:
        DiscretePSO(context, queue).execute(run, args)
Ejemplo n.º 2
0
Archivo: pga.py Proyecto: bazk/srs2d
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-v", "--verbosity", help="increase output verbosity", action="count")
    parser.add_argument("-q", "--quiet", help="supress output (except errors)", action="store_true")
    parser.add_argument("--device-type", help="device type (all, gpu or cpu), default is all", type=str, default="all")
    parser.add_argument("--islands-per-device", help="number of islands per device, default is 1", type=int, default=1)
    parser.add_argument("--no-save", help="skip saving best fitness simulation", action="store_true")
    parser.add_argument(
        "--ta", help="number of timesteps without fitness avaliation, default is 600", type=int, default=600
    )
    parser.add_argument(
        "--tb", help="number of timesteps with fitness avaliation, default is 5400", type=int, default=5400
    )
    parser.add_argument("-g", "--num-generations", help="number of generations, default is 500", type=int, default=500)
    parser.add_argument("-r", "--num-runs", help="number of runs, default is 3", type=int, default=3)
    parser.add_argument("-n", "--num-robots", help="number of robots, default is 10", type=int, default=10)
    parser.add_argument(
        "-p", "--population-size", help="population size (genomes), default is 120", type=int, default=120
    )
    parser.add_argument(
        "--targets-distances",
        help="list of distances between target areas to be evaluated \
        each generation, default is 0.7 0.9 1.1 1.3 1.5",
        type=float,
        nargs="+",
        default=[0.7, 0.9, 1.1, 1.3, 1.5],
    )
    parser.add_argument(
        "--targets-angles",
        help="list of axis angles where the target areas \
        are located each trial (between 0 and PI), default is [3*pi/4]",
        type=float,
        nargs="+",
        default=[2.356194490192345],
    )
    parser.add_argument(
        "--random-targets", help="place targets at random position (obeying targets distances)", action="store_true"
    )
    parser.add_argument("--symetrical-targets", help="place targets at symetrical position", action="store_true")
    parser.add_argument("-t", "--trials", help="number of trials per distance, default is 3", type=int, default=3)
    parser.add_argument("-c", "--pcrossover", help="probability of crossover, default is 0.9", type=float, default=0.9)
    parser.add_argument("-m", "--pmutation", help="probability of mutation, default is 0.03", type=float, default=0.03)
    parser.add_argument(
        "-o",
        "--offspring",
        help="number of children each couple of indivuals generate, MUST BE EVEN, default is 6",
        type=int,
        default=6,
    )
    parser.add_argument("-e", "--elite-size", help="size of population elite, default is 24", type=int, default=24)
    parser.add_argument(
        "--migration-rate",
        help="proportion of individual of a population that migrate, default is 0.1",
        type=float,
        default=0.1,
    )
    parser.add_argument(
        "--migration-freq", help="frequency of migration (in generations), default is 10", type=int, default=10
    )
    args = parser.parse_args()

    if args.verbosity >= 2:
        __log__.setLevel(logging.DEBUG)
    elif args.verbosity == 1:
        __log__.setLevel(logging.INFO)
    else:
        __log__.setLevel(logging.WARNING)

    if args.quiet:
        __log__.setLevel(logging.ERROR)

    if (args.offspring % 2) != 0:
        __log__.error("Offspring must be an even number!")
        sys.exit(1)

    uri = os.environ.get("SOLACE_URI")
    username = os.environ.get("SOLACE_USERNAME")
    password = os.environ.get("SOLACE_PASSWORD")

    try:
        git_version = subprocess.check_output("git describe --tags --long".split(), stderr=subprocess.STDOUT).replace(
            "\n", ""
        )
    except:
        git_version = None

    if (uri is None) or (username is None) or (password is None):
        raise Exception("Environment variables (SOLACE_URI, SOLACE_USERNAME, SOLACE_PASSWORD) not set!")

    device_type = cl.device_type.ALL
    if args.device_type == "cpu":
        device_type = cl.device_type.CPU
    elif args.device_type == "gpu":
        device_type = cl.device_type.GPU

    platform = cl.get_platforms()[0]
    devices = platform.get_devices(device_type=device_type)
    context = cl.Context(devices=devices)

    exp = solace.get_experiment(uri, username, password)
    inst = exp.create_instance(
        args.num_runs,
        {
            "PCROSSOVER": args.pcrossover,
            "PMUTATION": args.pmutation,
            "ELITE_SIZE": args.elite_size,
            "OFFSPRING": args.offspring,
            "MIGRATION_RATE": args.migration_rate,
            "MIGRATION_FREQ": args.migration_freq,
            "STEPS_TA": args.ta,
            "STEPS_TB": args.tb,
            "NUM_GENERATIONS": args.num_generations,
            "NUM_RUNS": args.num_runs,
            "NUM_ROBOTS": args.num_robots,
            "POPULATION_SIZE": args.population_size,
            "TARGETS_DISTANCES": args.targets_distances,
            "TARGETS_ANGLES": args.targets_angles,
            "TRIALS": args.trials,
            "RANDOM_TARGETS": 1 if args.random_targets else 0,
            "SYMETRICAL_TARGETS": 1 if args.symetrical_targets else 0,
        },
        code_version=git_version,
    )

    for run in inst.runs:
        PGA(context, args).execute(run)
Ejemplo n.º 3
0
Archivo: test.py Proyecto: bazk/solace
PARAM1 = 5.3
PARAM2 = [ 5, 4, 2 ]
PARAM3 = False
PARAM4 = 'fox'
PARAM5 = {'foo': 'bar', 'list': [3, 2, 1]}

def step(var1, var2):
    var1 += random.uniform(0,1)
    var2 += random.uniform(0,1.5)

    time.sleep(5)

    return var1, var2

if __name__=="__main__":
    exp = solace.get_experiment('solace://lys:3000/test', 'admin', 'a0358070')
    inst = exp.create_instance(NUM_RUNS, {'PARAM1': PARAM1, 'PARAM2': PARAM2, 'PARAM3': PARAM3, 'PARAM4': PARAM4, 'PARAM5': PARAM5, 'NUM_STEPS': NUM_STEPS})

    for run in inst.runs:
        run.begin()

        # the variables we are optimizing (just as an example)
        var1 = 0
        var2 = 0

        current_step = 0
        while current_step < NUM_STEPS:
            var1, var2 = step(var1, var2)

            current_step += 1
            run.progress(current_step / float(NUM_STEPS), {'var1': var1, 'var2': var2})
Ejemplo n.º 4
0
Archivo: test.py Proyecto: bazk/solace
PARAM3 = False
PARAM4 = 'fox'
PARAM5 = {'foo': 'bar', 'list': [3, 2, 1]}


def step(var1, var2):
    var1 += random.uniform(0, 1)
    var2 += random.uniform(0, 1.5)

    time.sleep(5)

    return var1, var2


if __name__ == "__main__":
    exp = solace.get_experiment('solace://lys:3000/test', 'admin', 'a0358070')
    inst = exp.create_instance(
        NUM_RUNS, {
            'PARAM1': PARAM1,
            'PARAM2': PARAM2,
            'PARAM3': PARAM3,
            'PARAM4': PARAM4,
            'PARAM5': PARAM5,
            'NUM_STEPS': NUM_STEPS
        })

    for run in inst.runs:
        run.begin()

        # the variables we are optimizing (just as an example)
        var1 = 0