Skip to content

Release 0.10.0 #2648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 69 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
835c736
Fixed small typo in documentation.
DanAmador Aug 20, 2019
2b64e45
Merge pull request #2470 from Unity-Technologies/release-0.9.2
xiaomaogy Aug 29, 2019
982f01e
Merge pull request #2451 from DanAmador/patch-1
xiaomaogy Aug 29, 2019
9cde007
Fixed typo in Training-Imitation-Learning.md (#2485)
AcelisWeaven Sep 3, 2019
4b1f1a3
python coverage: specify dirs, exclude test files (#2473)
Sep 3, 2019
fe97df8
Change update buffer to float32 instead of float64 (#2461)
Sep 3, 2019
863610b
Fix bug with construct_curr_info and test
Sep 4, 2019
77f105c
Add more tests
Sep 4, 2019
2a4724d
Add 2 visual obs test
Sep 4, 2019
5566760
Fix bug with construct_curr_info (#2490)
Sep 4, 2019
3d324db
Minor fix to link to GAIL reward signal doc (#2435)
shihzy Sep 4, 2019
d150c51
initialize trainer step count (#2498)
Sep 5, 2019
5cd2118
Add Soft Actor-Critic as trainer option (#2341)
Sep 6, 2019
784c3ef
Fix Baselines gym_unity example to work with the latest Baselines (#2…
qfettes Sep 6, 2019
5ada924
Renamed "StepInfo" to "EnvironmentStep"
Aug 19, 2019
035045e
Merge pull request #2516 from Unity-Technologies/master
Sep 9, 2019
8892581
Delete VisualBanana
Sep 9, 2019
31529b8
unit test - don't use global random generator (#2521)
Sep 9, 2019
bb82962
Merge pull request #2522 from Unity-Technologies/develop-cleanupconfig
xiaomaogy Sep 9, 2019
ec913ba
Use numpy for random sample in buffer (#2524)
Sep 10, 2019
ebe7e7c
Update the offline_bc_config path
xiaomaogy Sep 10, 2019
7deade9
Merge pull request #2526 from Unity-Technologies/develop-update-offli…
xiaomaogy Sep 10, 2019
7208853
Changing Training-RewardSignals.md --> Reward-Signals.md (#2525)
Sep 10, 2019
56ea0a8
Made the _check_environment_trains test a little more easy to pass so…
vincentpierre Sep 11, 2019
77c83cc
Fix determinism in unit test (#2530)
Sep 11, 2019
4a414cc
Reducing complexity on a number of classes. (#2480)
Sep 11, 2019
d79df88
Add a note on Custom messages about needing trainer changes (#2534)
Sep 11, 2019
27a4629
[memory] Fix for tensors not being disposed of. (#2541)
surfnerd Sep 11, 2019
a737e83
Fix run_id typing in trainer.py (#2537)
Sep 12, 2019
7fc5f54
Fixes missing camera resolution info in demos (#2523)
awjuliani Sep 12, 2019
884a662
Markdown link check in CI (#2543)
Sep 12, 2019
3d3a91c
Fix issue where SAC encoder type is always simple (#2548)
Sep 13, 2019
2107fdc
Fix crash when next_info is empty and using recurrent
Sep 13, 2019
c16eee4
Revert "Fix crash when next_info is empty and using recurrent"
Sep 13, 2019
bb479c9
[format] Format code whitespace with Unity Formatter. (#2550)
surfnerd Sep 13, 2019
0a2a095
Fix crash in construct_curr_info when next_info doesn't have any agen…
Sep 13, 2019
876d815
Add clearer message for bad permissions (#2539)
Sep 13, 2019
46f170b
[coding conventions] Change c# code to be compliant with Unity coding…
surfnerd Sep 13, 2019
602fe02
Enable learning rate decay to be disabled (#2567)
Sep 16, 2019
d1387ce
[coding conventions] Revert NNModelImporter rename and remove NonAllo…
surfnerd Sep 16, 2019
7248276
Develop allow python 3.7 (#2544)
Sep 16, 2019
92db4de
check for potentially bad env variables (#2540)
Sep 16, 2019
d98d9f9
Removed writing to UnitySDK.log from Academy/Changed UnityTimeOutExce…
andrewcoh Sep 17, 2019
102d0c5
fixed formatting
andrewcoh Sep 17, 2019
2a06b63
Develop remove academy done (#2519)
vincentpierre Sep 17, 2019
1f6492e
Normalize observations when adding experiences (#2556)
Sep 18, 2019
e594ba8
Fix flake8 import warnings (#2584)
Sep 18, 2019
b787e81
Allow mypy to reject incomplete defs for mlagents-envs (#2585)
Sep 18, 2019
88caccf
Merge pull request #2580 from Unity-Technologies/develop-removeUnityS…
andrewcoh Sep 19, 2019
e618318
Use argparse for arg parsing (#2586)
Sep 19, 2019
f3042b5
TensorFlowSharp is no more (#2590)
vincentpierre Sep 19, 2019
aa65274
Added option to use environment arguments in learn (#2594)
Sep 19, 2019
5fc2fb2
Fix issue exporting graph with multi-GPU (#2573)
Sep 19, 2019
8e580ff
Fix crash with VAIL + GAIL (#2598)
Sep 20, 2019
d5ea5af
image decompress timer (#2596)
Sep 20, 2019
97b9951
fix hang with multiple envs (#2600)
Sep 20, 2019
2e0bab8
When checking for the compatibility of the expert brain with the poli…
vincentpierre Sep 23, 2019
efc9d84
Develop yaml json loading errors (#2601)
Sep 24, 2019
98ea56a
ML-Agents Branding & Color Updates (#2583)
Hunter-Unity Sep 24, 2019
e557dab
Add note about using GPU inference for ResNet (#2607)
Sep 24, 2019
23404c0
Tick version of API and pypi packages to 10 (#2610)
Sep 24, 2019
4d3f2e5
Update project version to 2017.4.32 (#2613)
Sep 24, 2019
03453e1
Update Bouncer learning NN file (#2614)
Sep 24, 2019
6502feb
Record new demos for new envs (#2622)
Sep 25, 2019
75b149f
Update Migrating.md with note about environments (#2624)
Sep 25, 2019
62e8fb1
Remove Soccer .nn files (#2615)
Sep 26, 2019
f5b98ca
Improved SAC hyperparameters for Crawler, Walker (#2635)
Sep 27, 2019
83e3924
Fix spelling error in documentation (#2636)
Sep 27, 2019
600d94c
Fix visual hallway and visual pushblock brains and scenes. (#2645)
surfnerd Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow mypy to reject incomplete defs for mlagents-envs (#2585)
This wasn't working before because of several remaining partially defined
function definitions.
  • Loading branch information
Jonathan Harper authored Sep 18, 2019
commit b787e815a62b79ce70ee11118a999ef394b9c1c7
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ repos:
files: "ml-agents-envs/.*"
# Exclude protobuf files and don't follow them when imported
exclude: ".*_pb2.py"
# TODO get disallow-incomplete-defs working
args: [--ignore-missing-imports, --follow-imports=silent]
args: [--ignore-missing-imports, --disallow-incomplete-defs]
- id: mypy
name: mypy-gym-unity
files: "gym-unity/.*"
Expand Down
13 changes: 10 additions & 3 deletions ml-agents-envs/mlagents/envs/base_unity_environment.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
from abc import ABC, abstractmethod
from typing import Dict
from typing import Dict, Optional, Any

from mlagents.envs.brain import AllBrainInfo, BrainParameters


class BaseUnityEnvironment(ABC):
@abstractmethod
def step(
self, vector_action=None, memory=None, text_action=None, value=None
self,
vector_action: Optional[Dict] = None,
memory: Optional[Dict] = None,
text_action: Optional[Dict] = None,
value: Optional[Dict] = None,
) -> AllBrainInfo:
pass

@abstractmethod
def reset(
self, config=None, train_mode=True, custom_reset_parameters=None
self,
config: Optional[Dict] = None,
train_mode: bool = True,
custom_reset_parameters: Any = None,
) -> AllBrainInfo:
pass

Expand Down
144 changes: 77 additions & 67 deletions ml-agents-envs/mlagents/envs/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,81 @@
import numpy as np
import io

from mlagents.envs.communicator_objects.agent_info_proto_pb2 import AgentInfoProto
from mlagents.envs.communicator_objects.brain_parameters_proto_pb2 import (
BrainParametersProto,
)
from typing import Dict, List, Optional
from PIL import Image

logger = logging.getLogger("mlagents.envs")


class BrainParameters:
def __init__(
self,
brain_name: str,
vector_observation_space_size: int,
num_stacked_vector_observations: int,
camera_resolutions: List[Dict],
vector_action_space_size: List[int],
vector_action_descriptions: List[str],
vector_action_space_type: int,
):
"""
Contains all brain-specific parameters.
"""
self.brain_name = brain_name
self.vector_observation_space_size = vector_observation_space_size
self.num_stacked_vector_observations = num_stacked_vector_observations
self.number_visual_observations = len(camera_resolutions)
self.camera_resolutions = camera_resolutions
self.vector_action_space_size = vector_action_space_size
self.vector_action_descriptions = vector_action_descriptions
self.vector_action_space_type = ["discrete", "continuous"][
vector_action_space_type
]

def __str__(self):
return """Unity brain name: {}
Number of Visual Observations (per agent): {}
Vector Observation space size (per agent): {}
Number of stacked Vector Observation: {}
Vector Action space type: {}
Vector Action space size (per agent): {}
Vector Action descriptions: {}""".format(
self.brain_name,
str(self.number_visual_observations),
str(self.vector_observation_space_size),
str(self.num_stacked_vector_observations),
self.vector_action_space_type,
str(self.vector_action_space_size),
", ".join(self.vector_action_descriptions),
)

@staticmethod
def from_proto(brain_param_proto: BrainParametersProto) -> "BrainParameters":
"""
Converts brain parameter proto to BrainParameter object.
:param brain_param_proto: protobuf object.
:return: BrainParameter object.
"""
resolution = [
{"height": x.height, "width": x.width, "blackAndWhite": x.gray_scale}
for x in brain_param_proto.camera_resolutions
]
brain_params = BrainParameters(
brain_param_proto.brain_name,
brain_param_proto.vector_observation_size,
brain_param_proto.num_stacked_vector_observations,
resolution,
list(brain_param_proto.vector_action_size),
list(brain_param_proto.vector_action_descriptions),
brain_param_proto.vector_action_space_type,
)
return brain_params


class BrainInfo:
def __init__(
self,
Expand Down Expand Up @@ -101,7 +170,11 @@ def process_pixels(image_bytes: bytes, gray_scale: bool) -> np.ndarray:
return s

@staticmethod
def from_agent_proto(worker_id: int, agent_info_list, brain_params):
def from_agent_proto(
worker_id: int,
agent_info_list: List[AgentInfoProto],
brain_params: BrainParameters,
) -> "BrainInfo":
"""
Converts list of agent infos to BrainInfo.
"""
Expand Down Expand Up @@ -190,7 +263,9 @@ def safe_concat_lists(l1: Optional[List], l2: Optional[List]) -> Optional[List]:
return copy


def safe_concat_np_ndarray(a1: Optional[np.ndarray], a2: Optional[np.ndarray]):
def safe_concat_np_ndarray(
a1: Optional[np.ndarray], a2: Optional[np.ndarray]
) -> Optional[np.ndarray]:
if a1 is not None and a1.size != 0:
if a2 is not None and a2.size != 0:
return np.append(a1, a2, axis=0)
Expand All @@ -203,68 +278,3 @@ def safe_concat_np_ndarray(a1: Optional[np.ndarray], a2: Optional[np.ndarray]):

# Renaming of dictionary of brain name to BrainInfo for clarity
AllBrainInfo = Dict[str, BrainInfo]


class BrainParameters:
def __init__(
self,
brain_name: str,
vector_observation_space_size: int,
num_stacked_vector_observations: int,
camera_resolutions: List[Dict],
vector_action_space_size: List[int],
vector_action_descriptions: List[str],
vector_action_space_type: int,
):
"""
Contains all brain-specific parameters.
"""
self.brain_name = brain_name
self.vector_observation_space_size = vector_observation_space_size
self.num_stacked_vector_observations = num_stacked_vector_observations
self.number_visual_observations = len(camera_resolutions)
self.camera_resolutions = camera_resolutions
self.vector_action_space_size = vector_action_space_size
self.vector_action_descriptions = vector_action_descriptions
self.vector_action_space_type = ["discrete", "continuous"][
vector_action_space_type
]

def __str__(self):
return """Unity brain name: {}
Number of Visual Observations (per agent): {}
Vector Observation space size (per agent): {}
Number of stacked Vector Observation: {}
Vector Action space type: {}
Vector Action space size (per agent): {}
Vector Action descriptions: {}""".format(
self.brain_name,
str(self.number_visual_observations),
str(self.vector_observation_space_size),
str(self.num_stacked_vector_observations),
self.vector_action_space_type,
str(self.vector_action_space_size),
", ".join(self.vector_action_descriptions),
)

@staticmethod
def from_proto(brain_param_proto):
"""
Converts brain parameter proto to BrainParameter object.
:param brain_param_proto: protobuf object.
:return: BrainParameter object.
"""
resolution = [
{"height": x.height, "width": x.width, "blackAndWhite": x.gray_scale}
for x in brain_param_proto.camera_resolutions
]
brain_params = BrainParameters(
brain_param_proto.brain_name,
brain_param_proto.vector_observation_size,
brain_param_proto.num_stacked_vector_observations,
resolution,
list(brain_param_proto.vector_action_size),
list(brain_param_proto.vector_action_descriptions),
brain_param_proto.vector_action_space_type,
)
return brain_params
4 changes: 3 additions & 1 deletion ml-agents-envs/mlagents/envs/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def step(self) -> List[EnvironmentStep]:
pass

@abstractmethod
def reset(self, config=None, train_mode=True) -> List[EnvironmentStep]:
def reset(
self, config: Dict = None, train_mode: bool = True
) -> List[EnvironmentStep]:
pass

@property
Expand Down
32 changes: 19 additions & 13 deletions ml-agents-envs/mlagents/envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import os
import subprocess
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Any

from mlagents.envs.base_unity_environment import BaseUnityEnvironment
from mlagents.envs.timers import timed, hierarchical_timer
Expand Down Expand Up @@ -41,7 +41,7 @@
class UnityEnvironment(BaseUnityEnvironment):
SCALAR_ACTION_TYPES = (int, np.int32, np.int64, float, np.float32, np.float64)
SINGLE_BRAIN_ACTION_TYPES = SCALAR_ACTION_TYPES + (list, np.ndarray)
SINGLE_BRAIN_TEXT_TYPES = (str, list, np.ndarray)
SINGLE_BRAIN_TEXT_TYPES = list

def __init__(
self,
Expand Down Expand Up @@ -309,7 +309,10 @@ def __str__(self):
)

def reset(
self, config=None, train_mode=True, custom_reset_parameters=None
self,
config: Dict = None,
train_mode: bool = True,
custom_reset_parameters: Any = None,
) -> AllBrainInfo:
"""
Sends a signal to reset the unity environment.
Expand Down Expand Up @@ -355,11 +358,11 @@ def reset(
@timed
def step(
self,
vector_action=None,
memory=None,
text_action=None,
value=None,
custom_action=None,
vector_action: Dict[str, np.ndarray] = None,
memory: Optional[Dict[str, np.ndarray]] = None,
text_action: Optional[Dict[str, List[str]]] = None,
value: Optional[Dict[str, np.ndarray]] = None,
custom_action: Dict[str, Any] = None,
) -> AllBrainInfo:
"""
Provides the environment with an action, moves the environment dynamics forward accordingly,
Expand Down Expand Up @@ -495,8 +498,6 @@ def step(
else:
if text_action[brain_name] is None:
text_action[brain_name] = [""] * n_agent
if isinstance(text_action[brain_name], str):
text_action[brain_name] = [text_action[brain_name]] * n_agent
if brain_name not in custom_action:
custom_action[brain_name] = [None] * n_agent
else:
Expand Down Expand Up @@ -585,7 +586,7 @@ def _close(self):
self.proc1.kill()

@classmethod
def _flatten(cls, arr) -> List[float]:
def _flatten(cls, arr: Any) -> List[float]:
"""
Converts arrays to list.
:param arr: numpy vector.
Expand Down Expand Up @@ -619,7 +620,12 @@ def _get_state(self, output: UnityRLOutput) -> AllBrainInfo:

@timed
def _generate_step_input(
self, vector_action, memory, text_action, value, custom_action
self,
vector_action: Dict[str, np.ndarray],
memory: Dict[str, np.ndarray],
text_action: Dict[str, list],
value: Dict[str, np.ndarray],
custom_action: Dict[str, list],
) -> UnityInput:
rl_in = UnityRLInput()
for b in vector_action:
Expand All @@ -643,7 +649,7 @@ def _generate_step_input(
return self.wrap_unity_input(rl_in)

def _generate_reset_input(
self, training, config, custom_reset_parameters
self, training: bool, config: Dict, custom_reset_parameters: Any
) -> UnityInput:
rl_in = UnityRLInput()
rl_in.is_training = training
Expand Down
13 changes: 4 additions & 9 deletions ml-agents-envs/mlagents/envs/sampler_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def __init__(
min_value: Union[int, float],
max_value: Union[int, float],
seed: Optional[int] = None,
**kwargs
) -> None:
):
"""
:param min_value: minimum value of the range to be sampled uniformly from
:param max_value: maximum value of the range to be sampled uniformly from
Expand All @@ -49,11 +48,8 @@ class MultiRangeUniformSampler(Sampler):
"""

def __init__(
self,
intervals: List[List[Union[int, float]]],
seed: Optional[int] = None,
**kwargs
) -> None:
self, intervals: List[List[Union[int, float]]], seed: Optional[int] = None
):
"""
:param intervals: List of intervals to draw uniform samples from
:param seed: Random seed used for making uniform draws from the specified intervals
Expand Down Expand Up @@ -88,8 +84,7 @@ def __init__(
mean: Union[float, int],
st_dev: Union[float, int],
seed: Optional[int] = None,
**kwargs
) -> None:
):
"""
:param mean: Specifies the mean of the gaussian distribution to draw from
:param st_dev: Specifies the standard devation of the gaussian distribution to draw from
Expand Down
9 changes: 6 additions & 3 deletions ml-agents-envs/mlagents/envs/subprocess_env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, process: Process, worker_id: int, conn: Connection):
self.previous_all_action_info: Dict[str, ActionInfo] = {}
self.waiting = False

def send(self, name: str, payload=None):
def send(self, name: str, payload: Any = None) -> None:
try:
cmd = EnvironmentCommand(name, payload)
self.conn.send(cmd)
Expand All @@ -68,7 +68,7 @@ def close(self):

def worker(
parent_conn: Connection, step_queue: Queue, pickled_env_factory: str, worker_id: int
):
) -> None:
env_factory: Callable[[int], UnityEnvironment] = cloudpickle.loads(
pickled_env_factory
)
Expand Down Expand Up @@ -183,7 +183,10 @@ def step(self) -> List[EnvironmentStep]:
return step_infos

def reset(
self, config=None, train_mode=True, custom_reset_parameters=None
self,
config: Optional[Dict] = None,
train_mode: bool = True,
custom_reset_parameters: Any = None,
) -> List[EnvironmentStep]:
while any([ew.waiting for ew in self.env_workers]):
if not self.step_queue.empty():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from mlagents.envs.base_unity_environment import BaseUnityEnvironment


def mock_env_factory(worker_id: int):
def mock_env_factory(worker_id):
return mock.create_autospec(spec=BaseUnityEnvironment)


Expand Down
Loading