#### Initialize Ray Tune ################################### ray.shutdown() ray.init(ignore_reinit_error=True) #### Register the custom centralized critic model ########## ModelCatalog.register_custom_model("cc_model", CustomTorchCentralizedCriticModel) #### Register the environment ############################## temp_env_name = "this-aviary-v0" if ARGS.env == 'flock': register_env( temp_env_name, lambda _: FlockAviary( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) elif ARGS.env == 'leaderfollower': register_env( temp_env_name, lambda _: LeaderFollowerAviary( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) elif ARGS.env == 'meetup': register_env( temp_env_name, lambda _: MeetupAviary( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs,
#### Initialize the logger ######################################################################### if ARGS.log: logger = Logger(logging_freq_hz=int(ARGS.simulation_freq_hz / AGGR_PHY_STEPS), num_drones=ARGS.num_drones) #### Initialize the controllers #################################################################### ctrl = [DSLPIDControl(env) for i in range(ARGS.num_drones)] #### Debug environment used to print out the MARL's problem obs, reward and done ################### if ARGS.num_drones > 1 and ARGS.debug_marl: debug_env = FlockAviary(drone_model=ARGS.drone, num_drones=ARGS.num_drones, initial_xyzs=INIT_XYZS, physics=ARGS.physics, neighbourhood_radius=10, freq=ARGS.simulation_freq_hz, aggregate_phy_steps=AGGR_PHY_STEPS, gui=False, record=False, obstacles=True) #### Run the simulation ############################################################################ CTRL_EVERY_N_STEPS = int(np.floor(env.SIM_FREQ / ARGS.control_freq_hz)) action = { str(i): np.array([0, 0, 0, 0]) for i in range(ARGS.num_drones) } if not ARGS.dyn_ctrl else { "0": np.array([env.M * env.G, 0, 0, 0]) } START = time.time() for i in range(0, int(ARGS.duration_sec * env.SIM_FREQ),
#### Initialize Ray Tune ################################### ray.shutdown() ray.init(ignore_reinit_error=True) #### Register the custom centralized critic model ########## ModelCatalog.register_custom_model("cc_model", CustomTorchCentralizedCriticModel) #### Register the environment ############################## temp_env_name = "this-aviary-v0" if ARGS.exp.split("-")[1] == 'flock': register_env( temp_env_name, lambda _: FlockAviary( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT)) elif ARGS.exp.split("-")[1] == 'leaderfollower': register_env( temp_env_name, lambda _: LeaderFollowerAviary( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT)) elif ARGS.exp.split("-")[1] == 'meetup': register_env( temp_env_name, lambda _: MeetupAviary( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS,
help='Help (default: ..)', metavar='') ARGS = parser.parse_args() # e.g. python test_multiagent.py --file /Users/jacopo/ray_results/PPO/PPO_this-flock-aviary-v0_136de_00000_0_2020-10-25_20-20-39/checkpoint_1/checkpoint-1 #### Initialize Ray Tune ########################################################################### ray.shutdown() ray.init(ignore_reinit_error=True) #### Register the custom centralized critic model ################################################## ModelCatalog.register_custom_model("cc_model", CustomTorchCentralizedCriticModel) #### Unused env to extract correctly sized action and observation spaces ########################### temp_env = FlockAviary(num_drones=ARGS.num_drones) observer_space = Dict({ "own_obs": temp_env.observation_space[ 0], # Box(-1.0, 1.0, (20,), np.float32) or Dict(neighbors:MultiBinary(2), state:Box(-1.0, 1.0, (20,), np.float32)) "opponent_obs": temp_env.observation_space[0], "opponent_action": temp_env.action_space[0], }) action_space = temp_env.action_space[0] # Box(-1.0, 1.0, (4,), np.float32) #### Register the environment ###################################################################### register_env("this-flock-aviary-v0", lambda _: FlockAviary(num_drones=ARGS.num_drones)) #### Set up the trainer's config ################################################################### config = ppo.DEFAULT_CONFIG.copy( ) # For the default config, see github.com/ray-project/ray/blob/master/rllib/agents/trainer.py