浏览代码

Run training in yamato for a few steps (#3244)

/asymm-envs
GitHub 5 年前
当前提交
e4394d2f
共有 5 个文件被更改,包括 142 次插入22 次删除
  1. 3
      .yamato/standalone-build-test.yml
  2. 25
      ml-agents/tests/yamato/standalone_build_tests.py
  3. 61
      ml-agents/tests/yamato/yamato_utils.py
  4. 28
      .yamato/training-int-tests.yml
  5. 47
      ml-agents/tests/yamato/training_int_tests.py

3
.yamato/standalone-build-test.yml


name: Test Mac Standalone {{ editor.version }}
agent:
type: Unity::VM::osx
image: ml-agents/ml-agents-bokken-mac:v0.1.3-475350
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264
- pip install pyyaml
- python -u -m ml-agents.tests.yamato.standalone_build_tests
triggers:
pull_requests:

25
ml-agents/tests/yamato/standalone_build_tests.py


import sys
import subprocess
from .yamato_utils import get_base_path, get_unity_executable_path
from .yamato_utils import get_base_path, run_standalone_build
def main():

unity_exe = get_unity_executable_path()
print(f"Starting tests via {unity_exe}")
returncode = run_standalone_build(base_path, verbose=True)
test_args = [
unity_exe,
"-projectPath",
f"{base_path}/Project",
"-logfile",
"-",
"-batchmode",
"-executeMethod",
"MLAgents.StandaloneBuildTest.BuildStandalonePlayerOSX",
]
print(f"{' '.join(test_args)} ...")
timeout = 30 * 60 # 30 minutes, just in case
res: subprocess.CompletedProcess = subprocess.run(test_args, timeout=timeout)
if res.returncode == 0:
if returncode == 0:
sys.exit(res.returncode)
sys.exit(returncode)
if __name__ == "__main__":

61
ml-agents/tests/yamato/yamato_utils.py


import os
import subprocess
import yaml
def get_unity_executable_path():

# E.g. take the full path and back out the main module main.
# But for now, this should work
return os.getcwd()
def run_standalone_build(base_path: str, verbose: bool = False) -> int:
"""
Run BuildStandalonePlayerOSX test to produce a player at UnitySDK/testPlayer
:param base_path:
:return:
"""
unity_exe = get_unity_executable_path()
print(f"Running BuildStandalonePlayerOSX via {unity_exe}")
test_args = [
unity_exe,
"-projectPath",
f"{base_path}/Project",
"-batchmode",
"-executeMethod",
"MLAgents.StandaloneBuildTest.BuildStandalonePlayerOSX",
]
if verbose:
test_args += ["-logfile", "-"]
print(f"{' '.join(test_args)} ...")
timeout = 30 * 60 # 30 minutes, just in case
res: subprocess.CompletedProcess = subprocess.run(test_args, timeout=timeout)
return res.returncode
def init_venv():
# Set up the venv and install mlagents
subprocess.check_call("python -m venv venv", shell=True)
pip_commands = [
"--upgrade pip",
"--upgrade setuptools",
# TODO build these and publish to internal pypi
"~/tensorflow_pkg/tensorflow-2.0.0-cp37-cp37m-macosx_10_14_x86_64.whl",
"-e ./ml-agents-envs",
"-e ./ml-agents",
]
for cmd in pip_commands:
subprocess.check_call(
f"source venv/bin/activate; python -m pip install -q {cmd}", shell=True
)
def override_config_file(src_path, dest_path, **kwargs):
"""
Override settings in a trainer config file. For example,
override_config_file(src_path, dest_path, max_steps=42)
will copy the config file at src_path to dest_path, but override the max_steps field to 42 for all brains.
"""
with open(src_path) as f:
configs = yaml.safe_load(f)
for config in configs.values():
config.update(**kwargs)
with open(dest_path, "w") as f:
yaml.dump(configs, f)

28
.yamato/training-int-tests.yml


test_editors:
- version: 2018.4
- version: 2019.3
---
{% for editor in test_editors %}
test_mac_training_int_{{ editor.version }}:
name: Test Mac Fast Training {{ editor.version }}
agent:
type: Unity::VM::osx
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264
flavor: b1.small
variables:
UNITY_VERSION: {{ editor.version }}
commands:
- pip install pyyaml
- python -u -m ml-agents.tests.yamato.training_int_tests
triggers:
pull_requests:
- targets:
only:
- "master"
- "/release-.*/"
- "/hotfix-.*/"
artifacts:
unit:
paths:
- "artifacts/**"
{% endfor %}

47
ml-agents/tests/yamato/training_int_tests.py


import os
import sys
import subprocess
from .yamato_utils import (
get_base_path,
run_standalone_build,
init_venv,
override_config_file,
)
def main():
nn_file_expected = "./models/ppo/3DBall.nn"
if os.path.exists(nn_file_expected):
# Should never happen - make sure nothing leftover from an old test.
print("Artifacts from previous build found!")
sys.exit(1)
base_path = get_base_path()
print(f"Running in base path {base_path}")
build_returncode = run_standalone_build(base_path)
if build_returncode != 0:
print("Standalone build FAILED!")
sys.exit(build_returncode)
init_venv()
# Copy the default training config but override the max_steps parameter
override_config_file("config/trainer_config.yaml", "override.yaml", max_steps=100)
# TODO pass scene name and exe destination to build
# TODO make sure we fail if the exe isn't found - see MLA-559
mla_learn_cmd = "mlagents-learn override.yaml --train --env=Project/testPlayer --no-graphics --env-args -logFile -" # noqa
res = subprocess.run(f"source venv/bin/activate; {mla_learn_cmd}", shell=True)
if res.returncode != 0 or not os.path.exists(nn_file_expected):
print("mlagents-learn run FAILED!")
sys.exit(1)
print("mlagents-learn run SUCCEEDED!")
sys.exit(0)
if __name__ == "__main__":
main()
正在加载...
取消
保存