浏览代码

Testing gym with basic environment (#3725)

* Trying to build a specific environment

* forgot to replace one testPlayer

* reverting 3DBall to default

* removed the multi-agent test and replaced it with a single agent test

* forgot to add this file...
/develop/add-fire
GitHub 5 年前
当前提交
744ce3d2
共有 6 个文件被更改,包括 34 次插入23 次删除
  1. 2
      .yamato/gym-interface-test.yml
  2. 2
      .yamato/python-ll-api-test.yml
  3. 1
      .yamato/standalone-build-test.yml
  4. 27
      ml-agents/tests/yamato/scripts/run_gym.py
  5. 18
      ml-agents/tests/yamato/standalone_build_tests.py
  6. 7
      ml-agents/tests/yamato/yamato_utils.py

2
.yamato/gym-interface-test.yml


commands:
- pip install pyyaml
- python -u -m ml-agents.tests.yamato.setup_venv
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_gym.py
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_gym.py --env=Project/testPlayer-Basic
dependencies:
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }}
triggers:

2
.yamato/python-ll-api-test.yml


- python -u -m ml-agents.tests.yamato.setup_venv
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_llapi.py
dependencies:
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }}
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }} --env=Project/testPlayer
triggers:
cancel_old_ci: true
changes:

1
.yamato/standalone-build-test.yml


commands:
- pip install pyyaml
- python -u -m ml-agents.tests.yamato.standalone_build_tests
- python -u -m ml-agents.tests.yamato.standalone_build_tests --scene=Assets/ML-Agents/Examples/Basic/Scenes/Basic.unity
triggers:
cancel_old_ci: true
changes:

27
ml-agents/tests/yamato/scripts/run_gym.py


import argparse
import numpy as np
from gym_unity.envs import UnityEnv

Run the gym test using the specified environment
:param env_name: Name of the Unity environment binary to launch
"""
multi_env = UnityEnv(
env_name, worker_id=1, use_visual=False, multiagent=True, no_graphics=True
)
env = UnityEnv(env_name, worker_id=1, use_visual=False, no_graphics=True)
print(str(multi_env))
print(str(env))
initial_observations = multi_env.reset()
initial_observations = env.reset()
if len(multi_env.observation_space.shape) == 1:
if len(env.observation_space.shape) == 1:
print("Agent observations look like: \n{}".format(initial_observations[0]))
print("Agent observations look like: \n{}".format(initial_observations))
multi_env.reset()
env.reset()
actions = [
multi_env.action_space.sample()
for agent in range(multi_env.number_agents)
]
observations, rewards, dones, info = multi_env.step(actions)
episode_rewards += np.mean(rewards)
done = dones[0]
actions = env.action_space.sample()
obs, reward, done, _ = env.step(actions)
episode_rewards += reward
multi_env.close()
env.close()
if __name__ == "__main__":

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


import sys
import argparse
def main():
def main(scene_path):
returncode = run_standalone_build(base_path, verbose=True)
executable_name = None
if scene_path is not None:
executable_name = scene_path.strip(".unity")
executable_name = executable_name.split("/")[-1]
executable_name = "testPlayer-" + executable_name
returncode = run_standalone_build(
base_path, verbose=True, output_path=executable_name, scene_path=scene_path
)
if returncode == 0:
print("Test run SUCCEEDED!")

if __name__ == "__main__":
main()
parser = argparse.ArgumentParser()
parser.add_argument("--scene", default=None)
args = parser.parse_args()
main(args.scene)

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


def run_standalone_build(
base_path: str, verbose: bool = False, output_path: str = None
base_path: str,
verbose: bool = False,
output_path: str = None,
scene_path: str = None,
) -> int:
"""
Run BuildStandalonePlayerOSX test to produce a player. The location defaults to Project/testPlayer.

test_args += ["-logfile", "-"]
if output_path is not None:
test_args += ["--mlagents-build-output-path", output_path]
if scene_path is not None:
test_args += ["--mlagents-build-scene-path", scene_path]
print(f"{' '.join(test_args)} ...")
timeout = 30 * 60 # 30 minutes, just in case

正在加载...
取消
保存