浏览代码

Merge branch 'soccer-2v1' into asymm-envs

/asymm-envs
Andrew Cohen 5 年前
当前提交
4bc36520
共有 10 个文件被更改,包括 728 次插入506 次删除
  1. 1001
      Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos.nn
  2. 1
      ml-agents/mlagents/trainers/ghost/trainer.py
  3. 14
      ml-agents/tests/yamato/yamato_utils.py
  4. 32
      .yamato/gym-interface-test.yml
  5. 32
      .yamato/python-ll-api-test.yml
  6. 21
      ml-agents/tests/yamato/setup_venv.py
  7. 48
      ml-agents/tests/yamato/scripts/run_gym.py
  8. 85
      ml-agents/tests/yamato/scripts/run_llapi.py
  9. 0
      /ml-agents/tests/yamato/scripts/__init__.py

1001
Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos.nn
文件差异内容过多而无法显示
查看文件

1
ml-agents/mlagents/trainers/ghost/trainer.py


parsed_behavior_id = self._name_to_parsed_behavior_id[
trajectory_queue.behavior_id
]
if parsed_behavior_id.team_id == self._learning_team:
# With a future multiagent trainer, this will be indexed by 'role'
internal_trajectory_queue = self._internal_trajectory_queues[

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


import os
import subprocess
import yaml
from typing import List, Optional
def get_unity_executable_path():

return res.returncode
def init_venv(mlagents_python_version: str = None) -> str:
def init_venv(
mlagents_python_version: str = None, extra_packages: Optional[List[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 mlagents_python_version:
# install from pypi
pip_commands.append(f"mlagents=={mlagents_python_version}")
pip_commands += [
f"mlagents=={mlagents_python_version}",
f"gym-unity=={mlagents_python_version}",
]
pip_commands += ["-e ./ml-agents-envs", "-e ./ml-agents"]
pip_commands += ["-e ./ml-agents-envs", "-e ./ml-agents", "-e ./gym-unity"]
if extra_packages:
pip_commands += extra_packages
for cmd in pip_commands:
subprocess.check_call(
f"source {venv_path}/bin/activate; python -m pip install -q {cmd}",

32
.yamato/gym-interface-test.yml


test_editors:
- version: 2019.3
---
{% for editor in test_editors %}
test_gym_interface_{{ editor.version }}:
name: Test Mac Gym Interface {{ 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.setup_venv
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_gym.py
dependencies:
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }}
triggers:
cancel_old_ci: true
changes:
only:
- "com.unity.ml-agents/**"
- "Project/**"
- "ml-agents/**"
- "ml-agents-envs/**"
- ".yamato/gym-interface-test.yml"
except:
- "*.md"
- "com.unity.ml-agents/*.md"
- "com.unity.ml-agents/**/*.md"
{% endfor %}

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


test_editors:
- version: 2019.3
---
{% for editor in test_editors %}
test_mac_ll_api_{{ editor.version }}:
name: Test Mac LL-API {{ 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.setup_venv
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_llapi.py
dependencies:
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }}
triggers:
cancel_old_ci: true
changes:
only:
- "com.unity.ml-agents/**"
- "Project/**"
- "ml-agents/**"
- "ml-agents-envs/**"
- ".yamato/python-ll-api-test.yml"
except:
- "*.md"
- "com.unity.ml-agents/*.md"
- "com.unity.ml-agents/**/*.md"
{% endfor %}

21
ml-agents/tests/yamato/setup_venv.py


import argparse
from .yamato_utils import init_venv
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--mlagents-version", default=None)
parser.add_argument("--extra-packages", default=None)
args = parser.parse_args()
extra_packages = []
if args.extra_packages is not None:
extra_packages = args.extra_packages.split(",")
init_venv(
mlagents_python_version=args.mlagents_version, extra_packages=extra_packages
)
if __name__ == "__main__":
main()

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


import argparse
import numpy as np
from gym_unity.envs import UnityEnv
def main(env_name):
"""
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
)
try:
# Examine environment parameters
print(str(multi_env))
# Reset the environment
initial_observations = multi_env.reset()
if len(multi_env.observation_space.shape) == 1:
# Examine the initial vector observation
print("Agent observations look like: \n{}".format(initial_observations[0]))
for _episode in range(10):
multi_env.reset()
done = False
episode_rewards = 0
while not done:
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]
print("Total reward this episode: {}".format(episode_rewards))
finally:
multi_env.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--env", default="Project/testPlayer")
args = parser.parse_args()
main(args.env)

85
ml-agents/tests/yamato/scripts/run_llapi.py


import argparse
import numpy as np
from mlagents_envs.environment import UnityEnvironment
from mlagents_envs.side_channel.engine_configuration_channel import (
EngineConfigurationChannel,
)
def main(env_name):
"""
Run the low-level API test using the specified environment
:param env_name: Name of the Unity environment binary to launch
"""
engine_configuration_channel = EngineConfigurationChannel()
env = UnityEnvironment(
file_name=env_name,
side_channels=[engine_configuration_channel],
no_graphics=True,
args=["-logFile", "-"],
)
try:
# Reset the environment
env.reset()
# Set the default brain to work with
group_name = env.get_agent_groups()[0]
group_spec = env.get_agent_group_spec(group_name)
# Set the time scale of the engine
engine_configuration_channel.set_configuration_parameters(time_scale=3.0)
# Get the state of the agents
step_result = env.get_step_result(group_name)
# Examine the number of observations per Agent
print("Number of observations : ", len(group_spec.observation_shapes))
# Is there a visual observation ?
vis_obs = any(len(shape) == 3 for shape in group_spec.observation_shapes)
print("Is there a visual observation ?", vis_obs)
# Examine the state space for the first observation for the first agent
print("First Agent observation looks like: \n{}".format(step_result.obs[0][0]))
for _episode in range(10):
env.reset()
step_result = env.get_step_result(group_name)
done = False
episode_rewards = 0
while not done:
if group_spec.is_action_continuous():
action = np.random.randn(
step_result.n_agents(), group_spec.action_size
)
elif group_spec.is_action_discrete():
branch_size = group_spec.discrete_action_branches
action = np.column_stack(
[
np.random.randint(
0, branch_size[i], size=(step_result.n_agents())
)
for i in range(len(branch_size))
]
)
else:
# Should never happen
action = None
env.set_actions(group_name, action)
env.step()
step_result = env.get_step_result(group_name)
episode_rewards += step_result.reward[0]
done = step_result.done[0]
print("Total reward this episode: {}".format(episode_rewards))
finally:
env.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--env", default="Project/testPlayer")
args = parser.parse_args()
main(args.env)

/ml-agents/tests/yamato/lowlevel_api_tests.py → /ml-agents/tests/yamato/scripts/__init__.py

正在加载...
取消
保存