Skip to content

Commit d6dad11

Browse files
authored
Merge pull request #1261 from Unity-Technologies/hotfix-050a
Hotfix v0.5.0a
2 parents e82450a + 5ac6da7 commit d6dad11

File tree

8 files changed

+540
-503
lines changed

8 files changed

+540
-503
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
*.idea/misc.xml
6969
*.idea/modules.xml
7070
*.iml
71-
*.xml
7271
*.cache
7372
*/build/
7473
*/dist/

UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scenes/Banana.unity

Lines changed: 100 additions & 100 deletions
Large diffs are not rendered by default.

UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scripts/BananaAgent.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
public class BananaAgent : Agent
77
{
8-
public GameObject myAcademyObj;
9-
BananaAcademy myAcademy;
8+
private BananaAcademy myAcademy;
109
public GameObject area;
1110
BananaArea myArea;
1211
bool frozen;
@@ -39,7 +38,7 @@ public override void InitializeAgent()
3938
Monitor.verticalOffset = 1f;
4039
myArea = area.GetComponent<BananaArea>();
4140
rayPer = GetComponent<RayPerception>();
42-
myAcademy = myAcademyObj.GetComponent<BananaAcademy>();
41+
myAcademy = FindObjectOfType<BananaAcademy>();
4342
}
4443

4544
public override void CollectObservations()

UnitySDK/Assets/ML-Agents/Examples/Hallway/Scenes/HallwayIL.unity

Lines changed: 224 additions & 180 deletions
Large diffs are not rendered by default.

UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockIL.unity

Lines changed: 184 additions & 203 deletions
Large diffs are not rendered by default.

docs/Python-API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ file, put the file in the same directory as `envs`. For example, if the filename
5050
of your Unity environment is 3DBall.app, in python, run:
5151

5252
```python
53-
from mlagents.env import UnityEnvironment
53+
from mlagents.envs import UnityEnvironment
5454
env = UnityEnvironment(file_name="3DBall", worker_id=0, seed=1)
5555
```
5656

gym-unity/gym_unity/envs/unity_env.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import logging
12
import gym
23
import numpy as np
34
from mlagents.envs import UnityEnvironment
4-
from gym import error, spaces, logger
5+
from gym import error, spaces
56

67

78
class UnityGymException(error.Error):
@@ -11,6 +12,10 @@ class UnityGymException(error.Error):
1112
pass
1213

1314

15+
logging.basicConfig(level=logging.INFO)
16+
logger = logging.getLogger("gym_unity")
17+
18+
1419
class UnityEnv(gym.Env):
1520
"""
1621
Provides Gym wrapper for Unity Learning Environments.
@@ -44,7 +49,11 @@ def __init__(self, environment_filename: str, worker_id=0, use_visual=False, mul
4449
if use_visual and brain.number_visual_observations == 0:
4550
raise UnityGymException("`use_visual` was set to True, however there are no"
4651
" visual observations as part of this environment.")
47-
self.use_visual = brain.number_visual_observations == 1 and use_visual
52+
self.use_visual = brain.number_visual_observations >= 1 and use_visual
53+
54+
if brain.number_visual_observations > 1:
55+
logger.warning("The environment contains more than one visual observation. "
56+
"Please note that only the first will be provided in the observation.")
4857

4958
if brain.num_stacked_vector_observations != 1:
5059
raise UnityGymException(
@@ -114,7 +123,8 @@ def step(self, action):
114123
if not isinstance(action, list):
115124
raise UnityGymException("The environment was expecting `action` to be a list.")
116125
if len(action) != self._n_agents:
117-
raise UnityGymException("The environment was expecting a list of {} actions.".format(self._n_agents))
126+
raise UnityGymException(
127+
"The environment was expecting a list of {} actions.".format(self._n_agents))
118128
else:
119129
action = np.array(action)
120130

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

139-
return default_observation, info.rewards[0], info.local_done[0], {"text_observation": info.text_observations[0],
140-
"brain_info": info}
149+
return default_observation, info.rewards[0], info.local_done[0], {
150+
"text_observation": info.text_observations[0],
151+
"brain_info": info}
141152

142153
def _multi_step(self, info):
143154
if self.use_visual:
144155
self.visual_obs = info.visual_observations
145156
default_observation = self.visual_obs
146157
else:
147158
default_observation = info.vector_observations
148-
return list(default_observation), info.rewards, info.local_done, {"text_observation": info.text_observations,
149-
"brain_info": info}
159+
return list(default_observation), info.rewards, info.local_done, {
160+
"text_observation": info.text_observations,
161+
"brain_info": info}
150162

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

171183
def _check_agents(self, n_agents):
172184
if not self._multiagent and n_agents > 1:
173-
raise UnityGymException("The environment was launched as a single-agent environment, however"
174-
"there is more than one agent in the scene.")
185+
raise UnityGymException(
186+
"The environment was launched as a single-agent environment, however"
187+
"there is more than one agent in the scene.")
175188
elif self._multiagent and n_agents <= 1:
176-
raise UnityGymException("The environment was launched as a mutli-agent environment, however"
177-
"there is only one agent in the scene.")
189+
raise UnityGymException(
190+
"The environment was launched as a mutli-agent environment, however"
191+
"there is only one agent in the scene.")
178192
if self._n_agents is None:
179193
self._n_agents = n_agents
180194
logger.info("{} agents within environment.".format(n_agents))

gym-unity/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env python
22

3-
from setuptools import setup, Command, find_packages
3+
from setuptools import setup, find_packages
44

55
setup(name='gym_unity',
6-
version='0.1.0',
6+
version='0.1.1',
77
description='Unity Machine Learning Agents Gym Interface',
88
license='Apache License 2.0',
99
author='Unity Technologies',
1010
author_email='ML-Agents@unity3d.com',
1111
url='https://github.com/Unity-Technologies/ml-agents',
1212
packages=find_packages(),
13-
install_requires = ['gym', 'mlagents']
14-
)
13+
install_requires=['gym', 'mlagents']
14+
)

0 commit comments

Comments
 (0)