浏览代码

Merge pull request #3438 from Unity-Technologies/develop-badEnvReturnCode

Raise Exception if path does not exist [Bug Fix]
/asymm-envs
GitHub 5 年前
当前提交
24145c22
共有 3 个文件被更改,包括 46 次插入29 次删除
  1. 48
      ml-agents-envs/mlagents_envs/environment.py
  2. 14
      ml-agents/mlagents/trainers/learn.py
  3. 13
      ml-agents/mlagents/trainers/tests/test_learn.py

48
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):
cwd = os.getcwd()
file_name = (
file_name.strip()
@staticmethod
def validate_environment_path(env_path: str) -> Optional[str]:
# Strip out executable extensions if passed
env_path = (
env_path.strip()
true_filename = os.path.basename(os.path.normpath(file_name))
true_filename = os.path.basename(os.path.normpath(env_path))
if not (glob.glob(env_path) or glob.glob(env_path + ".*")):
return None
cwd = os.getcwd()
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):
launch_string = self.validate_environment_path(file_name)
"Couldn't launch the {0} environment. "
"Provided filename does not match any environments.".format(
true_filename
)
f"Couldn't launch the {file_name} environment. Provided filename does not match any environments."
)
else:
logger.debug("This is the launch string {}".format(launch_string))

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


from mlagents.trainers.subprocess_env_manager import SubprocessEnvManager
from mlagents_envs.side_channel.side_channel import SideChannel
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfig
from mlagents_envs.exception import UnityEnvironmentException
def _create_parser():

env_args: Optional[List[str]],
) -> Callable[[int, List[SideChannel]], BaseEnv]:
if env_path is not None:
# Strip out executable extensions if passed
env_path = (
env_path.strip()
.replace(".app", "")
.replace(".exe", "")
.replace(".x86_64", "")
.replace(".x86", "")
)
launch_string = UnityEnvironment.validate_environment_path(env_path)
if launch_string is None:
raise UnityEnvironmentException(
f"Couldn't launch the {env_path} environment. Provided filename does not match any environments."
)
docker_training = docker_target_name is not None
if docker_training and env_path is not None:
# Comments for future maintenance:

13
ml-agents/mlagents/trainers/tests/test_learn.py


from mlagents.trainers import learn
from mlagents.trainers.trainer_controller import TrainerController
from mlagents.trainers.learn import parse_command_line
from mlagents_envs.exception import UnityEnvironmentException
def basic_options(extra_args=None):

mock_init.assert_called_once()
assert mock_init.call_args[0][1] == "/dockertarget/models/ppo"
assert mock_init.call_args[0][2] == "/dockertarget/summaries"
def test_bad_env_path():
with pytest.raises(UnityEnvironmentException):
learn.create_environment_factory(
env_path="/foo/bar",
docker_target_name=None,
no_graphics=True,
seed=None,
start_port=8000,
env_args=None,
)
@patch("builtins.open", new_callable=mock_open, read_data="{}")

正在加载...
取消
保存