Skip to content

Commit 10ab222

Browse files
committed
Revert "Run black"
This reverts commit c50a6e3.
1 parent d3ee0c8 commit 10ab222

File tree

111 files changed

+1138
-3264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1138
-3264
lines changed

.prepare-commit-msg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141

4242
if branch.startswith(issue_prefix):
4343
issue_number = re.match("%s(.*)" % issue_prefix, branch).group(1)
44-
print(
45-
"prepare-commit-msg: Prepending [#%s] to commit message" % issue_number
46-
)
44+
print("prepare-commit-msg: Prepending [#%s] to commit message" % issue_number)
4745

4846
with open(commit_msg_filepath, "r+") as f:
4947
content = f.read()

axelrod/evolvable_player.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class InsufficientParametersError(Exception):
99
"""Error indicating that insufficient parameters were specified to initialize an Evolvable Player."""
10-
1110
def __init__(self, *args):
1211
super().__init__(*args)
1312

@@ -50,7 +49,7 @@ def create_new(self, **kwargs):
5049
def serialize_parameters(self):
5150
"""Serialize parameters."""
5251
pickled = dumps(self.init_kwargs) # bytes
53-
s = base64.b64encode(pickled).decode("utf8") # string
52+
s = base64.b64encode(pickled).decode('utf8') # string
5453
return s
5554

5655
@classmethod

axelrod/fingerprint.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _create_points(step: float, progress_bar: bool = True) -> List[Point]:
4242
num = int((1 / step) // 1) + 1
4343

4444
if progress_bar:
45-
p_bar = tqdm.tqdm(total=num ** 2, desc="Generating points")
45+
p_bar = tqdm.tqdm(total=num**2, desc="Generating points")
4646

4747
points = []
4848
for x in np.linspace(0, 1, num):
@@ -88,8 +88,8 @@ def _create_jossann(point: Point, probe: Any) -> Player:
8888

8989
if x + y >= 1:
9090
joss_ann = DualTransformer()(
91-
JossAnnTransformer((1 - x, 1 - y))(probe_class)
92-
)(**init_kwargs)
91+
JossAnnTransformer((1 - x, 1 - y))(
92+
probe_class))(**init_kwargs)
9393
else:
9494
joss_ann = JossAnnTransformer((x, y))(probe_class)(**init_kwargs)
9595
return joss_ann
@@ -177,10 +177,7 @@ def _generate_data(interactions: dict, points: list, edges: list) -> dict:
177177
"""
178178
edge_scores = [
179179
np.mean(
180-
[
181-
compute_final_score_per_turn(scores)[0]
182-
for scores in interactions[edge]
183-
]
180+
[compute_final_score_per_turn(scores)[0] for scores in interactions[edge]]
184181
)
185182
for edge in edges
186183
]
@@ -218,9 +215,7 @@ def _reshape_data(data: dict, points: list, size: int) -> np.ndarray:
218215

219216
class AshlockFingerprint(object):
220217
def __init__(
221-
self,
222-
strategy: Union[type, Player],
223-
probe: Union[type, Player] = axl.TitForTat,
218+
self, strategy: Union[type, Player], probe: Union[type, Player] = axl.TitForTat
224219
) -> None:
225220
"""
226221
Parameters
@@ -282,7 +277,7 @@ def fingerprint(
282277
processes: int = None,
283278
filename: str = None,
284279
progress_bar: bool = True,
285-
seed: int = None,
280+
seed: int = None
286281
) -> dict:
287282
"""Build and play the spatial tournament.
288283
@@ -328,11 +323,8 @@ def fingerprint(
328323

329324
self.step = step
330325
self.spatial_tournament = axl.Tournament(
331-
tourn_players,
332-
turns=turns,
333-
repetitions=repetitions,
334-
edges=edges,
335-
seed=seed,
326+
tourn_players, turns=turns, repetitions=repetitions, edges=edges,
327+
seed=seed
336328
)
337329
self.spatial_tournament.play(
338330
build_results=False,
@@ -440,7 +432,7 @@ def fingerprint(
440432
processes: int = None,
441433
filename: str = None,
442434
progress_bar: bool = True,
443-
seed: int = None,
435+
seed: int = None
444436
) -> np.array:
445437
"""Creates a spatial tournament to run the necessary matches to obtain
446438
fingerprint data.
@@ -487,7 +479,7 @@ def fingerprint(
487479
turns=turns,
488480
noise=noise,
489481
repetitions=repetitions,
490-
seed=seed,
482+
seed=seed
491483
)
492484
tournament.play(
493485
filename=filename,
@@ -524,9 +516,7 @@ def analyse_cooperation_ratio(filename):
524516
opponent in each turn. The ith row corresponds to the ith opponent
525517
and the jth column the jth turn.
526518
"""
527-
did_c = np.vectorize(
528-
lambda actions: [int(action == "C") for action in actions]
529-
)
519+
did_c = np.vectorize(lambda actions: [int(action == "C") for action in actions])
530520

531521
cooperation_rates = {}
532522
df = dd.read_csv(filename)
@@ -535,10 +525,7 @@ def analyse_cooperation_ratio(filename):
535525
df = df[df["Player index"] == 0][["Opponent index", "Actions"]]
536526

537527
for _, row in df.iterrows():
538-
opponent_index, player_history = (
539-
row["Opponent index"],
540-
row["Actions"],
541-
)
528+
opponent_index, player_history = row["Opponent index"], row["Actions"]
542529
if opponent_index in cooperation_rates:
543530
cooperation_rates[opponent_index].append(did_c(player_history))
544531
else:
@@ -603,8 +590,7 @@ def plot(
603590

604591
if display_names:
605592
plt.yticks(
606-
range(len(self.opponents)),
607-
[str(player) for player in self.opponents],
593+
range(len(self.opponents)), [str(player) for player in self.opponents]
608594
)
609595
else:
610596
plt.yticks([0, len(self.opponents) - 1], [0, 1])

axelrod/game.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class Game(object):
1616
The numerical score attribute to all combinations of action pairs.
1717
"""
1818

19-
def __init__(
20-
self, r: Score = 3, s: Score = 0, t: Score = 5, p: Score = 1
21-
) -> None:
19+
def __init__(self, r: Score = 3, s: Score = 0, t: Score = 5, p: Score = 1) -> None:
2220
"""Create a new game object.
2321
2422
Parameters
@@ -32,12 +30,7 @@ def __init__(
3230
p: int or float
3331
Score obtained by both player for mutual defection.
3432
"""
35-
self.scores = {
36-
(C, C): (r, r),
37-
(D, D): (p, p),
38-
(C, D): (s, t),
39-
(D, C): (t, s),
40-
}
33+
self.scores = {(C, C): (r, r), (D, D): (p, p), (C, D): (s, t), (D, C): (t, s)}
4134

4235
def RPST(self) -> Tuple[Score, Score, Score, Score]:
4336
"""Returns game matrix values in Press and Dyson notation."""

axelrod/graph.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ def attached_complete_graphs(length, loops=True, directed=False):
155155
for cluster in range(2):
156156
for i in range(length):
157157
for j in range(i + 1, length):
158-
edges.append(
159-
("{}:{}".format(cluster, i), "{}:{}".format(cluster, j))
160-
)
158+
edges.append(("{}:{}".format(cluster, i),
159+
"{}:{}".format(cluster, j)))
161160
# Attach at one node
162161
edges.append(("0:0", "1:0"))
163162
graph = Graph(directed=directed, edges=edges)

axelrod/history.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ def __eq__(self, other):
8282
if isinstance(other, list):
8383
return self._plays == other
8484
elif isinstance(other, History):
85-
return (
86-
self._plays == other._plays and self._coplays == other._coplays
87-
)
85+
return self._plays == other._plays and self._coplays == other._coplays
8886
raise TypeError("Cannot compare types.")
8987

9088
def __getitem__(self, key):
@@ -123,9 +121,7 @@ def __init__(self, memory_depth, plays=None, coplays=None):
123121
def flip_plays(self):
124122
"""Creates a flipped plays history for use with DualTransformer."""
125123
flipped_plays = [action.flip() for action in self._plays]
126-
return self.__class__(
127-
self.memory_depth, plays=flipped_plays, coplays=self._coplays
128-
)
124+
return self.__class__(self.memory_depth, plays=flipped_plays, coplays=self._coplays)
129125

130126
def append(self, play, coplay):
131127
"""Appends a new (play, coplay) pair an updates metadata for

axelrod/interaction_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def compute_final_score(interactions, game=None):
3232
return None
3333

3434
final_score = tuple(
35-
sum([score[player_index] for score in scores])
36-
for player_index in [0, 1]
35+
sum([score[player_index] for score in scores]) for player_index in [0, 1]
3736
)
3837
return final_score
3938

axelrod/match.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
noise=0,
3030
match_attributes=None,
3131
reset=True,
32-
seed=None,
32+
seed=None
3333
):
3434
"""
3535
Parameters
@@ -193,8 +193,7 @@ def play(self):
193193
result = []
194194
for _ in range(turns):
195195
plays = self.simultaneous_play(
196-
self.players[0], self.players[1], self.noise
197-
)
196+
self.players[0], self.players[1], self.noise)
198197
result.append(plays)
199198

200199
if self._cache_update_required:

