本文整理汇总了Python中gym.core.Env方法的典型用法代码示例。如果您正苦于以下问题:Python core.Env方法的具体用法?Python core.Env怎么用?Python core.Env使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gym.core
的用法示例。
在下文中一共展示了core.Env方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize
# 需要导入模块: from gym import core [as 别名]
# 或者: from gym.core import Env [as 别名]
def serialize(obj):
"""
Serialize any object to a dictionary, so that it can be dumped easily to a JSON file.
Four rules are applied:
- To be able to recreate the object, specify its class, or its spec id if the object is an Env.
- If the object has a config dictionary field, use it. It is assumed that this config suffices to recreate a
similar object.
- If the object is Serializable, use its recursive conversion to a dictionary.
- Else, use its __dict__ by applying repr() on its values
:param obj: an object
:return: a dictionary describing the object
"""
if hasattr(obj, "config"):
d = obj.config
elif isinstance(obj, Serializable):
d = obj.to_dict()
else:
d = {key: repr(value) for (key, value) in obj.__dict__.items()}
d['__class__'] = repr(obj.__class__)
if isinstance(obj, Env):
d['id'] = obj.spec.id
d['import_module'] = getattr(obj, "import_module", None)
return d
示例2: __init__
# 需要导入模块: from gym import core [as 别名]
# 或者: from gym.core import Env [as 别名]
def __init__(self, task=None):
super(Env, self).__init__()
if task is None:
task = self.sample_tasks(1)[0]
self.set_task(task)