Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent ID KeyError #49

Open
abastola0 opened this issue Apr 28, 2024 · 4 comments
Open

Agent ID KeyError #49

abastola0 opened this issue Apr 28, 2024 · 4 comments

Comments

@abastola0
Copy link

If anyone else is facing this same issue. I tried reinstalling the metadrive to the latest version but the latest one requires some dependencies incompatible with older python version.

Failure # 1 (occurred at 2024-04-28_19-08-33)
[36mray::CoPOTrainer.train()[39m (pid=517814, ip=130.127.106.66, repr=CoPOTrainer)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/tune/trainable/trainable.py", line 367, in train
    raise skipped from exception_cause(skipped)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/tune/trainable/trainable.py", line 364, in train
    result = self.step()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/algorithms/algorithm.py", line 749, in step
    results, train_iter_ctx = self._run_one_training_iteration()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/algorithms/algorithm.py", line 2623, in _run_one_training_iteration
    results = self.training_step()
  File "/home/abastol/working/cleanCOPO/algo_copo.py", line 534, in training_step
    worker_set=self.workers, max_env_steps=self.config.train_batch_size
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/execution/rollout_ops.py", line 86, in synchronous_parallel_sample
    lambda w: w.sample(), local_worker=False, healthy_only=True
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/worker_set.py", line 696, in foreach_worker
    handle_remote_call_result_errors(remote_results, self._ignore_worker_failures)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/worker_set.py", line 73, in handle_remote_call_result_errors
    raise r.get()
ray.exceptions.RayTaskError(KeyError): [36mray::RolloutWorker.apply()[39m (pid=517895, ip=130.127.106.66, repr=<ray.rllib.evaluation.rollout_worker.RolloutWorker object at 0x7af041348c10>)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/utils/actor_manager.py", line 183, in apply
    raise e
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/utils/actor_manager.py", line 174, in apply
    return func(self, *args, **kwargs)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/execution/rollout_ops.py", line 86, in <lambda>
    lambda w: w.sample(), local_worker=False, healthy_only=True
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/rollout_worker.py", line 900, in sample
    batches = [self.input_reader.next()]
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 92, in next
    batches = [self.get_data()]
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 285, in get_data
    item = next(self._env_runner)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 721, in _env_runner
    base_env.send_actions(actions_to_send)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/env/multi_agent_env.py", line 615, in send_actions
    raise e
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/env/multi_agent_env.py", line 608, in send_actions
    obs, rewards, dones, infos = env.step(agent_dict)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 309, in step
    o, r, d, i = super(LCFEnv, self).step(actions)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 96, in step
    self._update_distance_map(dones=d)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 143, in _update_distance_map
    if hasattr(self, "vehicles_including_just_terminated"):
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/envs/base_env.py", line 490, in vehicles_including_just_terminated
    ret.update(self.agent_manager.just_terminated_agents)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 276, in just_terminated_agents
    for agent_name, v_name in self._agents_finished_this_frame.items()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 276, in <dictcomp>
    for agent_name, v_name in self._agents_finished_this_frame.items()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 289, in get_agent
    object_name = self.agent_to_object(agent_name)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 316, in agent_to_object
    return self._agent_to_object[agent_id]
KeyError: 'agent15'
Failure # 2 (occurred at 2024-04-28_19-09-13)
[36mray::CoPOTrainer.train()[39m (pid=533950, ip=130.127.106.66, repr=CoPOTrainer)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/tune/trainable/trainable.py", line 367, in train
    raise skipped from exception_cause(skipped)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/tune/trainable/trainable.py", line 364, in train
    result = self.step()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/algorithms/algorithm.py", line 749, in step
    results, train_iter_ctx = self._run_one_training_iteration()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/algorithms/algorithm.py", line 2623, in _run_one_training_iteration
    results = self.training_step()
  File "/home/abastol/working/cleanCOPO/algo_copo.py", line 534, in training_step
    worker_set=self.workers, max_env_steps=self.config.train_batch_size
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/execution/rollout_ops.py", line 86, in synchronous_parallel_sample
    lambda w: w.sample(), local_worker=False, healthy_only=True
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/worker_set.py", line 696, in foreach_worker
    handle_remote_call_result_errors(remote_results, self._ignore_worker_failures)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/worker_set.py", line 73, in handle_remote_call_result_errors
    raise r.get()
ray.exceptions.RayTaskError(KeyError): [36mray::RolloutWorker.apply()[39m (pid=534063, ip=130.127.106.66, repr=<ray.rllib.evaluation.rollout_worker.RolloutWorker object at 0x72f28a442f10>)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/utils/actor_manager.py", line 183, in apply
    raise e
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/utils/actor_manager.py", line 174, in apply
    return func(self, *args, **kwargs)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/execution/rollout_ops.py", line 86, in <lambda>
    lambda w: w.sample(), local_worker=False, healthy_only=True
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/rollout_worker.py", line 900, in sample
    batches = [self.input_reader.next()]
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 92, in next
    batches = [self.get_data()]
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 285, in get_data
    item = next(self._env_runner)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/evaluation/sampler.py", line 721, in _env_runner
    base_env.send_actions(actions_to_send)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/env/multi_agent_env.py", line 615, in send_actions
    raise e
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/ray/rllib/env/multi_agent_env.py", line 608, in send_actions
    obs, rewards, dones, infos = env.step(agent_dict)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 309, in step
    o, r, d, i = super(LCFEnv, self).step(actions)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 96, in step
    self._update_distance_map(dones=d)
  File "/home/abastol/working/cleanCOPO/utils/env_wrappers.py", line 143, in _update_distance_map
    if hasattr(self, "vehicles_including_just_terminated"):
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/envs/base_env.py", line 490, in vehicles_including_just_terminated
    ret.update(self.agent_manager.just_terminated_agents)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 276, in just_terminated_agents
    for agent_name, v_name in self._agents_finished_this_frame.items()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 276, in <dictcomp>
    for agent_name, v_name in self._agents_finished_this_frame.items()
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 289, in get_agent
    object_name = self.agent_to_object(agent_name)
  File "/home/abastol/modules/anaconda3/envs/copo/lib/python3.7/site-packages/metadrive/manager/agent_manager.py", line 316, in agent_to_object
    return self._agent_to_object[agent_id]
KeyError: 'agent29'

@SimonWicks1
Copy link

I met the same problem. Did you solve it?

@abastola0
Copy link
Author

I met the same problem. Did you solve it?

nope i kinda moved away from this because i keep getting some more. I suspect this is because of dependency mismatch. Were you able to resolve?

@pengzhenghao
Copy link
Member

pengzhenghao commented May 18, 2024 via email

@Kayn-2019
Copy link

pip install metadrive-simulator== 0.4.2.3 will solve the problem,
but you need to modify the env_wrappers.py to let metadrive suport openai.gym, like:

from metadrive.envs.gym_wrapper import createGymWrapper
env = createGymWrapper(MetaDriveEnv)(config={"use_render": True}) # wrap the environme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants