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

buffer.dump(f) method not working (Latest d3rlpy v2.0.2 installed) #299

Closed
HateBunnyPlzzz opened this issue Jul 18, 2023 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@HateBunnyPlzzz
Copy link
Contributor

When running the code example in the newest documentation of Data Collection in tutorial section, the buffer.dump(f) method in the loop is throwing of UnsupportedOperation: read error

To reproduce: run the following code

# setup algorithm
dqn = d3rlpy.algos.DQNConfig().create()

# prepare experience replay buffer
buffer = d3rlpy.dataset.create_fifo_replay_buffer(limit=100000, env=env)

# prepare exploration strategy if necessary
explorer = d3rlpy.algos.ConstantEpsilonGreedy(0.3)

# start data collection
dqn.fit_online(env, buffer, explorer, n_steps=100000)

# save ReplayBuffer
with open("replay_dataset.h5", "wb") as f:
  buffer.dump(f)

Expected behavior
Expected to dump the replay_buffer.h5 file successfully

for more details here's the full error code below

UnsupportedOperation                      Traceback (most recent call last)
Cell In [11], line 2
      1 with open("replay_dataset.h5", "wb") as f:
----> 2   buffer.dump(f)

File ~/anaconda3/envs/ICRL/lib/python3.10/site-packages/d3rlpy/dataset/replay_buffer.py:245, in ReplayBuffer.dump(self, f)
    234 def dump(self, f: BinaryIO) -> None:
    235     """Dumps buffer data.
    236 
    237     .. code-block:: python
   (...)
    243         f: IO object to write to.
    244     """
--> 245     dump(self._buffer.episodes, f)

File ~/anaconda3/envs/ICRL/lib/python3.10/site-packages/d3rlpy/dataset/io.py:25, in dump(episodes, f)
     23 keys = list(serializedData[0].keys())
     24 with h5py.File(f, "w") as h5:
---> 25     h5.create_dataset("columns", data=keys)
     26     h5.create_dataset("total_size", data=len(episodes))
     27     for key in keys:

File ~/anaconda3/envs/ICRL/lib/python3.10/site-packages/h5py/_hl/group.py:183, in Group.create_dataset(self, name, shape, dtype, data, **kwds)
    180         parent_path, name = name.rsplit(b'/', 1)
...
File h5py/_proxy.pyx:146, in h5py._proxy.dset_rw()

File h5py/h5fd.pyx:163, in h5py.h5fd.H5FD_fileobj_read()

UnsupportedOperation: read
@HateBunnyPlzzz HateBunnyPlzzz added the bug Something isn't working label Jul 18, 2023
@takuseno
Copy link
Owner

@HateBunnyPlzzz Thank you for reporting this! This has been fixed at this commit: cb9ca69 . I'll release a patch that includes this fix tomorrow.

@takuseno
Copy link
Owner

The latest patch has been released.
https://github.com/takuseno/d3rlpy/releases/tag/v2.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants