浏览代码

add flake8-bugbear (#3137)

* unused loop variables

* change loop variable
/asymm-envs
GitHub 5 年前
当前提交
7fbf6b1d
共有 10 个文件被更改,包括 24 次插入19 次删除
  1. 2
      .pre-commit-config.yaml
  2. 2
      gym-unity/gym_unity/tests/test_gym.py
  3. 3
      ml-agents/mlagents/trainers/demo_loader.py
  4. 2
      ml-agents/mlagents/trainers/sac/models.py
  5. 14
      ml-agents/mlagents/trainers/tests/mock_brain.py
  6. 2
      ml-agents/mlagents/trainers/tests/test_agent_processor.py
  7. 2
      ml-agents/mlagents/trainers/tests/test_simple_rl.py
  8. 8
      ml-agents/mlagents/trainers/tests/test_trajectory.py
  9. 6
      ml-agents/mlagents/trainers/trainer_controller.py
  10. 2
      setup.cfg

2
.pre-commit-config.yaml


.*_pb2_grpc.py
)$
# flake8-tidy-imports is used for banned-modules, not actually tidying
additional_dependencies: [flake8-comprehensions, flake8-tidy-imports]
additional_dependencies: [flake8-comprehensions, flake8-tidy-imports, flake8-bugbear]
- id: trailing-whitespace
name: trailing-whitespace-markdown
types: [markdown]

2
gym-unity/gym_unity/tests/test_gym.py


else:
vector_action_space_size = tuple(vector_action_space_size)
obs_shapes = [(vector_observation_space_size,)]
for i in range(number_visual_observations):
for _ in range(number_visual_observations):
obs_shapes += [(8, 8, 3)]
return AgentGroupSpec(obs_shapes, act_type, vector_action_space_size)

3
ml-agents/mlagents/trainers/demo_loader.py


# Create and populate buffer using experiences
demo_raw_buffer = AgentBuffer()
demo_processed_buffer = AgentBuffer()
for idx, experience in enumerate(pair_infos):
for idx, current_pair_info in enumerate(pair_infos):
current_pair_info = pair_infos[idx]
next_pair_info = pair_infos[idx + 1]
current_brain_info = BrainInfo.from_agent_proto(
0, [current_pair_info.agent_info], brain_params

2
ml-agents/mlagents/trainers/sac/models.py


self.rewards_holders = {}
self.min_policy_qs = {}
for i, name in enumerate(stream_names):
for name in stream_names:
if discrete:
_branched_mpq1 = self.apply_as_branches(
self.policy_network.q1_pheads[name]

14
ml-agents/mlagents/trainers/tests/mock_brain.py


def simulate_rollout(env, policy, buffer_init_samples, exclude_key_list=None):
brain_info_list = []
for i in range(buffer_init_samples):
for _ in range(buffer_init_samples):
brain_info_list.append(env.step()[env.external_brain_names[0]])
buffer = create_buffer(brain_info_list, policy.brain, policy.sequence_length)
# If a key_list was given, remove those keys

for idx, experience in enumerate(brain_infos):
if idx > len(brain_infos) - 2:
break
current_brain_info = brain_infos[idx]
current_brain_info = experience
next_brain_info = brain_infos[idx + 1]
buffer.last_brain_info = current_brain_info
buffer["done"].append(next_brain_info.local_done[0])

use_discrete,
use_visual,
num_agents=12,
discrete_action_space=[3, 3, 3, 2],
vector_action_space=[2],
discrete_action_space=None,
vector_action_space=None,
# defaults
discrete_action_space = (
[3, 3, 3, 2] if discrete_action_space is None else discrete_action_space
)
vector_action_space = [2] if vector_action_space is None else vector_action_space
if not use_visual:
mock_brain = create_mock_brainparams(
vector_action_space_type="discrete" if use_discrete else "continuous",

2
ml-agents/mlagents/trainers/tests/test_agent_processor.py


num_vector_acts=2,
num_vis_observations=num_vis_obs,
)
for i in range(5):
for _ in range(5):
processor.add_experiences(mock_braininfo, mock_braininfo, fake_action_outputs)
# Assert that two trajectories have been added to the Trainer

2
ml-agents/mlagents/trainers/tests/test_simple_rl.py


# Begin training
tc.start_learning(env_manager)
print(tc._get_measure_vals())
for brain_name, mean_reward in tc._get_measure_vals().items():
for mean_reward in tc._get_measure_vals().values():
assert not math.isnan(mean_reward)
assert mean_reward > success_threshold

8
ml-agents/mlagents/trainers/tests/test_trajectory.py


the trajectory is terminated by a max step rather than a done.
"""
steps_list = []
for i in range(length - 1):
for _i in range(length - 1):
for i in range(num_vis_obs):
for _j in range(num_vis_obs):
obs.append(np.ones((84, 84, 3), dtype=np.float32))
obs.append(np.ones(vec_obs_size, dtype=np.float32))
reward = 1.0

@pytest.mark.parametrize("num_vec_obs", [0, 1])
def test_split_obs(num_visual_obs, num_vec_obs):
obs = []
for i in range(num_visual_obs):
for _ in range(num_visual_obs):
for i in range(num_vec_obs):
for _ in range(num_vec_obs):
obs.append(np.ones(VEC_OBS_SIZE, dtype=np.float32))
split_observations = SplitObservations.from_observations(obs)

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


last_brain_behavior_ids = external_brain_behavior_ids
n_steps = self.advance(env_manager)
for i in range(n_steps):
for _ in range(n_steps):
global_step += 1
self.reset_env_if_ready(env_manager, global_step)
if self._should_save_model(global_step):

self._reset_env(env)
# Reward buffers reset takes place only for curriculum learning
# else no reset.
for brain_name, trainer in self.trainers.items():
for trainer in self.trainers.values():
trainer.end_episode()
for brain_name, changed in lessons_incremented.items():
if changed:

with hierarchical_timer("env_step"):
new_step_infos = env.step()
for step_info in new_step_infos:
for brain_name, trainer in self.trainers.items():
for brain_name in self.trainers.keys():
for name_behavior_id in self.brain_name_to_identifier[brain_name]:
if step_info.has_actions_for_brain(name_behavior_id):
_processor = self.managers[name_behavior_id].processor

2
setup.cfg


# or whitespace before ':'. Rather than fight with black, just ignore these for now.
W503, E203,
# flake-tidy-import adds this warning, which we don't really care about for now
I200
I200,
banned-modules = tensorflow = use mlagents.tf_utils instead (it handles tf2 compat).
正在加载...
取消
保存