get ray to stop crashing

This commit is contained in:
Marek Wolan
2024-05-31 15:25:08 +01:00
parent 46ef3b8041
commit e48b71ea1a
5 changed files with 13 additions and 10 deletions

View File

@@ -54,7 +54,7 @@ license-files = ["LICENSE"]
[project.optional-dependencies] [project.optional-dependencies]
rl = [ rl = [
"ray[rllib] >= 2.9, < 3", "ray[rllib] >= 2.20.0, < 3",
"tensorflow==2.12.0", "tensorflow==2.12.0",
"stable-baselines3[extra]==2.1.0", "stable-baselines3[extra]==2.1.0",
] ]

View File

@@ -60,8 +60,8 @@
" policies={'defender_1','defender_2'}, # These names are the same as the agents defined in the example config.\n", " policies={'defender_1','defender_2'}, # These names are the same as the agents defined in the example config.\n",
" policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n", " policy_mapping_fn=lambda agent_id, episode, worker, **kw: agent_id,\n",
" )\n", " )\n",
" .environment(env=PrimaiteRayMARLEnv, env_config=cfg)#, disable_env_checking=True)\n", " .environment(env=PrimaiteRayMARLEnv, env_config=cfg)\n",
" .rollouts(num_rollout_workers=0)\n", " .env_runners(num_env_runners=0)\n",
" .training(train_batch_size=128)\n", " .training(train_batch_size=128)\n",
" )\n" " )\n"
] ]

View File

@@ -19,7 +19,6 @@
"from primaite.config.load import data_manipulation_config_path\n", "from primaite.config.load import data_manipulation_config_path\n",
"\n", "\n",
"from primaite.session.ray_envs import PrimaiteRayEnv\n", "from primaite.session.ray_envs import PrimaiteRayEnv\n",
"from ray.rllib.algorithms import ppo\n",
"from ray import air, tune\n", "from ray import air, tune\n",
"import ray\n", "import ray\n",
"from ray.rllib.algorithms.ppo import PPOConfig\n", "from ray.rllib.algorithms.ppo import PPOConfig\n",
@@ -52,8 +51,8 @@
"\n", "\n",
"config = (\n", "config = (\n",
" PPOConfig()\n", " PPOConfig()\n",
" .environment(env=PrimaiteRayEnv, env_config=env_config, disable_env_checking=True)\n", " .environment(env=PrimaiteRayEnv, env_config=env_config)\n",
" .rollouts(num_rollout_workers=0)\n", " .env_runners(num_env_runners=0)\n",
" .training(train_batch_size=128)\n", " .training(train_batch_size=128)\n",
")\n" ")\n"
] ]
@@ -74,7 +73,7 @@
"tune.Tuner(\n", "tune.Tuner(\n",
" \"PPO\",\n", " \"PPO\",\n",
" run_config=air.RunConfig(\n", " run_config=air.RunConfig(\n",
" stop={\"timesteps_total\": 5 * 128}\n", " stop={\"timesteps_total\": 512}\n",
" ),\n", " ),\n",
" param_space=config\n", " param_space=config\n",
").fit()\n" ").fit()\n"

View File

@@ -43,7 +43,10 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"with open(data_manipulation_config_path(), 'r') as f:\n", "with open(data_manipulation_config_path(), 'r') as f:\n",
" cfg = yaml.safe_load(f)" " cfg = yaml.safe_load(f)\n",
"for agent in cfg['agents']:\n",
" if agent['ref'] == 'defender':\n",
" agent['agent_settings']['flatten_obs']=True"
] ]
}, },
{ {
@@ -177,7 +180,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.10" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -45,7 +45,8 @@ class PrimaiteRayMARLEnv(MultiAgentEnv):
self.action_space = gymnasium.spaces.Dict( self.action_space = gymnasium.spaces.Dict(
{name: agent.action_manager.space for name, agent in self.agents.items()} {name: agent.action_manager.space for name, agent in self.agents.items()}
) )
self._obs_space_in_preferred_format = True
self._action_space_in_preferred_format = True
super().__init__() super().__init__()
@property @property