From 1734f618c5574f198a30ba49e7dad29027859a8c Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Mon, 22 Jul 2019 14:54:53 -0700 Subject: [PATCH 1/6] discrete action coverage --- UnitySDK/ProjectSettings/ProjectVersion.txt | 3 +- .../tests/test_environments/test_simple.py | 38 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/UnitySDK/ProjectSettings/ProjectVersion.txt b/UnitySDK/ProjectSettings/ProjectVersion.txt index e05840244b..93895bd690 100755 --- a/UnitySDK/ProjectSettings/ProjectVersion.txt +++ b/UnitySDK/ProjectSettings/ProjectVersion.txt @@ -1 +1,2 @@ -m_EditorVersion: 2017.4.10f1 +m_EditorVersion: 2019.1.10f1 +m_EditorVersionWithRevision: 2019.1.10f1 (f007ed779b7a) diff --git a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py b/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py index 4a92c970a5..147dbd777b 100644 --- a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py +++ b/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py @@ -1,6 +1,8 @@ -import yaml import math +import random import tempfile +import pytest +import yaml from typing import Any, Dict @@ -30,21 +32,25 @@ class Simple1DEnvironment(BaseUnityEnvironment): it reaches -1. The position is incremented by the action amount (clamped to [-step_size, step_size]). """ - def __init__(self): + def __init__(self, use_discrete): + super().__init__() + self.discrete = use_discrete self._brains: Dict[str, BrainParameters] = {} self._brains[BRAIN_NAME] = BrainParameters( brain_name=BRAIN_NAME, vector_observation_space_size=OBS_SIZE, num_stacked_vector_observations=1, camera_resolutions=[], - vector_action_space_size=[1], + vector_action_space_size=[2] if use_discrete else [1], vector_action_descriptions=["moveDirection"], - vector_action_space_type=1, # "continuous" + vector_action_space_type=0 if use_discrete else 1, ) # state self.position = 0.0 self.step_count = 0 + self.random = random.Random(str(self._brains)) + self.goal = random.choice([-1, 1]) def step( self, @@ -55,21 +61,23 @@ def step( ) -> AllBrainInfo: assert vector_action is not None - delta = vector_action[BRAIN_NAME][0][0] + if self.discrete: + act = vector_action[BRAIN_NAME][0][0] + delta = 1 if act else -1 + else: + delta = vector_action[BRAIN_NAME][0][0] delta = clamp(delta, -STEP_SIZE, STEP_SIZE) self.position += delta self.position = clamp(self.position, -1, 1) self.step_count += 1 done = self.position >= 1.0 or self.position <= -1.0 if done: - reward = SUCCESS_REWARD * self.position + reward = SUCCESS_REWARD * self.position * self.goal else: reward = -TIME_PENALTY agent_info = AgentInfoProto( - stacked_vector_observation=[self.position] * OBS_SIZE, - reward=reward, - done=done, + stacked_vector_observation=[self.goal] * OBS_SIZE, reward=reward, done=done ) if done: @@ -84,6 +92,7 @@ def step( def _reset_agent(self): self.position = 0.0 self.step_count = 0 + self.goal = random.choice([-1, 1]) def reset( self, @@ -94,7 +103,7 @@ def reset( self._reset_agent() agent_info = AgentInfoProto( - stacked_vector_observation=[self.position] * OBS_SIZE, + stacked_vector_observation=[self.goal] * OBS_SIZE, done=False, max_step_reached=False, ) @@ -120,7 +129,7 @@ def close(self): pass -def test_simple(): +def _check_environment_trains(env): config = """ default: trainer: ppo @@ -165,7 +174,6 @@ def test_simple(): ) # Begin training - env = Simple1DEnvironment() env_manager = SimpleEnvManager(env) trainer_config = yaml.safe_load(config) tc.start_learning(env_manager, trainer_config) @@ -173,3 +181,9 @@ def test_simple(): for brain_name, mean_reward in tc._get_measure_vals().items(): assert not math.isnan(mean_reward) assert mean_reward > 0.99 + + +@pytest.mark.parametrize("use_discrete", [True, False]) +def test_simple(use_discrete): + env = Simple1DEnvironment(use_discrete=use_discrete) + _check_environment_trains(env) From 95521db94dc5f62f56cbe9118ba408a2ca9e6c16 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Mon, 22 Jul 2019 17:15:44 -0700 Subject: [PATCH 2/6] undo change --- UnitySDK/ProjectSettings/ProjectVersion.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UnitySDK/ProjectSettings/ProjectVersion.txt b/UnitySDK/ProjectSettings/ProjectVersion.txt index 93895bd690..e05840244b 100755 --- a/UnitySDK/ProjectSettings/ProjectVersion.txt +++ b/UnitySDK/ProjectSettings/ProjectVersion.txt @@ -1,2 +1 @@ -m_EditorVersion: 2019.1.10f1 -m_EditorVersionWithRevision: 2019.1.10f1 (f007ed779b7a) +m_EditorVersion: 2017.4.10f1 From 6fa27ec0af926cee416fc21b6957ab9d7aa77abb Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 26 Jul 2019 16:51:57 -0700 Subject: [PATCH 3/6] rename test --- .../mlagents/trainers/tests/test_environments/test_simple.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py b/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py index 147dbd777b..636e00b1eb 100644 --- a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py +++ b/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py @@ -184,6 +184,6 @@ def _check_environment_trains(env): @pytest.mark.parametrize("use_discrete", [True, False]) -def test_simple(use_discrete): +def test_simple_rl(use_discrete): env = Simple1DEnvironment(use_discrete=use_discrete) _check_environment_trains(env) From 2e72b2dbf9ce9163c92066036b06591dc4173e5c Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 26 Jul 2019 16:53:12 -0700 Subject: [PATCH 4/6] move test file --- ml-agents/mlagents/trainers/tests/test_environments/__init__.py | 0 .../tests/{test_environments/test_simple.py => test_simple_rl.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ml-agents/mlagents/trainers/tests/test_environments/__init__.py rename ml-agents/mlagents/trainers/tests/{test_environments/test_simple.py => test_simple_rl.py} (100%) diff --git a/ml-agents/mlagents/trainers/tests/test_environments/__init__.py b/ml-agents/mlagents/trainers/tests/test_environments/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py b/ml-agents/mlagents/trainers/tests/test_simple_rl.py similarity index 100% rename from ml-agents/mlagents/trainers/tests/test_environments/test_simple.py rename to ml-agents/mlagents/trainers/tests/test_simple_rl.py From 44cb7848ff6b71070d5b301ca635d1e90c86a337 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 26 Jul 2019 16:56:43 -0700 Subject: [PATCH 5/6] Revert "move test file" This reverts commit 2e72b2dbf9ce9163c92066036b06591dc4173e5c. --- ml-agents/mlagents/trainers/tests/test_environments/__init__.py | 0 .../tests/{test_simple_rl.py => test_environments/test_simple.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 ml-agents/mlagents/trainers/tests/test_environments/__init__.py rename ml-agents/mlagents/trainers/tests/{test_simple_rl.py => test_environments/test_simple.py} (100%) diff --git a/ml-agents/mlagents/trainers/tests/test_environments/__init__.py b/ml-agents/mlagents/trainers/tests/test_environments/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ml-agents/mlagents/trainers/tests/test_simple_rl.py b/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py similarity index 100% rename from ml-agents/mlagents/trainers/tests/test_simple_rl.py rename to ml-agents/mlagents/trainers/tests/test_environments/test_simple.py From c8300370229a0845d13dfd38f0dc66816e2605b2 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 26 Jul 2019 16:57:25 -0700 Subject: [PATCH 6/6] move files post merge --- ml-agents/mlagents/trainers/tests/test_environments/__init__.py | 0 .../tests/{test_environments/test_simple.py => test_simple_rl.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ml-agents/mlagents/trainers/tests/test_environments/__init__.py rename ml-agents/mlagents/trainers/tests/{test_environments/test_simple.py => test_simple_rl.py} (100%) diff --git a/ml-agents/mlagents/trainers/tests/test_environments/__init__.py b/ml-agents/mlagents/trainers/tests/test_environments/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ml-agents/mlagents/trainers/tests/test_environments/test_simple.py b/ml-agents/mlagents/trainers/tests/test_simple_rl.py similarity index 100% rename from ml-agents/mlagents/trainers/tests/test_environments/test_simple.py rename to ml-agents/mlagents/trainers/tests/test_simple_rl.py