Skip to content

Commit

Permalink
Merge pull request #1261 from Unity-Technologies/hotfix-050a
Browse files Browse the repository at this point in the history
Hotfix v0.5.0a
  • Loading branch information
awjuliani authored Sep 25, 2018
2 parents e82450a + 5ac6da7 commit d6dad11
Show file tree
Hide file tree
Showing 8 changed files with 540 additions and 503 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
*.idea/misc.xml
*.idea/modules.xml
*.iml
*.xml
*.cache
*/build/
*/dist/
Expand Down
200 changes: 100 additions & 100 deletions UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scenes/Banana.unity

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

public class BananaAgent : Agent
{
public GameObject myAcademyObj;
BananaAcademy myAcademy;
private BananaAcademy myAcademy;
public GameObject area;
BananaArea myArea;
bool frozen;
Expand Down Expand Up @@ -39,7 +38,7 @@ public override void InitializeAgent()
Monitor.verticalOffset = 1f;
myArea = area.GetComponent<BananaArea>();
rayPer = GetComponent<RayPerception>();
myAcademy = myAcademyObj.GetComponent<BananaAcademy>();
myAcademy = FindObjectOfType<BananaAcademy>();
}

public override void CollectObservations()
Expand Down
404 changes: 224 additions & 180 deletions UnitySDK/Assets/ML-Agents/Examples/Hallway/Scenes/HallwayIL.unity

Large diffs are not rendered by default.

387 changes: 184 additions & 203 deletions UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockIL.unity

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Python-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ file, put the file in the same directory as `envs`. For example, if the filename
of your Unity environment is 3DBall.app, in python, run:

```python
from mlagents.env import UnityEnvironment
from mlagents.envs import UnityEnvironment
env = UnityEnvironment(file_name="3DBall", worker_id=0, seed=1)
```

Expand Down
36 changes: 25 additions & 11 deletions gym-unity/gym_unity/envs/unity_env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import gym
import numpy as np
from mlagents.envs import UnityEnvironment
from gym import error, spaces, logger
from gym import error, spaces


class UnityGymException(error.Error):
Expand All @@ -11,6 +12,10 @@ class UnityGymException(error.Error):
pass


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("gym_unity")


class UnityEnv(gym.Env):
"""
Provides Gym wrapper for Unity Learning Environments.
Expand Down Expand Up @@ -44,7 +49,11 @@ def __init__(self, environment_filename: str, worker_id=0, use_visual=False, mul
if use_visual and brain.number_visual_observations == 0:
raise UnityGymException("`use_visual` was set to True, however there are no"
" visual observations as part of this environment.")
self.use_visual = brain.number_visual_observations == 1 and use_visual
self.use_visual = brain.number_visual_observations >= 1 and use_visual

if brain.number_visual_observations > 1:
logger.warning("The environment contains more than one visual observation. "
"Please note that only the first will be provided in the observation.")

if brain.num_stacked_vector_observations != 1:
raise UnityGymException(
Expand Down Expand Up @@ -114,7 +123,8 @@ def step(self, action):
if not isinstance(action, list):
raise UnityGymException("The environment was expecting `action` to be a list.")
if len(action) != self._n_agents:
raise UnityGymException("The environment was expecting a list of {} actions.".format(self._n_agents))
raise UnityGymException(
"The environment was expecting a list of {} actions.".format(self._n_agents))
else:
action = np.array(action)

Expand All @@ -136,17 +146,19 @@ def _single_step(self, info):
else:
default_observation = info.vector_observations[0, :]

return default_observation, info.rewards[0], info.local_done[0], {"text_observation": info.text_observations[0],
"brain_info": info}
return default_observation, info.rewards[0], info.local_done[0], {
"text_observation": info.text_observations[0],
"brain_info": info}

def _multi_step(self, info):
if self.use_visual:
self.visual_obs = info.visual_observations
default_observation = self.visual_obs
else:
default_observation = info.vector_observations
return list(default_observation), info.rewards, info.local_done, {"text_observation": info.text_observations,
"brain_info": info}
return list(default_observation), info.rewards, info.local_done, {
"text_observation": info.text_observations,
"brain_info": info}

def render(self, mode='rgb_array'):
return self.visual_obs
Expand All @@ -170,11 +182,13 @@ def seed(self, seed=None):

def _check_agents(self, n_agents):
if not self._multiagent and n_agents > 1:
raise UnityGymException("The environment was launched as a single-agent environment, however"
"there is more than one agent in the scene.")
raise UnityGymException(
"The environment was launched as a single-agent environment, however"
"there is more than one agent in the scene.")
elif self._multiagent and n_agents <= 1:
raise UnityGymException("The environment was launched as a mutli-agent environment, however"
"there is only one agent in the scene.")
raise UnityGymException(
"The environment was launched as a mutli-agent environment, however"
"there is only one agent in the scene.")
if self._n_agents is None:
self._n_agents = n_agents
logger.info("{} agents within environment.".format(n_agents))
Expand Down
8 changes: 4 additions & 4 deletions gym-unity/setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python

from setuptools import setup, Command, find_packages
from setuptools import setup, find_packages

setup(name='gym_unity',
version='0.1.0',
version='0.1.1',
description='Unity Machine Learning Agents Gym Interface',
license='Apache License 2.0',
author='Unity Technologies',
author_email='[email protected]',
url='https://github.com/Unity-Technologies/ml-agents',
packages=find_packages(),
install_requires = ['gym', 'mlagents']
)
install_requires=['gym', 'mlagents']
)

0 comments on commit d6dad11

Please sign in to comment.