From 69a7079ef38f543ecfd9abe648f9073a6867f543 Mon Sep 17 00:00:00 2001 From: CarloLonghi Date: Fri, 20 May 2022 16:31:10 +0200 Subject: [PATCH 1/5] isaac restart recovery --- .../isaac/manager_direct_cpghyper_shared.py | 14 +++++------ pyrevolve/experiment_management.py | 4 ++-- .../direct_tree/direct_tree_genotype.py | 23 ++++++++++++------- .../tree_body_hyperneat_brain_genotype.py | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/experiments/isaac/manager_direct_cpghyper_shared.py b/experiments/isaac/manager_direct_cpghyper_shared.py index 11eafaac85..e71996987c 100644 --- a/experiments/isaac/manager_direct_cpghyper_shared.py +++ b/experiments/isaac/manager_direct_cpghyper_shared.py @@ -45,8 +45,8 @@ def environment_constructor(gym: gymapi.Gym, def generate_candidate_partners(population: PositionedPopulation, db: PostgreSQLDatabase, grace_time: float = 0.) -> None: - ids: List[int] = [int(individual.phenotype.database_id) for individual in population.individuals] - individual_map: Dict[int, Individual] = {int(individual.phenotype.database_id): individual for individual in population.individuals } + ids: List[int] = [int(individual.phenotype.id) for individual in population.individuals] + individual_map: Dict[int, Individual] = {int(individual.phenotype.id): individual for individual in population.individuals } # Using a set for candidates to avoid repetitions # TODO if a robot is seen more, should it get more chances? @@ -129,7 +129,7 @@ async def run(): mutation_p_generate_subtree=morph_single_mutation_prob, mutation_p_swap_subtree=morph_single_mutation_prob, mutation_p_mutate_oscillators=brain_single_mutation_prob, - mutation_p_mutate_oscillator=0.5, + mutation_p_mutate_oscillator=0, mutate_oscillator_amplitude_sigma=0.3, mutate_oscillator_period_sigma=0.3, mutate_oscillator_phase_sigma=0.3, @@ -202,7 +202,7 @@ def worker_crash(process, exit_code) -> None: # CELERY CONNECTION (includes database connection) # simulator_queue = CeleryQueue(args, args.port_start, dbname='revolve', db_addr='127.0.0.1', use_isaacgym=True) simulator_queue = CeleryPopulationQueue(args, use_isaacgym=True, local_computing=True) - await simulator_queue.start(cleanup_database=True) + await simulator_queue.start(cleanup_database=(not do_recovery)) # CELERY GAZEBO WORKER celery_workers: List[GazeboCeleryWorkerSupervisor] = [] @@ -242,7 +242,7 @@ def worker_crash(process, exit_code) -> None: if gen_num == 0: await population.initialize_from_single_individual(individuals) else: - population = await population.next_generation(gen_num, individuals) + population = await population.next_generation(gen_num) experiment_management.export_snapshots(population.individuals, gen_num) else: @@ -283,7 +283,7 @@ def update_robot_pose(individuals: List[Individual], db: PostgreSQLDatabase) -> assert last_eval_n == 0 for individual in individuals: - dbid = int(individual.phenotype.database_id) + dbid = int(individual.phenotype.id) final_position = session \ .query(RobotState.pos_x, RobotState.pos_y) \ .filter(RobotState.evaluation_n == last_eval_n) \ @@ -301,7 +301,7 @@ def export_special_data(file, individuals: List[Individual], offspring_list: Lis with db.session() as session: for individual in individuals: - dbid = int(individual.phenotype.database_id) + dbid = int(individual.phenotype.id) last_eval: RobotEvaluation = session \ .query(RobotEvaluation) \ diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index 27c4837a68..d189276089 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -11,7 +11,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import List, AnyStr, Optional + from typing import List, AnyStr, Optional, Tuple from pyrevolve.tol.manage.measures import BehaviouralMeasurements from pyrevolve.evolution.speciation.genus import Genus from pyrevolve.evolution.speciation.species import Species @@ -301,7 +301,7 @@ def read_recovery_state(self, population_size: int, offspring_size: int, species=False, - n_developments: int = 1) -> (int, bool, int): + n_developments: int = 1) -> Tuple[int, bool, int]: """ Read the saved data to determine how many generations have been completed and if the last generation has partially started evaluating. diff --git a/pyrevolve/genotype/direct_tree/direct_tree_genotype.py b/pyrevolve/genotype/direct_tree/direct_tree_genotype.py index 175fa0e7e5..a64045ca02 100644 --- a/pyrevolve/genotype/direct_tree/direct_tree_genotype.py +++ b/pyrevolve/genotype/direct_tree/direct_tree_genotype.py @@ -7,7 +7,7 @@ from pyrevolve.genotype.direct_tree.direct_tree_config import DirectTreeGenotypeConfig from pyrevolve.genotype.direct_tree.direct_tree_utils import duplicate_subtree from pyrevolve.revolve_bot import RevolveBot -from pyrevolve.revolve_bot.brain import BrainNN, brain_nn +from pyrevolve.revolve_bot.brain import BrainNN, brain_nn, BrainCPPNCPG from pyrevolve.revolve_bot.revolve_module import ActiveHingeModule from pyrevolve.revolve_bot.revolve_module import CoreModule @@ -53,18 +53,23 @@ def load_genotype(self, genotype_filename: AnyStr) -> None: revolvebot.load_file(genotype_filename, conf_type='yaml') self._load_genotype_from_revolvebot(revolvebot) - def _load_genotype_from_lines(self, genotype_lines: List[AnyStr]) -> None: + def _load_genotype_from_lines(self, genotype_lines: List[AnyStr], only_body=False) -> None: revolvebot: RevolveBot = RevolveBot() revolvebot.load('\n'.join(genotype_lines), conf_type='yaml') - self._load_genotype_from_revolvebot(revolvebot) + if only_body: + self._load_genotype_only_body(revolvebot) + else: + self._load_genotype_from_revolvebot(revolvebot) - def _load_genotype_from_revolvebot(self, revolvebot: RevolveBot) -> None: + def _load_genotype_only_body(self, revolvebot: RevolveBot) -> None: self.id = revolvebot.id - self.representation = revolvebot._body + self.representation = revolvebot._body + def _load_genotype_only_brain(self, revolvebot: RevolveBot) -> None: # load brain params into the modules brain = revolvebot._brain - assert isinstance(brain, BrainNN) + + assert isinstance(brain, BrainCPPNCPG) module_map = {} for module in revolvebot.iter_all_elements(): @@ -80,7 +85,9 @@ def _load_genotype_from_revolvebot(self, revolvebot: RevolveBot) -> None: for module in revolvebot.iter_all_elements(): assert module_map[module.id] == module - return + def _load_genotype_from_revolvebot(self, revolvebot: RevolveBot) -> None: + self._load_genotype_only_body(revolvebot=revolvebot) + self._load_genotype_only_brain(revolvebot=revolvebot) def export_genotype(self, filepath: str) -> None: self.develop() @@ -94,7 +101,7 @@ def _export_genotype_open_file(self, open_file: TextIO) -> None: def develop(self) -> RevolveBot: if self.phenotype is None: self.phenotype: RevolveBot = RevolveBot(self.id) - self.phenotype._body: CoreModule = self.representation + self.phenotype._body = self.representation self.phenotype._brain = self._develop_brain(self.representation) return self.phenotype diff --git a/pyrevolve/genotype/tree_body_hyperneat_brain/tree_body_hyperneat_brain_genotype.py b/pyrevolve/genotype/tree_body_hyperneat_brain/tree_body_hyperneat_brain_genotype.py index e62474f0b8..ee38b71449 100644 --- a/pyrevolve/genotype/tree_body_hyperneat_brain/tree_body_hyperneat_brain_genotype.py +++ b/pyrevolve/genotype/tree_body_hyperneat_brain/tree_body_hyperneat_brain_genotype.py @@ -92,7 +92,7 @@ def load_genotype(self, file_path: str) -> None: # remove first element - it's the number of brain genomes number_of_brain_genomes = int(lines.pop(0)) # read the body genome - self._body_genome._load_genotype_from_lines(lines[:-number_of_brain_genomes]) + self._body_genome._load_genotype_from_lines(lines[:-number_of_brain_genomes], only_body=True) # read the brain genomes for brain_i in range(number_of_brain_genomes): i = -number_of_brain_genomes + brain_i From d97e40644a6ab0b242be84baa469491d44b8e08a Mon Sep 17 00:00:00 2001 From: CarloLonghi Date: Fri, 20 May 2022 18:10:34 +0200 Subject: [PATCH 2/5] save database id --- .../isaac/manager_direct_cpghyper_shared.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/experiments/isaac/manager_direct_cpghyper_shared.py b/experiments/isaac/manager_direct_cpghyper_shared.py index e71996987c..cbf662698b 100644 --- a/experiments/isaac/manager_direct_cpghyper_shared.py +++ b/experiments/isaac/manager_direct_cpghyper_shared.py @@ -3,6 +3,7 @@ import os from typing import List, Dict +import yaml import math from isaacgym import gymapi @@ -45,8 +46,8 @@ def environment_constructor(gym: gymapi.Gym, def generate_candidate_partners(population: PositionedPopulation, db: PostgreSQLDatabase, grace_time: float = 0.) -> None: - ids: List[int] = [int(individual.phenotype.id) for individual in population.individuals] - individual_map: Dict[int, Individual] = {int(individual.phenotype.id): individual for individual in population.individuals } + ids: List[int] = [int(individual.phenotype.database_id) for individual in population.individuals] + individual_map: Dict[int, Individual] = {int(individual.phenotype.database_id): individual for individual in population.individuals } # Using a set for candidates to avoid repetitions # TODO if a robot is seen more, should it get more chances? @@ -232,9 +233,11 @@ def worker_crash(process, exit_code) -> None: if do_recovery: # loading a previous state of the experiment population.load_snapshot(gen_num, multi_development=True) + load_database_ids(gen_num, experiment_management,population.individuals) if gen_num >= 0: logger.info(f'Recovered snapshot {gen_num}, pop with {len(population.individuals)} individuals') if has_offspring: + assert False individuals = population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) gen_num += 1 logger.info(f'Recovered unfinished offspring {gen_num}') @@ -259,6 +262,8 @@ def worker_crash(process, exit_code) -> None: generate_candidate_partners(population, simulator_queue._db, args.grace_time) new_population = await population.next_generation(gen_num) update_robot_pose(population.individuals, simulator_queue._db) + with open(f'{experiment_management.generation_folder(gen_num-1)}/database_ids.yml', 'w') as database_id_file: + save_db_ids(database_id_file, population.individuals) experiment_management.export_snapshots(population.individuals, gen_num) with open(f'{experiment_management.generation_folder(gen_num-1)}/extra.tsv', 'w') as extra_data_file: export_special_data(extra_data_file, population.individuals, new_population.individuals, gen_num, simulator_queue._db) @@ -269,6 +274,18 @@ def worker_crash(process, exit_code) -> None: await celery_worker.stop() await simulator_queue.stop() +def save_db_ids(outfile, individuals: List[Individual]): + database_ids = {} + for ind in individuals: + database_ids[ind.phenotype.id] = int(ind.phenotype.database_id) + yaml.dump(database_ids, outfile) + +def load_database_ids(gen_num: int, experiment_management: ExperimentManagement, individuals: List[Individual]): + database_ids = {} + with open(f'{experiment_management.generation_folder(gen_num-1)}/database_ids.yml', 'r') as database_id_file: + database_ids = yaml.safe_load(database_id_file) + for ind in individuals: + ind.phenotype.database_id = database_ids[ind.phenotype.id] def update_robot_pose(individuals: List[Individual], db: PostgreSQLDatabase) -> None: From f51ba459cc7bcab8c85aa924254728fbc2e568c8 Mon Sep 17 00:00:00 2001 From: CarloLonghi Date: Mon, 23 May 2022 15:41:01 +0200 Subject: [PATCH 3/5] restored database_ids --- experiments/isaac/manager_direct_cpghyper_shared.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experiments/isaac/manager_direct_cpghyper_shared.py b/experiments/isaac/manager_direct_cpghyper_shared.py index cbf662698b..d3ae672f62 100644 --- a/experiments/isaac/manager_direct_cpghyper_shared.py +++ b/experiments/isaac/manager_direct_cpghyper_shared.py @@ -300,7 +300,7 @@ def update_robot_pose(individuals: List[Individual], db: PostgreSQLDatabase) -> assert last_eval_n == 0 for individual in individuals: - dbid = int(individual.phenotype.id) + dbid = int(individual.phenotype._database_id) final_position = session \ .query(RobotState.pos_x, RobotState.pos_y) \ .filter(RobotState.evaluation_n == last_eval_n) \ @@ -318,7 +318,7 @@ def export_special_data(file, individuals: List[Individual], offspring_list: Lis with db.session() as session: for individual in individuals: - dbid = int(individual.phenotype.id) + dbid = int(individual.phenotype.database_id) last_eval: RobotEvaluation = session \ .query(RobotEvaluation) \ From 048d2ce170661777ac14e90a31cb6943f5c565c7 Mon Sep 17 00:00:00 2001 From: CarloLonghi Date: Mon, 23 May 2022 15:46:55 +0200 Subject: [PATCH 4/5] database_id --- experiments/isaac/manager_direct_cpghyper_shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/isaac/manager_direct_cpghyper_shared.py b/experiments/isaac/manager_direct_cpghyper_shared.py index d3ae672f62..90c68b92ac 100644 --- a/experiments/isaac/manager_direct_cpghyper_shared.py +++ b/experiments/isaac/manager_direct_cpghyper_shared.py @@ -300,7 +300,7 @@ def update_robot_pose(individuals: List[Individual], db: PostgreSQLDatabase) -> assert last_eval_n == 0 for individual in individuals: - dbid = int(individual.phenotype._database_id) + dbid = int(individual.phenotype.database_id) final_position = session \ .query(RobotState.pos_x, RobotState.pos_y) \ .filter(RobotState.evaluation_n == last_eval_n) \ From a1ab7db1e2159a0c462d4d333acf43475f744c81 Mon Sep 17 00:00:00 2001 From: CarloLonghi Date: Tue, 24 May 2022 21:43:50 +0200 Subject: [PATCH 5/5] replay --- experiments/isaac/manager_replay.py | 216 +++++++++++++++++++++++ pyrevolve/config.py | 6 + pyrevolve/isaac/common.py | 3 +- pyrevolve/isaac/manage_isaac_multiple.py | 18 +- 4 files changed, 235 insertions(+), 8 deletions(-) create mode 100644 experiments/isaac/manager_replay.py diff --git a/experiments/isaac/manager_replay.py b/experiments/isaac/manager_replay.py new file mode 100644 index 0000000000..d9b67a484b --- /dev/null +++ b/experiments/isaac/manager_replay.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import os +from typing import List, Dict +import yaml + +import math +from isaacgym import gymapi + +from experiments.isaac.positioned_population import PositionedPopulation +from pyrevolve import parser +from pyrevolve.custom_logging.logger import logger +from pyrevolve.evolution import fitness +from pyrevolve.evolution.individual import Individual +from pyrevolve.evolution.population.population_config import PopulationConfig +from pyrevolve.evolution.population.population_management import generational_population_management +from pyrevolve.evolution.selection import best_selection +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.direct_tree.direct_tree_genotype import DirectTreeGenotypeConfig +from pyrevolve.genotype.neat_brain_genome.neat_brain_genome import NeatBrainGenomeConfig, BrainType +from pyrevolve.genotype.tree_body_hyperneat_brain import DirectTreeCPGHyperNEATGenotypeConfig, \ + DirectTreeCPGHyperNEATGenotype +from pyrevolve.genotype.tree_body_hyperneat_brain.crossover import standard_crossover +from pyrevolve.genotype.tree_body_hyperneat_brain.mutation import standard_mutation +from pyrevolve.util.supervisor.rabbits import GazeboCeleryWorkerSupervisor, PostgreSQLDatabase, RobotEvaluation, \ + RobotState +from pyrevolve.util.supervisor.rabbits.celery_queue import CeleryPopulationQueue + +INTERNAL_WORKERS = False + + +def environment_constructor(gym: gymapi.Gym, + sim: gymapi.Sim, + _env_lower: gymapi.Vec3, + _env_upper: gymapi.Vec3, + _num_per_row: int, + env: gymapi.Env) -> float: + radius: float = 0.2 + asset_options: gymapi.AssetOptions = gymapi.AssetOptions() + asset_options.density = 1.0 + asset_options.linear_damping = 0.5 + asset_options.angular_damping = 0.5 + sphere_asset = gym.create_sphere(sim, radius, asset_options) + return 0 + + + +# MATING_RANGE = 0.45 +MATING_RANGE = 45 + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 200 + population_size = 32 + offspring_size = population_size + + morph_single_mutation_prob = 0.2 + morph_no_single_mutation_prob = 1 - morph_single_mutation_prob # 0.8 + morph_no_all_mutation_prob = morph_no_single_mutation_prob ** 4 # 0.4096 + morph_at_least_one_mutation_prob = 1 - morph_no_all_mutation_prob # 0.5904 + + brain_single_mutation_prob = 0.5 + + tree_genotype_conf: DirectTreeGenotypeConfig = DirectTreeGenotypeConfig( + max_parts=25, + min_parts=5, + max_oscillation=5, + init_n_parts_mu=10, + init_n_parts_sigma=4, + init_prob_no_child=0.1, + init_prob_child_block=0.4, + init_prob_child_active_joint=0.5, + mutation_p_duplicate_subtree=morph_single_mutation_prob, + mutation_p_delete_subtree=morph_single_mutation_prob, + mutation_p_generate_subtree=morph_single_mutation_prob, + mutation_p_swap_subtree=morph_single_mutation_prob, + mutation_p_mutate_oscillators=brain_single_mutation_prob, + mutation_p_mutate_oscillator=0, + mutate_oscillator_amplitude_sigma=0.3, + mutate_oscillator_period_sigma=0.3, + mutate_oscillator_phase_sigma=0.3, + ) + + neat_conf: NeatBrainGenomeConfig = NeatBrainGenomeConfig( + brain_type=BrainType.CPG, + random_seed=None + ) + + genotype_conf: DirectTreeCPGHyperNEATGenotypeConfig = DirectTreeCPGHyperNEATGenotypeConfig( + direct_tree_conf=tree_genotype_conf, + neat_conf=neat_conf, + number_of_brains=1, + ) + + # Parse command line / file input arguments + args = parser.parse_args() + experiment_management = ExperimentManagement(args) + has_offspring = False + do_recovery = args.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info(f'Activated run {args.run} of experiment {args.experiment_name}') + + #gen_num, has_offspring, next_robot_id, next_species_id = \ + # experiment_management.read_recovery_state(population_size, offspring_size, species=False) + gen_num = args.generation + if gen_num < 0: + logger.info('Experiment continuing from first generation') + gen_num = 1 + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=lambda conf, _id: DirectTreeCPGHyperNEATGenotype(conf, _id, random_init_body=True), + genotype_conf=genotype_conf, + fitness_function=fitness.displacement_velocity, + objective_functions=None, + mutation_operator=lambda genotype, gen_conf: standard_mutation(genotype, gen_conf), + mutation_conf=genotype_conf, + crossover_operator=lambda parents, gen_conf, _: standard_crossover(parents, gen_conf), + crossover_conf=None, + selection=best_selection, + parent_selection=None, + population_management=generational_population_management, + population_management_selector=None, + evaluation_time=args.evaluation_time, + grace_time=args.grace_time, + offspring_size=offspring_size, + experiment_name=args.experiment_name, + experiment_management=experiment_management, + environment_constructor=environment_constructor, #TODO IMPLEMENT THIS!!!! pass it to isaacqueue that passes it to the manage_isaac_multiple + ) + + n_cores = args.n_cores + + def worker_crash(process, exit_code) -> None: + logger.fatal(f'GazeboCeleryWorker died with code: {exit_code} ({process})') + + # CELERY CONNECTION (includes database connection) + # simulator_queue = CeleryQueue(args, args.port_start, dbname='revolve', db_addr='127.0.0.1', use_isaacgym=True) + simulator_queue = CeleryPopulationQueue(args, use_isaacgym=True, local_computing=True) + await simulator_queue.start(cleanup_database=False) + + # CELERY GAZEBO WORKER + celery_workers: List[GazeboCeleryWorkerSupervisor] = [] + if INTERNAL_WORKERS: + for n in range(n_cores): + celery_worker = GazeboCeleryWorkerSupervisor( + world_file='worlds/plane.celery.world', + gui=args.gui, + simulator_args=['--verbose'], + plugins_dir_path=os.path.join('../heritability', 'build', 'lib'), + models_dir_path=os.path.join('../heritability', 'models'), + simulator_name=f'GazeboCeleryWorker_{n}', + process_terminated_callback=worker_crash, + ) + await celery_worker.launch_simulator(port=args.port_start + n) + celery_workers.append(celery_worker) + + # ANALYZER CONNECTION + # analyzer_port = args.port_start + (n_cores if INTERNAL_WORKERS else 0) + # analyzer_queue = AnalyzerQueue(1, args, port_start=analyzer_port) + # await analyzer_queue.start() + analyzer_queue = None + + # INITIAL POPULATION OBJECT + population = PositionedPopulation(population_conf, simulator_queue, analyzer_queue) + + # loading a previous state of the experiment + population.load_snapshot(gen_num, multi_development=True) + load_database_ids(gen_num, experiment_management,population.individuals) + if gen_num >= 0: + logger.info(f'Recovered snapshot {gen_num}, pop with {len(population.individuals)} individuals') + + #new_population = await population.next_generation(gen_num) + update_robot_pose(population.individuals, simulator_queue._db) + await population.evaluate(population.individuals, gen_num) + + # CLEANUP + for celery_worker in celery_workers: + await celery_worker.stop() + await simulator_queue.stop() + +def update_robot_pose(individuals: List[Individual], db: PostgreSQLDatabase) -> None: + + with db.session() as session: + + last_eval: RobotEvaluation = session \ + .query(RobotEvaluation) \ + .filter(RobotEvaluation.robot_id == individuals[0].id) \ + .order_by(RobotEvaluation.n.desc()) \ + .one() + last_eval_n = last_eval.n + assert last_eval_n == 0 + + for individual in individuals: + dbid = int(individual.phenotype.database_id) + final_position = session \ + .query(RobotState.pos_x, RobotState.pos_y) \ + .filter(RobotState.evaluation_n == last_eval_n) \ + .filter(RobotState.evaluation_robot_id == dbid) \ + .order_by(RobotState.time_sec.desc(), RobotState.time_nsec.desc()) \ + .first() + print(f"DB:{individual} ({final_position})") + individual.pose.x = final_position[0] + individual.pose.y = final_position[1] + +def load_database_ids(gen_num: int, experiment_management: ExperimentManagement, individuals: List[Individual]): + database_ids = {} + with open(f'{experiment_management.generation_folder(gen_num-1)}/database_ids.yml', 'r') as database_id_file: + database_ids = yaml.safe_load(database_id_file) + for ind in individuals: + ind.phenotype.database_id = database_ids[ind.phenotype.id] \ No newline at end of file diff --git a/pyrevolve/config.py b/pyrevolve/config.py index b1dbe63e83..21283fa19e 100644 --- a/pyrevolve/config.py +++ b/pyrevolve/config.py @@ -269,6 +269,12 @@ def str_to_address(v): "\nDefault \"False\"." ) +parser.add_argument( + '--generation', + default=0, type=int, + help="Generation to replay" +) + def make_revolve_config(conf): """ diff --git a/pyrevolve/isaac/common.py b/pyrevolve/isaac/common.py index 14790dbf0a..37db9865a2 100644 --- a/pyrevolve/isaac/common.py +++ b/pyrevolve/isaac/common.py @@ -121,7 +121,8 @@ def simulator_main_loop(gym: IsaacSim, controller_update_time: float): life_cycle(gym, time) if len(gym.robots) == 0: break - gym.update_robots(time, controller_update_time) + # comment below + #gym.update_robots(time, controller_update_time) # Step the physics gym.simulate() diff --git a/pyrevolve/isaac/manage_isaac_multiple.py b/pyrevolve/isaac/manage_isaac_multiple.py index e6a7297ba5..87a55f3d05 100644 --- a/pyrevolve/isaac/manage_isaac_multiple.py +++ b/pyrevolve/isaac/manage_isaac_multiple.py @@ -37,7 +37,7 @@ def simulator_multiple(robots_urdf: List[AnyStr], mydb = db # Parse arguments # args = gymutil.parse_arguments(description="Loading and testing") - args = Arguments() + args = Arguments(headless=False, use_gpu=True) isolated_environments = True manual_db_session = False @@ -115,19 +115,23 @@ def simulator_multiple(robots_urdf: List[AnyStr], # shared physics collision group gym.insert_robot(env_index, robot, robot_asset_filename, asset_options, robot.pose, f"{robot.name} #{i}", 1, 0, 0) isaac_logger.info(f"Loaded {robot.name} asset '{robot_asset_filepath}' from '{asset_root}', #'{i}'") - - # Insert robot in the database + + # Insert robot in the database TODO do nor insert for replay with mydb.session() as session2: robot.db_robot = DBRobot(name=robot.name) - session2.add(robot.db_robot) - session2.commit() + # comment two lines below + #session2.add(robot.db_robot) + #session2.commit() # this line actually queries the database while the session is still active robot.db_robot_id = robot.db_robot.id - + + db_eval = DBRobotEvaluation(robot=robot.db_robot, n=0) robot.evals.append(db_eval) # Write first evaluations in database - session.add(db_eval) + # comment below + #session.add(db_eval) + # end for loop session.commit()