-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support Actor preprocessing network reuse for continuous case, fixes in DQN network #1128
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be1c8cd
DQN:
opcode81 18ed981
Add pickle/serialisation utils: setstate and getstate
opcode81 0b49484
continuous.Critic: Add flag apply_preprocess_net_to_obs_only to allow…
opcode81 d18ded3
CriticFactoryReuseActor: Fix the case where we want to reuse an actor's
opcode81 7473741
Fix typo
opcode81 250a129
SamplingConfig: Improve docstrings of replay_buffer_save_only_last_ob…
opcode81 8ac6bf5
Improve docstrings
opcode81 8308392
Mention CHANGELOG.md in PR template
opcode81 40f7724
Update change log with changes from #1128
opcode81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"""Helper functions for persistence/pickling, which have been copied from sensAI (specifically `sensai.util.pickle`).""" | ||
|
||
from collections.abc import Iterable | ||
from copy import copy | ||
from typing import Any | ||
|
||
|
||
def setstate( | ||
cls: type, | ||
obj: Any, | ||
state: dict[str, Any], | ||
renamed_properties: dict[str, str] | None = None, | ||
new_optional_properties: list[str] | None = None, | ||
new_default_properties: dict[str, Any] | None = None, | ||
removed_properties: list[str] | None = None, | ||
) -> None: | ||
"""Helper function for safe implementations of `__setstate__` in classes, which appropriately handles the cases where | ||
a parent class already implements `__setstate__` and where it does not. Call this function whenever you would actually | ||
like to call the super-class' implementation. | ||
Unfortunately, `__setstate__` is not implemented in `object`, rendering `super().__setstate__(state)` invalid in the general case. | ||
|
||
:param cls: the class in which you are implementing `__setstate__` | ||
:param obj: the instance of `cls` | ||
:param state: the state dictionary | ||
:param renamed_properties: a mapping from old property names to new property names | ||
:param new_optional_properties: a list of names of new property names, which, if not present, shall be initialized with None | ||
:param new_default_properties: a dictionary mapping property names to their default values, which shall be added if they are not present | ||
:param removed_properties: a list of names of properties that are no longer being used | ||
""" | ||
# handle new/changed properties | ||
if renamed_properties is not None: | ||
for mOld, mNew in renamed_properties.items(): | ||
if mOld in state: | ||
state[mNew] = state[mOld] | ||
del state[mOld] | ||
if new_optional_properties is not None: | ||
for mNew in new_optional_properties: | ||
if mNew not in state: | ||
state[mNew] = None | ||
if new_default_properties is not None: | ||
for mNew, mValue in new_default_properties.items(): | ||
if mNew not in state: | ||
state[mNew] = mValue | ||
if removed_properties is not None: | ||
for p in removed_properties: | ||
if p in state: | ||
del state[p] | ||
# call super implementation, if any | ||
s = super(cls, obj) | ||
if hasattr(s, "__setstate__"): | ||
s.__setstate__(state) | ||
else: | ||
obj.__dict__ = state | ||
|
||
|
||
def getstate( | ||
cls: type, | ||
obj: Any, | ||
transient_properties: Iterable[str] | None = None, | ||
excluded_properties: Iterable[str] | None = None, | ||
override_properties: dict[str, Any] | None = None, | ||
excluded_default_properties: dict[str, Any] | None = None, | ||
) -> dict[str, Any]: | ||
"""Helper function for safe implementations of `__getstate__` in classes, which appropriately handles the cases where | ||
a parent class already implements `__getstate__` and where it does not. Call this function whenever you would actually | ||
like to call the super-class' implementation. | ||
Unfortunately, `__getstate__` is not implemented in `object`, rendering `super().__getstate__()` invalid in the general case. | ||
|
||
:param cls: the class in which you are implementing `__getstate__` | ||
:param obj: the instance of `cls` | ||
:param transient_properties: transient properties which shall be set to None in serializations | ||
:param excluded_properties: properties which shall be completely removed from serializations | ||
:param override_properties: a mapping from property names to values specifying (new or existing) properties which are to be set; | ||
use this to set a fixed value for an existing property or to add a completely new property | ||
:param excluded_default_properties: properties which shall be completely removed from serializations, if they are set | ||
to the given default value | ||
:return: the state dictionary, which may be modified by the receiver | ||
""" | ||
s = super(cls, obj) | ||
d = s.__getstate__() if hasattr(s, "__getstate__") else obj.__dict__ | ||
d = copy(d) | ||
if transient_properties is not None: | ||
for p in transient_properties: | ||
if p in d: | ||
d[p] = None | ||
if excluded_properties is not None: | ||
for p in excluded_properties: | ||
if p in d: | ||
del d[p] | ||
if override_properties is not None: | ||
for k, v in override_properties.items(): | ||
d[k] = v | ||
if excluded_default_properties is not None: | ||
for p, v in excluded_default_properties.items(): | ||
if p in d and d[p] == v: | ||
del d[p] | ||
return d |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.