浏览代码

Test against older python and C# versions (#3689)

/develop/add-fire
GitHub 4 年前
当前提交
53ca3dc7
共有 3 个文件被更改,包括 83 次插入10 次删除
  1. 5
      .yamato/training-int-tests.yml
  2. 37
      ml-agents/tests/yamato/training_int_tests.py
  3. 51
      ml-agents/tests/yamato/yamato_utils.py

5
.yamato/training-int-tests.yml


commands:
- pip install pyyaml
- python -u -m ml-agents.tests.yamato.training_int_tests
# Backwards-compatibility tests.
# If we make a breaking change to the communication protocol, these will need
# to be disabled until the next release.
- python -u -m ml-agents.tests.yamato.training_int_tests --python=0.15.0
- python -u -m ml-agents.tests.yamato.training_int_tests --csharp=0.15.0
triggers:
cancel_old_ci: true
changes:

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


import argparse
import time
from .yamato_utils import (
get_base_path,

checkout_csharp_version,
undo_git_checkout,
def main():
nn_file_expected = "./models/ppo/3DBall.nn"
def run_training(python_version, csharp_version):
latest = "latest"
run_id = int(time.time() * 1000.0)
print(
f"Running training with python={python_version or latest} and c#={csharp_version or latest}"
)
nn_file_expected = f"./models/{run_id}/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!")

print(f"Running in base path {base_path}")
if csharp_version is not None:
checkout_csharp_version(csharp_version)
init_venv()
venv_path = init_venv(python_version)
# Copy the default training config but override the max_steps parameter,
# and reduce the batch_size and buffer_size enough to ensure an update step happens.

# 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)
mla_learn_cmd = f"mlagents-learn override.yaml --train --env=Project/testPlayer --run-id={run_id} --no-graphics --env-args -logFile -" # noqa
res = subprocess.run(
f"source {venv_path}/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(0)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--python", default=None)
parser.add_argument("--csharp", default=None)
args = parser.parse_args()
try:
run_training(args.python, args.csharp)
finally:
# Cleanup - this gets executed even if we hit sys.exit()
undo_git_checkout()
if __name__ == "__main__":

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


return res.returncode
def init_venv():
def init_venv(mlagents_python_version: str = None) -> str:
"""
Set up the virtual environment, and return the venv path.
:param mlagents_python_version: The version of mlagents python packcage to install.
If None, will do a local install, otherwise will install from pypi
:return:
"""
# Use a different venv path for different versions
venv_path = "venv"
if mlagents_python_version:
venv_path += "_" + mlagents_python_version
subprocess.check_call("python -m venv venv", shell=True)
subprocess.check_call(f"python -m venv {venv_path}", shell=True)
"-e ./ml-agents-envs",
"-e ./ml-agents",
if mlagents_python_version:
# install from pypi
pip_commands.append(f"mlagents=={mlagents_python_version}")
else:
# Local install
pip_commands += ["-e ./ml-agents-envs", "-e ./ml-agents"]
f"source venv/bin/activate; python -m pip install -q {cmd}", shell=True
f"source {venv_path}/bin/activate; python -m pip install -q {cmd}",
shell=True,
)
return venv_path
def checkout_csharp_version(csharp_version):
"""
Checks out the specific git revision (usually a tag) for the C# package and Project.
If csharp_version is None, no changes are made.
:param csharp_version:
:return:
"""
if csharp_version is None:
return
csharp_dirs = ["com.unity.ml-agents", "Project"]
for csharp_dir in csharp_dirs:
subprocess.check_call(
f"git checkout {csharp_version} -- {csharp_dir}", shell=True
def undo_git_checkout():
"""
Clean up the git working directory.
"""
subprocess.check_call("git reset HEAD .", shell=True)
subprocess.check_call("git checkout -- .", shell=True)
def override_config_file(src_path, dest_path, **kwargs):

正在加载...
取消
保存