Skip to content

Commit

Permalink
hyper plastic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karinemiras committed Mar 26, 2021
1 parent 2db32fb commit 729fdf6
Show file tree
Hide file tree
Showing 19 changed files with 1,199 additions and 55 deletions.
6 changes: 3 additions & 3 deletions experiments/karines_experiments/check-experiments-status.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

runs=10
final_gen=149
experiments=("hyperplasticodingseasons")
runs=5
final_gen=199
experiments=("hyperplasticodingseasonsI15" "hyperplasticodingp" "hyperplasticodingt3")


for i in $(seq $runs)
Expand Down
15 changes: 8 additions & 7 deletions experiments/karines_experiments/consolidate_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
dirpath = 'data/'

experiments_type = [
'hyperplasticodingt4',
'hyperplasticodingoldt4',
'hyperplasticodingoldt3'
#'hyperplasticodingp',
#'hyperplasticodingt3',
'hyperplasticodingseasons'

]
environments = {
'hyperplasticodingt4': ['tilted4'],
'hyperplasticodingoldt4': ['tilted4'],
'hyperplasticodingoldt3': ['tilted3']
#'hyperplasticodingp': ['plane'],
#'hyperplasticodingt3': ['tilted3'],
'hyperplasticodingseasons' : ['plane', 'tilted3']
}

runs = range(1, 10+1)
runs = range(1, 5+1)

# set these variables according to your experiments #

Expand Down
174 changes: 174 additions & 0 deletions experiments/karines_experiments/hyperplasticodingp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/usr/bin/env python3
import asyncio

from pyrevolve import parser
from pyrevolve.evolution import fitness
from pyrevolve.evolution.selection import multiple_selection, tournament_selection
from pyrevolve.evolution.population import Population, PopulationConfig
from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management
from pyrevolve.experiment_management import ExperimentManagement
from pyrevolve.genotype.hyperplasticoding_v2.crossover.crossover import CrossoverConfig
from pyrevolve.genotype.hyperplasticoding_v2.crossover.standard_crossover import standard_crossover
from pyrevolve.genotype.hyperplasticoding_v2.initialization import random_initialization
from pyrevolve.genotype.hyperplasticoding_v2.mutation.mutation import MutationConfig
from pyrevolve.genotype.hyperplasticoding_v2.mutation.standard_mutation import standard_mutation
from pyrevolve.genotype.hyperplasticoding_v2.hyperplasticoding import HyperPlasticodingConfig
from pyrevolve.tol.manage import measures
from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue
from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue
from pyrevolve.custom_logging.logger import logger
import sys


async def run():
"""
The main coroutine, which is started below.
"""

# experiment params #
num_generations = 200
population_size = 100
offspring_size = 100
front = 'none'

# environment world and z-start
environments = {'plane': 0.03 }

# calculation of the measures can be on or off, because they are expensive
novelty_on = {'novelty': False,
'novelty_pop': True,
'measures': ['branching',
'limbs',
'length_of_limbs',
'coverage',
'joints',
'proportion',
'size',
'symmetry']
}

cppn_config_path = 'pyrevolve/genotype/hyperplasticoding_v2/config-nonplastic'

genotype_conf = HyperPlasticodingConfig(
plastic=False,
cppn_config_path=cppn_config_path
)

mutation_conf = MutationConfig(
mutation_prob=1,
genotype_conf=genotype_conf,
cppn_config_path=cppn_config_path
)

crossover_conf = CrossoverConfig(
crossover_prob=0,
cppn_config_path=cppn_config_path
)

# experiment params #

# Parse command line / file input arguments
settings = parser.parse_args()

experiment_management = ExperimentManagement(settings, environments)
do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new()


logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name)

if do_recovery:
gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size,
offspring_size)
if gen_num == num_generations-1:
logger.info('Experiment is already complete.')
return
else:
gen_num = 0
next_robot_id = 1

def fitness_function_plane(measures, robot):
return fitness.displacement_velocity_hill(measures, robot)

fitness_function = {'plane': fitness_function_plane}

population_conf = PopulationConfig(
population_size=population_size,
genotype_constructor=random_initialization,
genotype_conf=genotype_conf,
fitness_function=fitness_function,
mutation_operator=standard_mutation,
mutation_conf=mutation_conf,
crossover_operator=standard_crossover,
crossover_conf=crossover_conf,
selection=lambda individuals: tournament_selection(individuals, environments, 2),
parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments),
population_management=steady_state_population_management,
population_management_selector=tournament_selection,
evaluation_time=settings.evaluation_time,
offspring_size=offspring_size,
experiment_name=settings.experiment_name,
experiment_management=experiment_management,
environments=environments,
novelty_on=novelty_on,
front=front,
run_simulation=settings.run_simulation,
all_settings=settings,
)

simulator_queue = {}
analyzer_queue = None

if settings.run_simulation == 1:
previous_port = None
for environment in environments:

settings.world = environment
settings.z_start = environments[environment]

if previous_port is None:
port = settings.port_start
previous_port = port
else:
port = previous_port+settings.n_cores
previous_port = port

simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port)
await simulator_queue[environment].start()

analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores)
await analyzer_queue.start()

population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id)

if do_recovery:

population.load_novelty_archive()

if gen_num >= 0:
# loading a previous state of the experiment
await population.load_snapshot(gen_num)
logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals')

