marl-book / codebase

Official code repo for the MARL book (www.marl-book.com)
343 stars 47 forks source link

Getting error when try to run the code. #29

Open Jaron-U opened 5 hours ago

Jaron-U commented 5 hours ago

Hi,

I got this error when i tried to run the code:

HYDRA_FULL_ERROR=1 python run.py +algorithm=ac env.name="lbforaging:Foraging-8x8-2p-3f-v3" env.time_limit=25
(15698) [WARNING] - (10/21 18:02:57) - root >> No seed has been set.
ActorCritic(
  (actor): MultiAgentFCNetwork(
    (independent): ModuleList(
      (0-1): 2 x Sequential(
        (0): Linear(in_features=15, out_features=64, bias=True)
        (1): ReLU()
        (2): Linear(in_features=64, out_features=64, bias=True)
        (3): ReLU()
        (4): Linear(in_features=64, out_features=6, bias=True)
      )
    )
  )
  (critic): MultiAgentFCNetwork(
    (independent): ModuleList(
      (0-1): 2 x Sequential(
        (0): Linear(in_features=15, out_features=64, bias=True)
        (1): ReLU()
        (2): Linear(in_features=64, out_features=64, bias=True)
        (3): ReLU()
        (4): Linear(in_features=64, out_features=1, bias=True)
      )
    )
  )
  (target_critic): MultiAgentFCNetwork(
    (independent): ModuleList(
      (0-1): 2 x Sequential(
        (0): Linear(in_features=15, out_features=64, bias=True)
        (1): ReLU()
        (2): Linear(in_features=64, out_features=64, bias=True)
        (3): ReLU()
        (4): Linear(in_features=64, out_features=1, bias=True)
      )
    )
  )
)
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/gymnasium/utils/passive_env_checker.py:245: UserWarning: WARN: The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: <class 'list'>
  logger.warn(
Error executing job with overrides: ['+algorithm=ac', 'env.name=lbforaging:Foraging-8x8-2p-3f-v3', 'env.time_limit=25']
Traceback (most recent call last):
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 92, in _call_target
    return _target_(*args, **kwargs)
  File "/home/jianglongyu/Documents/multi_agent/marl_lbforaging/marlbase/ac/train.py", line 103, in main
    batch_rew[n, :] = torch.tensor(reward)
RuntimeError: The expanded size of the tensor (2) must match the existing size (8) at non-singleton dimension 1.  Target sizes: [8, 2].  Tensor sizes: [8]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jianglongyu/Documents/multi_agent/marl_lbforaging/marlbase/run.py", line 43, in <module>
    main()
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/main.py", line 94, in decorated_main
    _run_hydra(
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "/home/jianglongyu/Documents/multi_agent/marl_lbforaging/marlbase/run.py", line 37, in main
    hydra.utils.call(cfg.algorithm, env, eval_env, logger, _recursive_=False)
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 226, in instantiate
    return instantiate_node(
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 347, in instantiate_node
    return _call_target(_target_, partial, args, kwargs, full_key)
  File "/home/jianglongyu/miniconda3/envs/marlbase/lib/python3.10/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 97, in _call_target
    raise InstantiationException(msg) from e
hydra.errors.InstantiationException: Error in call to target 'ac.train.main':
RuntimeError('The expanded size of the tensor (2) must match the existing size (8) at non-singleton dimension 1.  Target sizes: [8, 2].  Tensor sizes: [8]')
full_key: algorithm
Jaron-U commented 4 hours ago

update: I can run the dqn