Skip to content

Commit 30a5738

Browse files
authored
Merge pull request #1922 from Unity-Technologies/release-v08-slowflag
Fix '--slow' flag after environment updates
2 parents 2e945ba + 35d6706 commit 30a5738

File tree

7 files changed

+17
-23
lines changed

7 files changed

+17
-23
lines changed

ml-agents-envs/mlagents/envs/environment.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def __init__(self,
3333
seed: int = 0,
3434
docker_training: bool = False,
3535
no_graphics: bool = False,
36-
timeout_wait: int = 30,
37-
train_mode: bool = True):
36+
timeout_wait: int = 30):
3837
"""
3938
Starts a new unity environment and establishes a connection with the environment.
4039
Notice: Currently communication between Unity and Python takes place over an open socket without authentication.
@@ -56,7 +55,6 @@ def __init__(self,
5655
self._loaded = False # If true, this means the environment was successfully loaded
5756
self.proc1 = None # The process that is started. If None, no process was started
5857
self.communicator = self.get_communicator(worker_id, base_port, timeout_wait)
59-
self._train_mode = train_mode
6058

6159
# If the environment name is None, a new environment will not be launched
6260
# and the communicator will directly try to connect to an existing unity environment.
@@ -245,7 +243,7 @@ def __str__(self):
245243
for k in self._resetParameters])) + '\n' + \
246244
'\n'.join([str(self._brains[b]) for b in self._brains])
247245

248-
def reset(self, config=None, train_mode=None, custom_reset_parameters=None) -> AllBrainInfo:
246+
def reset(self, config=None, train_mode=True, custom_reset_parameters=None) -> AllBrainInfo:
249247
"""
250248
Sends a signal to reset the unity environment.
251249
:return: AllBrainInfo : A data structure corresponding to the initial reset state of the environment.
@@ -265,11 +263,6 @@ def reset(self, config=None, train_mode=None, custom_reset_parameters=None) -> A
265263
raise UnityEnvironmentException(
266264
"The parameter '{0}' is not a valid parameter.".format(k))
267265

268-
if train_mode is None:
269-
train_mode = self._train_mode
270-
else:
271-
self._train_mode = train_mode
272-
273266
if self._loaded:
274267
outputs = self.communicator.exchange(
275268
self._generate_reset_input(train_mode, config, custom_reset_parameters)

ml-agents/mlagents/trainers/learn.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def run_training(sub_id: int, run_seed: int, run_options, process_queue):
7676
docker_target_name,
7777
no_graphics,
7878
run_seed,
79-
base_port + (sub_id * num_envs),
80-
fast_simulation
79+
base_port + (sub_id * num_envs)
8180
)
8281
env = SubprocessUnityEnvironment(env_factory, num_envs)
8382
maybe_meta_curriculum = try_create_meta_curriculum(curriculum_folder, env)
@@ -87,7 +86,7 @@ def run_training(sub_id: int, run_seed: int, run_options, process_queue):
8786
save_freq, maybe_meta_curriculum,
8887
load_model, train_model,
8988
keep_checkpoints, lesson, env.external_brains,
90-
run_seed)
89+
run_seed, fast_simulation)
9190

9291
# Signal that environment has been launched.
9392
process_queue.put(True)
@@ -156,8 +155,7 @@ def create_environment_factory(
156155
docker_target_name: str,
157156
no_graphics: bool,
158157
seed: Optional[int],
159-
start_port: int,
160-
fast_simulation: bool
158+
start_port: int
161159
) -> Callable[[int], BaseUnityEnvironment]:
162160
if env_path is not None:
163161
# Strip out executable extensions if passed
@@ -191,8 +189,7 @@ def create_unity_environment(worker_id: int) -> UnityEnvironment:
191189
seed=env_seed,
192190
docker_training=docker_training,
193191
no_graphics=no_graphics,
194-
base_port=start_port,
195-
train_mode=(not fast_simulation)
192+
base_port=start_port
196193
)
197194
return create_unity_environment
198195

ml-agents/mlagents/trainers/tests/test_learn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def test_run_training(load_config, create_environment_factory, subproc_env_mock)
5151
5,
5252
0,
5353
subproc_env_mock.return_value.external_brains,
54-
0
54+
0,
55+
True
5556
)
5657

5758

ml-agents/mlagents/trainers/tests/test_trainer_controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,15 @@ def basic_trainer_controller(brain_info):
152152
keep_checkpoints=False,
153153
lesson=None,
154154
external_brains={'testbrain': brain_info},
155-
training_seed=99
155+
training_seed=99,
156+
fast_simulation=True
156157
)
157158

158159
@patch('numpy.random.seed')
159160
@patch('tensorflow.set_random_seed')
160161
def test_initialization_seed(numpy_random_seed, tensorflow_set_seed):
161162
seed = 27
162-
TrainerController('', '', '1', 1, None, True, False, False, None, {}, seed)
163+
TrainerController('', '', '1', 1, None, True, False, False, None, {}, seed, True)
163164
numpy_random_seed.assert_called_with(seed)
164165
tensorflow_set_seed.assert_called_with(seed)
165166

ml-agents/mlagents/trainers/trainer_controller.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from mlagents.envs import AllBrainInfo, BrainParameters
1616
from mlagents.envs.base_unity_environment import BaseUnityEnvironment
1717
from mlagents.envs.exception import UnityEnvironmentException
18-
from mlagents.trainers import Trainer, Policy
18+
from mlagents.trainers import Trainer
1919
from mlagents.trainers.ppo.trainer import PPOTrainer
2020
from mlagents.trainers.bc.offline_trainer import OfflineBCTrainer
2121
from mlagents.trainers.bc.online_trainer import OnlineBCTrainer
@@ -34,7 +34,8 @@ def __init__(self,
3434
keep_checkpoints: int,
3535
lesson: Optional[int],
3636
external_brains: Dict[str, BrainParameters],
37-
training_seed: int):
37+
training_seed: int,
38+
fast_simulation: bool):
3839
"""
3940
:param model_path: Path to save the model.
4041
:param summaries_dir: Folder to save training summaries.
@@ -66,6 +67,7 @@ def __init__(self,
6667
self.meta_curriculum = meta_curriculum
6768
self.seed = training_seed
6869
self.training_start_time = time()
70+
self.fast_simulation = fast_simulation
6971
np.random.seed(self.seed)
7072
tf.set_random_seed(self.seed)
7173

@@ -186,9 +188,9 @@ def _reset_env(self, env: BaseUnityEnvironment):
186188
environment.
187189
"""
188190
if self.meta_curriculum is not None:
189-
return env.reset(config=self.meta_curriculum.get_config())
191+
return env.reset(train_mode=self.fast_simulation, config=self.meta_curriculum.get_config())
190192
else:
191-
return env.reset()
193+
return env.reset(train_mode=self.fast_simulation)
192194

193195
def start_learning(self, env: BaseUnityEnvironment, trainer_config):
194196
# TODO: Should be able to start learning at different lesson numbers

0 commit comments

Comments
 (0)