Skip to content

Commit 662d1a9

Browse files
committed
added a few extra things to make ml-agents-dots compatible with 0.15.1 with minimal changes
1 parent 04e4e1d commit 662d1a9

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

ml-agents-envs~/mlagents_dots_envs/unity_environment.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,88 @@
3838

3939

4040
class UnityEnvironment(BaseEnv):
41+
API_VERSION = "API-14" # TODO : REMOVE
42+
DEFAULT_EDITOR_PORT = 5004 # TODO : REMOVE
43+
PORT_COMMAND_LINE_ARG = "--mlagents-port" # TODO : REMOVE
44+
45+
@staticmethod # TODO : REMOVE
46+
def validate_environment_path(env_path: str) -> Optional[str]:
47+
# Strip out executable extensions if passed
48+
env_path = (
49+
env_path.strip()
50+
.replace(".app", "")
51+
.replace(".exe", "")
52+
.replace(".x86_64", "")
53+
.replace(".x86", "")
54+
)
55+
true_filename = os.path.basename(os.path.normpath(env_path))
56+
logger.debug("The true file name is {}".format(true_filename))
57+
58+
if not (glob.glob(env_path) or glob.glob(env_path + ".*")):
59+
return None
60+
61+
cwd = os.getcwd()
62+
launch_string = None
63+
true_filename = os.path.basename(os.path.normpath(env_path))
64+
if platform == "linux" or platform == "linux2":
65+
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86_64")
66+
if len(candidates) == 0:
67+
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86")
68+
if len(candidates) == 0:
69+
candidates = glob.glob(env_path + ".x86_64")
70+
if len(candidates) == 0:
71+
candidates = glob.glob(env_path + ".x86")
72+
if len(candidates) > 0:
73+
launch_string = candidates[0]
74+
75+
elif platform == "darwin":
76+
candidates = glob.glob(
77+
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", true_filename)
78+
)
79+
if len(candidates) == 0:
80+
candidates = glob.glob(
81+
os.path.join(env_path + ".app", "Contents", "MacOS", true_filename)
82+
)
83+
if len(candidates) == 0:
84+
candidates = glob.glob(
85+
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", "*")
86+
)
87+
if len(candidates) == 0:
88+
candidates = glob.glob(
89+
os.path.join(env_path + ".app", "Contents", "MacOS", "*")
90+
)
91+
if len(candidates) > 0:
92+
launch_string = candidates[0]
93+
elif platform == "win32":
94+
candidates = glob.glob(os.path.join(cwd, env_path + ".exe"))
95+
if len(candidates) == 0:
96+
candidates = glob.glob(env_path + ".exe")
97+
if len(candidates) > 0:
98+
launch_string = candidates[0]
99+
return launch_string
100+
# TODO: END REMOVE
101+
41102
def __init__(
42103
self,
43-
executable_name: Optional[str] = None,
104+
worker_id=None, # TODO : REMOVE
105+
seed=None, # TODO : REMOVE
106+
docker_training=None, # TODO : REMOVE
107+
no_graphics=None, # TODO : REMOVE
108+
base_port=None, # TODO : REMOVE
109+
file_name: Optional[str] = None,
44110
args: Optional[List[str]] = None,
45111
side_channels: Optional[List[SideChannel]] = None,
46112
):
47113
"""
48114
Starts a new unity environment and establishes a connection with the environment.
49115
50-
:string executable_name: Name of Unity environment binary. If None, will try to connect to the Editor.
116+
:string file_name: Name of Unity environment binary. If None, will try to connect to the Editor.
51117
:list args: Addition Unity command line arguments
52118
:list side_channels: Additional side channel for not-rl communication with Unity
53119
"""
54120
args = args or []
55121
atexit.register(self.close)
122+
executable_name = file_name
56123

57124
if executable_name is None:
58125
assert args == []

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"description": "Add interactivity to your game with ML-Agents trained using Deep Reinforcement Learning.",
77
"dependencies": {
88
"com.unity.barracuda": "0.5.0-preview",
9-
"com.unity.entities": "0.7.0-preview.9",
10-
"com.unity.jobs": "0.2.6-preview.6",
9+
"com.unity.entities": "0.7.0-preview.19",
10+
"com.unity.jobs": "0.2.6-preview.13",
1111
"com.unity.mathematics": "1.1.0",
12-
"com.unity.collections": "0.5.3-preview.5"
12+
"com.unity.collections": "0.6.0-preview.9"
1313
},
1414
"samples": [
1515
{

0 commit comments

Comments
 (0)