tristandeleu / pytorch-maml-rl

Reinforcement Learning with Model-Agnostic Meta-Learning in Pytorch
MIT License
827 stars 158 forks source link

AttributeError: 'dict' object has no attribute 'iteritems' #6

Closed dragen1860 closed 6 years ago

dragen1860 commented 6 years ago
i@d:~/rl/pytorch-maml-rl$ python main.py --env-name HalfCheetahDir-v1 --num-workers 8 --fast-lr 0.1 --max-kl 0.01 --fast-batch-size 20 --meta-batch-size 40 --num-layers 2 --hidden-size 100 --num-batches 1000 --gamma 0.99 --tau 1.0 --cg-damping 1e-5 --ls-max-steps 15 --output-folder maml-halfcheetah-dir --device cuda

Traceback (most recent call last):
  File "main.py", line 138, in <module>
    main(args)
  File "main.py", line 29, in main
    config = {k: v for (k, v) in vars(args).iteritems() if k != 'device'}
AttributeError: 'dict' object has no attribute 'iteritems'

I followed your readme but the error occurs. Any tips, Thanks.

dendisuhubdy commented 6 years ago

@dragen1860 are you using Python 3+? See https://stackoverflow.com/a/30418498

dragen1860 commented 6 years ago

yes. @dendisuhubdy

dendisuhubdy commented 6 years ago

@dragen1860 iteritems() was removed from Python3, the codebase I believe is running on Python 2.7. Change main.py line 29 to config = {k: v for (k, v) in vars(args).items() if k != 'device'}, let me know.

dragen1860 commented 6 years ago

@dendisuhubdy

Traceback (most recent call last):
  File "main.py", line 139, in <module>
    main(args)
  File "main.py", line 31, in main
    config.update(device=args.device.type)
AttributeError: 'tuple' object has no attribute 'update'
dendisuhubdy commented 6 years ago

Your config is a tuple without a update attribute, config is supposed to be a dict. Did you remove the { ... } from config = { ..... }

dragen1860 commented 6 years ago

oh, I solved it . @dendisuhubdy thx. Can you update the readme to append a guide of how to install mujoco?

/home/i/conda/lib/python3.6/site-packages/mujoco_py/cymj.c:609:21: fatal error: mjmodel.h: No such file or directory
compilation terminated.
Traceback (most recent call last):
  File "/home/i/conda/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
    extra_postargs)
  File "/home/i/conda/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/home/i/conda/lib/python3.6/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/home/i/conda/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
    % (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 139, in <module>
    main(args)
  File "main.py", line 35, in main
    num_workers=args.num_workers)
  File "/home/i/rl/pytorch-maml-rl/maml_rl/sampler.py", line 21, in __init__
    queue=self.queue)
  File "/home/i/rl/pytorch-maml-rl/maml_rl/envs/subproc_vec_env.py", line 67, in __init__
    for (remote, env_fn) in zip(self.work_remotes, env_factory)]
  File "/home/i/rl/pytorch-maml-rl/maml_rl/envs/subproc_vec_env.py", line 67, in <listcomp>
    for (remote, env_fn) in zip(self.work_remotes, env_factory)]
  File "/home/i/rl/pytorch-maml-rl/maml_rl/envs/subproc_vec_env.py", line 15, in __init__
    self.env = env_fn()
  File "/home/i/rl/pytorch-maml-rl/maml_rl/sampler.py", line 10, in _make_env
    return gym.make(env_name)
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/registration.py", line 167, in make
    return registry.make(id)
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/registration.py", line 86, in make
    env = cls(**self._kwargs)
  File "/home/i/rl/pytorch-maml-rl/maml_rl/envs/utils.py", line 6, in mujoco_wrapper
    env_cls = load(entry_point)
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/registration.py", line 14, in load
    result = entry_point.load(False)
  File "/home/i/conda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/home/i/conda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/i/rl/pytorch-maml-rl/maml_rl/envs/mujoco/half_cheetah.py", line 2, in <module>
    from gym.envs.mujoco import HalfCheetahEnv as HalfCheetahEnv_
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/mujoco/__init__.py", line 1, in <module>
    from gym.envs.mujoco.mujoco_env import MujocoEnv
  File "/home/i/conda/lib/python3.6/site-packages/gym/envs/mujoco/mujoco_env.py", line 11, in <module>
    import mujoco_py
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/__init__.py", line 1, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 468, in <module>
    cymj = load_cython_ext(mjpro_path)
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 90, in load_cython_ext
    cext_so_path = builder.build()
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 202, in build
    built_so_file_path = self._build_impl()
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 274, in _build_impl
    so_file_path = super()._build_impl()
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 225, in _build_impl
    dist.run_commands()
  File "/home/i/conda/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/home/i/conda/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/i/conda/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/home/i/conda/lib/python3.6/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "/home/i/conda/lib/python3.6/site-packages/mujoco_py/builder.py", line 125, in build_extensions
    build_ext.build_extensions(self)
  File "/home/i/conda/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 194, in build_extensions
    self.build_extension(ext)
  File "/home/i/conda/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "/home/i/conda/lib/python3.6/distutils/ccompiler.py", line 574, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/home/i/conda/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1
tristandeleu commented 6 years ago

Oh my bad, I did that change locally but didn't committed it. Thank your for the feedback! As for installation for Mujoco, this is also something I forgot in the requirements (gym[mujoco] instead of gym). I will make that change. As for the installation of the software itself, I suggest going through the steps from the mujoco-py readme.