laermannjan / nip-deeprl-project

Student project in deep reinforcement learning with the OpenAI Gym. We evaluated and analyzed how different model architectures performed as agents in various games.
0 stars 0 forks source link

Pickling broken #1

Closed laermannjan closed 7 years ago

laermannjan commented 7 years ago

Environment LunarLander

Behaviour Agents cannot be pickled and written to file.

Reproduction Procedure Run any lunarlander experiment, e.g. python testbench.py LunarLander-v2 dummy

Stack Trace

Traceback (most recent call last):
  File "testbench.py", line 61, in <module>
    train(args.env, config_name, args.pickle_root, args.exp_name, args.num_cpu)
  File "/Users/jan/code/nip-deeprl-project/custom_train.py", line 128, in train
    ActWrapper(act, act_params).save(os.path.join(pickle_dir, pickle_fname))
  File "/usr/local/anaconda3/lib/python3.6/site-packages/baselines/deepq/simple.py", line 55, in save
    dill.dump((model_data, self._act_params), f)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 252, in dump
    pik.dump(obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 409, in dump
    self.save(obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 841, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 1306, in save_function
    obj.__dict__), obj=obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 751, in save_tuple
    save(element)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 1057, in save_cell
    pickler.save_reduce(_create_cell, (obj.cell_contents,), obj=obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 610, in save_reduce
    save(args)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 736, in save_tuple
    save(element)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 521, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 634, in save_reduce
    save(state)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 841, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 521, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 634, in save_reduce
    save(state)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 476, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/anaconda3/lib/python3.6/site-packages/dill/dill.py", line 841, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 821, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 847, in _batch_setitems
    save(v)
  File "/usr/local/anaconda3/lib/python3.6/pickle.py", line 496, in save
    rv = reduce(self.proto)
TypeError: can't pickle SwigPyObject objects
laermannjan commented 7 years ago

Checkout misc_util.EzPickle and misc_util.relatively_safe_pickle(...). Maybe we can also unpack or strip the SwigPyObject from the System state before pickling. Or is this just a bug concerning dill.py?

laermannjan commented 7 years ago

Fixed with 65cebd4266234e5082ff043aa3e135a31d8bc5a2