-
Notifications
You must be signed in to change notification settings - Fork 223
Fix episodic buffer __len__ #155
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
Conversation
The behaviour of episodic replay buffers has been changed so that now __len__ returns the number of transitions, not episodes, to fix chainer#138. You can use the n_episodes property to get the number of episodes in the buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me except it should be clear which class should take care of size checks. For example, I suppose update_if_necessary
should have the same check as the lines you added to PCL.
Besides, I left some suggestions that might improve the code.
chainerrl/replay_buffer.py
Outdated
def stop_current_episode(self): | ||
"""Notify the buffer that the current episode is interrupted. | ||
|
||
When a transtion with is_state_terminal=True is appended, the buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest starting the document with the cases when the method should be called, for example:
You may want to interrupt the current episode and start a new one before observing a terminal state. This is typical in continuing envs. In such cases, you need to call this method before appending a new transition so that the buffer will treat it as an initial transition of a new episode.
This method should not be called after an episode whose termination is already notified by appending a transition with is_state_terminal=True.
chainerrl/replay_buffer.py
Outdated
@@ -14,14 +14,16 @@ | |||
from chainerrl.misc.prioritized import PrioritizedBuffer | |||
|
|||
|
|||
class ReplayBuffer(object): | |||
class AbstractReplayBuffer(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you decorate the methods with @abstractmethod
?
and raise an error instead of pass
Thank you for your review! I added a check of |
LGTM! |
AbstractReplayBuffer
andAbstractEpisodicReplayBuffer
to clarify the interfaces of replay buffers__len__
ofEpisodicReplayBuffer
andPrioritizedEpisodicReplayBuffer
so that they now return the number of transitions, not of episodes.n_episodes
property to count the number of episodesResolves #138