浏览代码

more cleanup

/tag-0.12.1.dev0
Chris Elion 5 年前
当前提交
f5e6b0ed
共有 24 个文件被更改,包括 62 次插入59 次删除
  1. 6
      docs/Basic-Guide.md
  2. 6
      docs/Learning-Environment-Executable.md
  3. 4
      docs/Python-API.md
  4. 2
      docs/Training-on-Amazon-Web-Service.md
  5. 2
      ml-agents-envs/README.md
  6. 2
      ml-agents-envs/mlagents_envs/communicator.py
  7. 2
      ml-agents-envs/mlagents_envs/environment.py
  8. 2
      ml-agents-envs/mlagents_envs/exception.py
  9. 2
      ml-agents-envs/mlagents_envs/rpc_communicator.py
  10. 2
      ml-agents-envs/mlagents_envs/rpc_utils.py
  11. 18
      ml-agents-envs/mlagents_envs/tests/test_envs.py
  12. 2
      ml-agents-envs/mlagents_envs/tests/test_timers.py
  13. 7
      ml-agents-envs/setup.py
  14. 2
      ml-agents/README.md
  15. 2
      ml-agents/mlagents/trainers/brain.py
  16. 4
      ml-agents/mlagents/trainers/learn.py
  17. 2
      ml-agents/mlagents/trainers/subprocess_env_manager.py
  18. 12
      ml-agents/mlagents/trainers/tests/test_bcmodule.py
  19. 10
      ml-agents/mlagents/trainers/tests/test_ppo.py
  20. 16
      ml-agents/mlagents/trainers/tests/test_reward_signals.py
  21. 10
      ml-agents/mlagents/trainers/tests/test_sac.py
  22. 2
      ml-agents/mlagents/trainers/trainer.py
  23. 2
      ml-agents/mlagents/trainers/trainer_controller.py
  24. 2
      utils/validate_versions.py

6
docs/Basic-Guide.md


like this:
```console
INFO:mlagents.envs:
INFO:mlagents_envs:
INFO:mlagents.envs:Connected new brain:
INFO:mlagents_envs:Connected new brain:
Unity brain name: 3DBallLearning
Number of Visual Observations (per agent): 0
Vector Observation space size (per agent): 8

Vector Action descriptions: ,
INFO:mlagents.envs:Hyperparameters for the PPO Trainer of brain 3DBallLearning:
INFO:mlagents_envs:Hyperparameters for the PPO Trainer of brain 3DBallLearning:
batch_size: 64
beta: 0.001
buffer_size: 12000

6
docs/Learning-Environment-Executable.md


CrashReporter: initialized
Mono path[0] = '/Users/dericp/workspace/ml-agents/3DBall.app/Contents/Resources/Data/Managed'
Mono config path = '/Users/dericp/workspace/ml-agents/3DBall.app/Contents/MonoBleedingEdge/etc'
INFO:mlagents.envs:
INFO:mlagents_envs:
INFO:mlagents.envs:Connected new brain:
INFO:mlagents_envs:Connected new brain:
Unity brain name: Ball3DLearning
Number of Visual Observations (per agent): 0
Vector Observation space size (per agent): 8

Vector Action descriptions: ,
INFO:mlagents.envs:Hyperparameters for the PPO Trainer of brain Ball3DLearning:
INFO:mlagents_envs:Hyperparameters for the PPO Trainer of brain Ball3DLearning:
batch_size: 64
beta: 0.001
buffer_size: 12000

4
docs/Python-API.md


# Unity ML-Agents Python Low Level API
The `mlagents` Python package contains two components: a low level API which
allows you to interact directly with a Unity Environment (`mlagents.envs`) and
allows you to interact directly with a Unity Environment (`mlagents_envs`) and
an entry point to train (`mlagents-learn`) which allows you to train agents in
Unity Environments using our implementations of reinforcement learning or
imitation learning.

## mlagents.envs
## mlagents_envs
The ML-Agents Toolkit Low Level API is a Python API for controlling the simulation
loop of an environment or game built with Unity. This API is used by the

2
docs/Training-on-Amazon-Web-Service.md


File "/home/ubuntu/ml-agents/ml-agents/mlagents/envs/environment.py", line 489, in send_academy_parameters
return self.communicator.initialize(inputs).rl_initialization_output
File "/home/ubuntu/ml-agents/ml-agents/mlagents/envs/rpc_communicator.py", line 60, in initialize
mlagents.envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
The environment does not need user interaction to launch
The environment and the Python interface have compatible versions.
```

2
ml-agents-envs/README.md


