Skip to content

The Gym Wrapper Does Not Work for Some Examples #3953

Closed
@vwxyzjn

Description

@vwxyzjn

Describe the bug
Hi, thanks for the amazing work. I was trying to run the example environments using my own RL library using the documentation from here: https://github.com/Unity-Technologies/ml-agents/blob/release_1_docs/gym-unity/README.md. However, I get an error of the following when calling env.action_space.sample() in the GridWorld.x86_64 example, however the script works with Basic.x86_64

UnityActionException: The behavior GridWorld?team=0 needs an input of dimension (9, 1) but received input of dimension (1, 1)

To Reproduce
The operating system that I am using is Linux, and I build the binaries from example using the following command:

TERM=xterm Unity -projectPath ./Project \
-batchmode \
-logFile ./log.txt \
-executeMethod Unity.MLAgents.StandaloneBuildTest.BuildStandalonePlayerOSX \
--mlagents-build-scene-path Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity \
--mlagents-build-output-path Binaries/GridWorld.x86_64 

...

TERM=xterm Unity -projectPath ./Project \
-batchmode \
-logFile ./log.txt \
-executeMethod Unity.MLAgents.StandaloneBuildTest.BuildStandalonePlayerOSX \
--mlagents-build-scene-path Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicTarget.unity \
--mlagents-build-output-path Binaries/CrawlerDynamicTarget.x86_64 

TERM=xterm Unity -projectPath ./Project \
-batchmode \
-logFile ./log.txt \
-executeMethod Unity.MLAgents.StandaloneBuildTest.BuildStandalonePlayerOSX \
--mlagents-build-scene-path Assets/ML-Agents/Examples/Reacher/Scenes/Reacher.unity \
--mlagents-build-output-path Binaries/Reacher.x86_64 

Then I run the following script

from mlagents_envs.environment import UnityEnvironment
from gym_unity.envs import UnityToGymWrapper


unity_env = UnityEnvironment(
    file_name="Project/Binaries/GridWorld.x86_64")
env = UnityToGymWrapper(unity_env, use_visual=True, flatten_branched=True)

observation = env.reset()
for _ in range(1000):
  env.render()
  action = env.action_space.sample() # your agent here (this takes random actions)
  observation, reward, done, info = env.step(action)

  if done:
    observation = env.reset()
env.close()

and whole outputs for the error is

Found path: /home/costa/Documents/work/go/src/github.com/Unity-Technologies/ml-agents/Project/Binaries/GridWorld.x86_64
Mono path[0] = '/home/costa/Documents/work/go/src/github.com/Unity-Technologies/ml-agents/Project/Binaries/GridWorld_Data/Managed'
Mono config path = '/home/costa/Documents/work/go/src/github.com/Unity-Technologies/ml-agents/Project/Binaries/GridWorld_Data/MonoBleedingEdge/etc'
Preloaded 'lib_burst_generated.so'
Preloaded 'libgrpc_csharp_ext.x64.so'
Preloaded 'ScreenSelector.so'
Display 0 'LG HDR 5K 34"': 5120x2160 (primary device).
Logging to /home/costa/.config/unity3d/Unity Technologies/UnityEnvironment/Player.log
2020-05-12 22:25:16 INFO [environment.py:111] Connected to Unity environment with package version 1.0.0-preview and communication version 1.0.0
2020-05-12 22:25:17 INFO [environment.py:342] Connected new brain:
GridWorld?team=0
/home/costa/anaconda3/lib/python3.7/site-packages/gym/logger.py:30: UserWarning: WARN: Box bound precision lowered by casting to float32
  warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))
Traceback (most recent call last):

  File "/home/costa/Documents/work/go/src/github.com/Unity-Technologies/ml-agents/test_gym.py", line 13, in <module>
    observation, reward, done, info = env.step(action)

  File "/home/costa/anaconda3/lib/python3.7/site-packages/gym_unity/envs/__init__.py", line 171, in step
    self._env.set_actions(self.name, action)

  File "/home/costa/anaconda3/lib/python3.7/site-packages/mlagents_envs/environment.py", line 419, in set_actions
    behavior_name, expected_shape, action.shape

UnityActionException: The behavior GridWorld?team=0 needs an input of dimension (9, 1) but received input of dimension (1, 1)

Environment (please complete the following information):

  • Unity Version: 2018.4.22
  • OS + version: Arch Linux
  • mlagents_envs.version : '0.16.0'
  • TensorFlow version: N/A
  • Environment: Grid

Metadata

Metadata

Assignees

Labels

bugIssue describes a potential bug in ml-agents.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions