浏览代码

moving launch check to static method

/asymm-envs
Alphonso Crawford 5 年前
当前提交
2c14779c
共有 2 个文件被更改,包括 39 次插入75 次删除
  1. 55
      ml-agents-envs/mlagents_envs/environment.py
  2. 59
      ml-agents/mlagents/trainers/learn.py

55
ml-agents-envs/mlagents_envs/environment.py


def get_communicator(worker_id, base_port, timeout_wait):
return RpcCommunicator(worker_id, base_port, timeout_wait)
def executable_launcher(self, file_name, docker_training, no_graphics, args):
@staticmethod
def environment_launch_check(env_path):
if not (glob.glob(env_path) or glob.glob(env_path + ".*")):
raise UnityEnvironmentException(
"Couldn't launch the {0} environment. "
"Provided filename does not match any environments.".format(env_path)
)
file_name = (
file_name.strip()
.replace(".app", "")
.replace(".exe", "")
.replace(".x86_64", "")
.replace(".x86", "")
)
true_filename = os.path.basename(os.path.normpath(file_name))
logger.debug("The true file name is {}".format(true_filename))
true_filename = os.path.basename(os.path.normpath(env_path))
candidates = glob.glob(os.path.join(cwd, file_name) + ".x86_64")
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86_64")
candidates = glob.glob(os.path.join(cwd, file_name) + ".x86")
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86")
candidates = glob.glob(file_name + ".x86_64")
candidates = glob.glob(env_path + ".x86_64")
candidates = glob.glob(file_name + ".x86")
candidates = glob.glob(env_path + ".x86")
os.path.join(
cwd, file_name + ".app", "Contents", "MacOS", true_filename
)
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", true_filename)
os.path.join(file_name + ".app", "Contents", "MacOS", true_filename)
os.path.join(env_path + ".app", "Contents", "MacOS", true_filename)
os.path.join(cwd, file_name + ".app", "Contents", "MacOS", "*")
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", "*")
os.path.join(file_name + ".app", "Contents", "MacOS", "*")
os.path.join(env_path + ".app", "Contents", "MacOS", "*")
candidates = glob.glob(os.path.join(cwd, file_name + ".exe"))
candidates = glob.glob(os.path.join(cwd, env_path + ".exe"))
candidates = glob.glob(file_name + ".exe")
candidates = glob.glob(env_path + ".exe")
return launch_string
def executable_launcher(self, file_name, docker_training, no_graphics, args):
cwd = os.getcwd()
file_name = (
file_name.strip()
.replace(".app", "")
.replace(".exe", "")
.replace(".x86_64", "")
.replace(".x86", "")
)
true_filename = os.path.basename(os.path.normpath(file_name))
logger.debug("The true file name is {}".format(true_filename))
launch_string = self.environment_launch_check(file_name)
if launch_string is None:
self._close()
raise UnityEnvironmentException(

59
ml-agents/mlagents/trainers/learn.py


env_path = "/ml-agents/{env_path}".format(env_path=env_path)
return env_path
def environment_launch_check(env_path):
if not (glob.glob(env_path) or glob.glob(env_path + ".*")):
raise UnityEnvironmentException(
"Couldn't launch the {0} environment. "
"Provided filename does not match any environments.".format(env_path)
)
cwd = os.getcwd()
launch_string = None
true_filename = os.path.basename(os.path.normpath(env_path))
if platform == "linux" or platform == "linux2":
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86_64")
if len(candidates) == 0:
candidates = glob.glob(os.path.join(cwd, env_path) + ".x86")
if len(candidates) == 0:
candidates = glob.glob(env_path + ".x86_64")
if len(candidates) == 0:
candidates = glob.glob(env_path + ".x86")
if len(candidates) > 0:
launch_string = candidates[0]
elif platform == "darwin":
candidates = glob.glob(
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", true_filename)
)
if len(candidates) == 0:
candidates = glob.glob(
os.path.join(env_path + ".app", "Contents", "MacOS", true_filename)
)
if len(candidates) == 0:
candidates = glob.glob(
os.path.join(cwd, env_path + ".app", "Contents", "MacOS", "*")
)
if len(candidates) == 0:
candidates = glob.glob(
os.path.join(env_path + ".app", "Contents", "MacOS", "*")
)
if len(candidates) > 0:
launch_string = candidates[0]
elif platform == "win32":
candidates = glob.glob(os.path.join(cwd, env_path + ".exe"))
if len(candidates) == 0:
candidates = glob.glob(env_path + ".exe")
if len(candidates) > 0:
launch_string = candidates[0]
if launch_string is None:
raise UnityEnvironmentException(
"Couldn't launch the {0} environment. "
"Provided filename does not match any environments.".format(true_filename)
)
def create_environment_factory(
env_path: Optional[str],
docker_target_name: Optional[str],

.replace(".x86_64", "")
.replace(".x86", "")
)
environment_launch_check(env_path)
launch_string = UnityEnvironment.environment_launch_check(env_path)
if launch_string is None:
raise UnityEnvironmentException(
"Couldn't launch the {0} environment. "
"Provided filename does not match any environments.".format(env_path)
)
docker_training = docker_target_name is not None
if docker_training and env_path is not None:
# Comments for future maintenance:

正在加载...
取消
保存