if has_offspring:
individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id)
gen_num += 1
logger.info('Recovered unfinished offspring '+str(gen_num))

if gen_num == 0:
await population.init_pop(individuals)
else:
population = await population.next_gen(gen_num, individuals)

experiment_management.export_snapshots(population.individuals, gen_num)
else:
# starting a new experiment
experiment_management.create_exp_folders()
await population.init_pop()
experiment_management.export_snapshots(population.individuals, gen_num)

while gen_num < num_generations-1:
gen_num += 1
population = await population.next_gen(gen_num)
experiment_management.export_snapshots(population.individuals, gen_num)

# output result after completing all generations...
177 changes: 177 additions & 0 deletions experiments/karines_experiments/hyperplasticodingseasons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/usr/bin/env python3
import asyncio

from pyrevolve import parser
from pyrevolve.evolution import fitness
from pyrevolve.evolution.selection import multiple_selection, tournament_selection
from pyrevolve.evolution.population import Population, PopulationConfig
from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management
from pyrevolve.experiment_management import ExperimentManagement
from pyrevolve.genotype.hyperplasticoding_v2.crossover.crossover import CrossoverConfig
from pyrevolve.genotype.hyperplasticoding_v2.crossover.standard_crossover import standard_crossover
from pyrevolve.genotype.hyperplasticoding_v2.initialization import random_initialization
from pyrevolve.genotype.hyperplasticoding_v2.mutation.mutation import MutationConfig
from pyrevolve.genotype.hyperplasticoding_v2.mutation.standard_mutation import standard_mutation
from pyrevolve.genotype.hyperplasticoding_v2.hyperplasticoding import HyperPlasticodingConfig
from pyrevolve.tol.manage import measures
from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue
from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue
from pyrevolve.custom_logging.logger import logger
import sys


async def run():
"""
The main coroutine, which is started below.
"""

# experiment params #
num_generations = 200
population_size = 100
offspring_size = 100
front = 'slaves'

# environment world and z-start
environments = {'plane': 0.03,
'tilted3': 0.08 }

# calculation of the measures can be on or off, because they are expensive
novelty_on = {'novelty': False,
'novelty_pop': True,
'measures': ['branching',
'limbs',
'length_of_limbs',
'coverage',
'joints',
'proportion',
'size',
'symmetry']
}

cppn_config_path = 'pyrevolve/genotype/hyperplasticoding_v2/config-plastic'

genotype_conf = HyperPlasticodingConfig(
plastic=True,
cppn_config_path=cppn_config_path
)

mutation_conf = MutationConfig(
mutation_prob=1,
genotype_conf=genotype_conf,
cppn_config_path=cppn_config_path
)

crossover_conf = CrossoverConfig(
crossover_prob=0,
cppn_config_path=cppn_config_path
)

# experiment params #

# Parse command line / file input arguments
settings = parser.parse_args()

experiment_management = ExperimentManagement(settings, environments)
do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new()


logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name)

if do_recovery:
gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size,
offspring_size)
if gen_num == num_generations-1:
logger.info('Experiment is already complete.')
return
else:
gen_num = 0
next_robot_id = 1

def fitness_function_plane(measures, robot):
return fitness.displacement_velocity_hill(measures, robot)

# using the same function
fitness_function = {'plane': fitness_function_plane,
'tilted3': fitness_function_plane}

population_conf = PopulationConfig(
population_size=population_size,
genotype_constructor=random_initialization,
genotype_conf=genotype_conf,
fitness_function=fitness_function,
mutation_operator=standard_mutation,
mutation_conf=mutation_conf,
crossover_operator=standard_crossover,
crossover_conf=crossover_conf,
selection=lambda individuals: tournament_selection(individuals, environments, 2),
parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments),
population_management=steady_state_population_management,
population_management_selector=tournament_selection,
evaluation_time=settings.evaluation_time,
offspring_size=offspring_size,
experiment_name=settings.experiment_name,
experiment_management=experiment_management,
environments=environments,
novelty_on=novelty_on,
front=front,
run_simulation=settings.run_simulation,
all_settings=settings,
)

simulator_queue = {}
analyzer_queue = None

if settings.run_simulation == 1:
previous_port = None
for environment in environments:

settings.world = environment
settings.z_start = environments[environment]

if previous_port is None:
port = settings.port_start
previous_port = port
else:
port = previous_port+settings.n_cores
previous_port = port

simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port)
await simulator_queue[environment].start()

analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores)
await analyzer_queue.start()

population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id)

if do_recovery:

population.load_novelty_archive()

if gen_num >= 0:
# loading a previous state of the experiment
await population.load_snapshot(gen_num)
logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals')

if has_offspring:
individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id)
gen_num += 1
logger.info('Recovered unfinished offspring '+str(gen_num))

if gen_num == 0:
await population.init_pop(individuals)
else:
population = await population.next_gen(gen_num, individuals)

experiment_management.export_snapshots(population.individuals, gen_num)
else:
# starting a new experiment
experiment_management.create_exp_folders()
await population.init_pop()
experiment_management.export_snapshots(population.individuals, gen_num)

while gen_num < num_generations-1:
gen_num += 1
population = await population.next_gen(gen_num)
experiment_management.export_snapshots(population.individuals, gen_num)

# output result after completing all generations...
Loading

0 comments on commit 729fdf6

Please sign in to comment.