浏览代码

make sure DefaultTrainerDict is pickle-able (#4842)

/MLA-1734-demo-provider
GitHub 4 年前
当前提交
af5f6ad0
共有 3 个文件被更改,包括 16 次插入1 次删除
  1. 1
      com.unity.ml-agents/CHANGELOG.md
  2. 8
      ml-agents/mlagents/trainers/settings.py
  3. 8
      ml-agents/mlagents/trainers/tests/test_settings.py

1
com.unity.ml-agents/CHANGELOG.md


#### com.unity.ml-agents (C#)
- Fix a compile warning about using an obsolete enum in `GrpcExtensions.cs`. (#4812)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Fixed a bug that would cause an exception when `RunOptions` was deserialized via `pickle`. (#4842)
## [1.7.2-preview] - 2020-12-22

8
ml-agents/mlagents/trainers/settings.py


class DefaultTrainerDict(collections.defaultdict):
def __init__(self, *args):
super().__init__(TrainerSettings, *args)
# Depending on how this is called, args may have the defaultdict
# callable at the start of the list or not. In particular, unpickling
# will pass [TrainerSettings].
if args and args[0] == TrainerSettings:
super().__init__(*args)
else:
super().__init__(TrainerSettings, *args)
def __missing__(self, key: Any) -> "TrainerSettings":
if TrainerSettings.default_override is not None:

8
ml-agents/mlagents/trainers/tests/test_settings.py


import attr
import cattr
import pickle
import pytest
import yaml

test1_settings.max_steps = 1
test1_settings.network_settings.hidden_units == default_settings_cls.network_settings.hidden_units
check_if_different(test1_settings, default_settings_cls)
def test_pickle():
# Make sure RunOptions is pickle-able.
run_options = RunOptions()
p = pickle.dumps(run_options)
pickle.loads(p)
正在加载...
取消
保存