The `mlagents_envs` Python package contains one sub package:
* `mlagents.envs`: A low level API which allows you to interact directly with a
* `mlagents_envs`: A low level API which allows you to interact directly with a
Unity Environment. See
[here](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Python-API.md)
for more information on using this package.

2
ml-agents-envs/mlagents_envs/communicator.py


from mlagents_envs.communicator_objects.unity_output_pb2 import UnityOutputProto
from mlagents_envs.communicator_objects.unity_input_pb2 import UnityInputProto
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents_envs")
class Communicator(object):

2
ml-agents-envs/mlagents_envs/environment.py


import struct
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents_envs")
class UnityEnvironment(BaseEnv):

2
ml-agents-envs/mlagents_envs/exception.py


import logging
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents_envs")
class UnityException(Exception):

2
ml-agents-envs/mlagents_envs/rpc_communicator.py


from mlagents_envs.communicator_objects.unity_output_pb2 import UnityOutputProto
from .exception import UnityTimeOutException, UnityWorkerInUseException
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents_envs")
class UnityToExternalServicerImplementation(UnityToExternalProtoServicer):

2
ml-agents-envs/mlagents_envs/rpc_utils.py


from typing import cast, List, Tuple, Union, Collection
from PIL import Image
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents_envs")
def agent_group_spec_from_proto(

18
ml-agents-envs/mlagents_envs/tests/test_envs.py


from mlagents_envs.mock_communicator import MockCommunicator
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_initialization(mock_communicator, mock_launcher):
mock_communicator.return_value = MockCommunicator(
discrete_action=False, visual_inputs=0

env.close()
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_reset(mock_communicator, mock_launcher):
mock_communicator.return_value = MockCommunicator(
discrete_action=False, visual_inputs=0

assert (n_agents,) + shape == obs.shape
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_step(mock_communicator, mock_launcher):
mock_communicator.return_value = MockCommunicator(
discrete_action=False, visual_inputs=0

assert batched_step_result.done[2]
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_close(mock_communicator, mock_launcher):
comm = MockCommunicator(discrete_action=False, visual_inputs=0)
mock_communicator.return_value = comm

2
ml-agents-envs/mlagents_envs/tests/test_timers.py


def test_timers() -> None:
with mock.patch(
"mlagents.envs.timers._global_timer_stack", new_callable=timers.TimerStack
"mlagents_envs.timers._global_timer_stack", new_callable=timers.TimerStack
) as test_timer:
# First, run some simple code
with timers.hierarchical_timer("top_level"):

7
ml-agents-envs/setup.py


from setuptools.command.install import install
import mlagents_envs
VERSION = mlagents.envs.__version__
VERSION = mlagents_envs.__version__
here = os.path.abspath(os.path.dirname(__file__))

"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
packages=["mlagents.envs", "mlagents.envs.communicator_objects"], # Required
packages=[
"mlagents_envs",
"mlagents_envs.communicator_objects",
], # Required # TODO SIDE CHANNELS
zip_safe=False,
install_requires=[
"cloudpickle",

2
ml-agents/README.md


The `mlagents` Python package contains two sub packages:
* `mlagents.envs`: A low level API which allows you to interact directly with a
* `mlagents_envs`: A low level API which allows you to interact directly with a
Unity Environment. See
[here](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Python-API.md)
for more information on using this package.

2
ml-agents/mlagents/trainers/brain.py


from typing import Dict, List, NamedTuple, Collection
from PIL import Image
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents.trainers")
class CameraResolution(NamedTuple):

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


# pylint: disable=no-member
return f""" Version information:
ml-agents: {mlagents.trainers.__version__},
ml-agents-envs: {mlagents.envs.__version__},
ml-agents-envs: {mlagents_envs.__version__},
Communicator API: {UnityEnvironment.API_VERSION},
TensorFlow: {tf_utils.tf.__version__}"""

print(get_version_string())
options = parse_command_line()
trainer_logger = logging.getLogger("mlagents.trainers")
env_logger = logging.getLogger("mlagents.envs")
env_logger = logging.getLogger("mlagents_envs")
trainer_logger.info(options)
if options.debug:
trainer_logger.setLevel("DEBUG")

2
ml-agents/mlagents/trainers/subprocess_env_manager.py


group_spec_to_brain_parameters,
)
logger = logging.getLogger("mlagents.envs")
logger = logging.getLogger("mlagents.trainers")
class EnvironmentCommand(NamedTuple):

12
ml-agents/mlagents/trainers/tests/test_bcmodule.py


# Test default values
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_defaults(mock_env):
# See if default values match
mock_brain = mb.create_mock_3dball_brain()

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_update(mock_env, trainer_config):
mock_brain = mb.create_mock_3dball_brain()
env, policy = create_policy_with_bc_mock(

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_constant_lr_update(mock_env, trainer_config):
mock_brain = mb.create_mock_3dball_brain()
trainer_config["behavioral_cloning"]["steps"] = 0

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_rnn_update(mock_env, trainer_config):
mock_brain = mb.create_mock_3dball_brain()
env, policy = create_policy_with_bc_mock(

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_dc_visual_update(mock_env, trainer_config):
mock_brain = mb.create_mock_banana_brain()
env, policy = create_policy_with_bc_mock(

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_bcmodule_rnn_dc_update(mock_env, trainer_config):
mock_brain = mb.create_mock_banana_brain()
env, policy = create_policy_with_bc_mock(

10
ml-agents/mlagents/trainers/tests/test_ppo.py


NUM_AGENTS = 12
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_ppo_policy_evaluate(mock_communicator, mock_launcher, dummy_config):
tf.reset_default_graph()
mock_communicator.return_value = MockCommunicator(

env.close()
@mock.patch("mlagents.envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents.envs.environment.UnityEnvironment.get_communicator")
@mock.patch("mlagents_envs.environment.UnityEnvironment.executable_launcher")
@mock.patch("mlagents_envs.environment.UnityEnvironment.get_communicator")
def test_ppo_get_value_estimates(mock_communicator, mock_launcher, dummy_config):
tf.reset_default_graph()
mock_communicator.return_value = MockCommunicator(

assert trainer.step == 10
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
@pytest.mark.parametrize("use_discrete", [True, False])
def test_trainer_update_policy(mock_env, dummy_config, use_discrete):
env, mock_brain, _ = mb.setup_mock_env_and_brains(

16
ml-agents/mlagents/trainers/tests/test_reward_signals.py


@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_gail_cc(mock_env, trainer_config, gail_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, gail_dummy_config, False, False, False

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_gail_dc_visual(mock_env, trainer_config, gail_dummy_config):
gail_dummy_config["gail"]["demo_path"] = (
os.path.dirname(os.path.abspath(__file__)) + "/testdcvis.demo"

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_gail_rnn(mock_env, trainer_config, gail_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, gail_dummy_config, True, False, False

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_curiosity_cc(mock_env, trainer_config, curiosity_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, curiosity_dummy_config, False, False, False

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_curiosity_dc(mock_env, trainer_config, curiosity_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, curiosity_dummy_config, False, True, False

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_curiosity_visual(mock_env, trainer_config, curiosity_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, curiosity_dummy_config, False, False, True

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_curiosity_rnn(mock_env, trainer_config, curiosity_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, curiosity_dummy_config, True, False, False

@pytest.mark.parametrize(
"trainer_config", [ppo_dummy_config(), sac_dummy_config()], ids=["ppo", "sac"]
)
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_extrinsic(mock_env, trainer_config, curiosity_dummy_config):
env, policy = create_policy_mock(
mock_env, trainer_config, curiosity_dummy_config, False, False, False

10
ml-agents/mlagents/trainers/tests/test_sac.py


return env, policy
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_sac_cc_policy(mock_env, dummy_config):
# Test evaluate
tf.reset_default_graph()

@pytest.mark.parametrize("discrete", [True, False], ids=["discrete", "continuous"])
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_sac_update_reward_signals(mock_env, dummy_config, discrete):
# Test evaluate
tf.reset_default_graph()

env.close()
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_sac_dc_policy(mock_env, dummy_config):
# Test evaluate
tf.reset_default_graph()

env.close()
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_sac_visual_policy(mock_env, dummy_config):
# Test evaluate
tf.reset_default_graph()

assert type(run_out) is dict
@mock.patch("mlagents.envs.environment.UnityEnvironment")
@mock.patch("mlagents_envs.environment.UnityEnvironment")
def test_sac_rnn_policy(mock_env, dummy_config):
# Test evaluate
tf.reset_default_graph()

2
ml-agents/mlagents/trainers/trainer.py


class Trainer(object):
"""This class is the base class for the mlagents.envs.trainers"""
"""This class is the base class for the mlagents_envs.trainers"""
def __init__(
self,

2
ml-agents/mlagents/trainers/trainer_controller.py


self.trainer_factory = trainer_factory
self.model_path = model_path
self.summaries_dir = summaries_dir
self.logger = logging.getLogger("mlagents.envs")
self.logger = logging.getLogger("mlagents.trainers")
self.run_id = run_id
self.save_freq = save_freq
self.train_model = train

2
utils/validate_versions.py


DIRECTORIES = [
"ml-agents/mlagents/trainers",
"ml-agents-envs/mlagents/envs",
"ml-agents-envs/mlagents_envs",
"gym-unity/gym_unity",
]

正在加载...
取消
保存