axelrod/match_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(
1212
prob_end=None,
1313
edges=None,
1414
match_attributes=None,
15-
seed=None,
15+
seed=None
1616
):
1717
"""
1818
A class to generate matches. This is used by the Tournament class which

axelrod/moran.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
fitness_transformation: Callable = None,
2929
mutation_method="transition",
3030
stop_on_fixation=True,
31-
seed=None,
31+
seed=None
3232
) -> None:
3333
"""
3434
An agent based Moran process class. In each round, each player plays a
@@ -93,9 +93,7 @@ def __init__(
9393
if m in ["atomic", "transition"]:
9494
self.mutation_method = m
9595
else:
96-
raise ValueError(
97-
"Invalid mutation method {}".format(mutation_method)
98-
)
96+
raise ValueError("Invalid mutation method {}".format(mutation_method))
9997
assert (mutation_rate >= 0) and (mutation_rate <= 1)
10098
assert (noise >= 0) and (noise <= 1)
10199
mode = mode.lower()
@@ -129,9 +127,7 @@ def __init__(
129127
d[str(p)] = p
130128
mutation_targets = dict()
131129
for key in sorted(keys):
132-
mutation_targets[key] = [
133-
v for (k, v) in sorted(d.items()) if k != key
134-
]
130+
mutation_targets[key] = [v for (k, v) in sorted(d.items()) if k != key]
135131
self.mutation_targets = mutation_targets
136132

137133
if interaction_graph is None:
@@ -150,18 +146,14 @@ def __init__(
150146
self.fitness_transformation = fitness_transformation
151147
# Map players to graph vertices
152148
self.locations = sorted(interaction_graph.vertices)
153-
self.index = dict(
154-
zip(sorted(interaction_graph.vertices), range(len(players)))
155-
)
149+
self.index = dict(zip(sorted(interaction_graph.vertices), range(len(players))))
156150
self.fixated = self.fixation_check()
157151

158152
def set_players(self) -> None:
159153
"""Copy the initial players into the first population, setting seeds as needed."""
160154
self.players = []
161155
for player in self.initial_players:
162-
if (self.mutation_method == "atomic") and issubclass(
163-
player.__class__, EvolvablePlayer
164-
):
156+
if (self.mutation_method == "atomic") and issubclass(player.__class__, EvolvablePlayer):
165157
# For reproducibility, we generate random seeds for evolvable players.
166158
seed = next(self._bulk_random)
167159
new_player = player.create_new(seed=seed)
@@ -171,9 +163,8 @@ def set_players(self) -> None:
171163
self.players.append(player)
172164
self.populations = [self.population_distribution()]
173165

174-
def fitness_proportionate_selection(
175-
self, scores: List, fitness_transformation: Callable = None
176-
) -> int:
166+
def fitness_proportionate_selection(self,
167+
scores: List, fitness_transformation: Callable = None) -> int:
177168
"""Randomly selects an individual proportionally to score.
178169
179170
Parameters
@@ -209,9 +200,7 @@ def mutate(self, index: int) -> Player:
209200

210201
if self.mutation_method == "atomic":
211202
if not issubclass(self.players[index].__class__, EvolvablePlayer):
212-
raise TypeError(
213-
"Player is not evolvable. Use a subclass of EvolvablePlayer."
214-
)
203+
raise TypeError("Player is not evolvable. Use a subclass of EvolvablePlayer.")
215204
return self.players[index].mutate()
216205

217206
# Assuming mutation_method == "transition"
@@ -248,9 +237,7 @@ def death(self, index: int = None) -> int:
248237
# Select locally
249238
# index is not None in this case
250239
vertex = self._random.choice(
251-
sorted(
252-
self.reproduction_graph.out_vertices(self.locations[index])
253-
)
240+
sorted(self.reproduction_graph.out_vertices(self.locations[index]))
254241
)
255242
i = self.index[vertex]
256243
return i
@@ -383,7 +370,7 @@ def score_all(self) -> List:
383370
noise=self.noise,
384371
game=self.game,
385372
deterministic_cache=self.deterministic_cache,
386-
seed=next(self._bulk_random),
373+
seed=next(self._bulk_random)
387374
)
388375
match.play()
389376
match_scores = match.final_score_per_turn()
@@ -497,11 +484,8 @@ class ApproximateMoranProcess(MoranProcess):
497484
"""
498485

499486
def __init__(
500-
self,
501-
players: List[Player],
502-
cached_outcomes: dict,
503-
mutation_rate: float = 0,
504-
seed: Optional[int] = None,
487+
self, players: List[Player], cached_outcomes: dict, mutation_rate: float = 0,
488+
seed: Optional[int] = None
505489
) -> None:
506490
"""
507491
Parameters
@@ -519,7 +503,7 @@ def __init__(
519503
noise=0,
520504
deterministic_cache=None,
521505
mutation_rate=mutation_rate,
522-
seed=seed,
506+
seed=seed
523507
)
524508
self.cached_outcomes = cached_outcomes
525509

@@ -545,9 +529,7 @@ def score_all(self) -> List:
545529
scores = [0] * N
546530
for i in range(N):
547531
for j in range(i + 1, N):
548-
player_names = tuple(
549-
[str(self.players[i]), str(self.players[j])]
550-
)
532+
player_names = tuple([str(self.players[i]), str(self.players[j])])
551533
cached_score = self._get_scores_from_cache(player_names)
552534
scores[i] += cached_score[0]
553535
scores[j] += cached_score[1]

0 commit comments

Comments
 (0)