-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit missing example.gym.helpers module.
Fixes #91. PiperOrigin-RevId: 350354657 Change-Id: I11e1af1b616f56792f7be2233377ce7d5e928bf4
- Loading branch information
1 parent
0899c0f
commit 0417c6e
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,46 @@ | ||
# python3 | ||
# Copyright 2018 DeepMind Technologies Limited. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""OpenAI Gym environment factory.""" | ||
|
||
from acme import wrappers | ||
import dm_env | ||
import gym | ||
|
||
TASKS = { | ||
'debug': ['MountainCarContinuous-v0'], | ||
'default': [ | ||
'HalfCheetah-v2', 'Hopper-v2', 'InvertedDoublePendulum-v2', | ||
'InvertedPendulum-v2', 'Reacher-v2', 'Swimmer-v2', 'Walker2d-v2' | ||
], | ||
} | ||
|
||
|
||
def make_environment( | ||
evaluation: bool = False, | ||
task: str = 'MountainCarContinuous-v0') -> dm_env.Environment: | ||
"""Creates an OpenAI Gym environment.""" | ||
del evaluation | ||
|
||
# Load the gym environment. | ||
environment = gym.make(task) | ||
|
||
# Make sure the environment obeys the dm_env.Environment interface. | ||
environment = wrappers.GymWrapper(environment) | ||
# Clip the action returned by the agent to the environment spec. | ||
environment = wrappers.CanonicalSpecWrapper(environment, clip=True) | ||
environment = wrappers.SinglePrecisionWrapper(environment) | ||
|
||
return environment |