本文整理匯總了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)