Skip to content

Commit

Permalink
Commit missing example.gym.helpers module.
Browse files Browse the repository at this point in the history
Fixes #91.

PiperOrigin-RevId: 350354657
Change-Id: I11e1af1b616f56792f7be2233377ce7d5e928bf4
  • Loading branch information
sinopalnikov authored and tkiela1 committed Jan 6, 2021
1 parent 0899c0f commit 0417c6e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/gym/helpers.py
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

0 comments on commit 0417c6e

Please sign in to comment.