Skip to content

Commit e6b9f54

Browse files
authored
Automatic ruff check improvements (official-stockfish#345)
1 parent e4eae8b commit e6b9f54

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

delete_bad_nets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def get_nets_by_directory(best_nets, worst_nets, num_best_to_keep=16):
5959

6060
for net_name, rating, error in itertools.chain(best_nets, worst_nets):
6161
basedir = get_net_dir(net_name)
62-
if not basedir in binned_best_nets:
62+
if basedir not in binned_best_nets:
6363
binned_best_nets[basedir] = []
64-
if not basedir in binned_worst_nets:
64+
if basedir not in binned_worst_nets:
6565
binned_worst_nets[basedir] = []
6666

6767
for net_name, rating, error in worst_nets:

do_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def do_plots(out_filename, root_dirs, elo_range, loss_range, split):
191191
epoch = row[1]
192192
elo = row[2]
193193
error = row[3]
194-
if not epoch in epochs:
194+
if epoch not in epochs:
195195
if elo > maxelo - elo_range:
196196
epochs.append(epoch)
197197
elos.append(elo)

perf_sigmoid_fitter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
import data_loader
66
import torch
7-
import sys
87

98

109
def sigmoid(x, k):

run_games.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def get_all_params(self):
5050
params += [
5151
f"option.Hash={self.hash}",
5252
f"option.Threads={self.threads}",
53-
f"timeout=20",
53+
"timeout=20",
5454
]
5555

5656
if self.nodes_per_move:
5757
params += [
58-
f"tc=10000+10000",
58+
"tc=10000+10000",
5959
f"nodes={self.nodes_per_move}",
6060
]
6161
else:

scripts/easy_train.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22

33
import time
4-
import random
54
import sys
65
import psutil
76
import re
@@ -11,7 +10,6 @@
1110
import argparse
1211
import math
1312
import logging
14-
import time
1513

1614
EXITCODE_OK = 0
1715
EXITCODE_MISSING_DEPENDENCIES = 2
@@ -184,11 +182,11 @@ def validate_pytorch():
184182
from torch import cuda
185183

186184
if cuda.is_available() and cuda.device_count() > 0:
187-
LOGGER.info(f"Found torch with CUDA. OK.")
185+
LOGGER.info("Found torch with CUDA. OK.")
188186
return True
189187
else:
190188
LOGGER.error(
191-
f"Found torch without CUDA but CUDA support required. Exiting"
189+
"Found torch without CUDA but CUDA support required. Exiting"
192190
)
193191
return False
194192
else:
@@ -269,10 +267,8 @@ def validate_environment_requirements():
269267
# Only now import the rest of the required packages
270268
from asciimatics.widgets import (
271269
Frame,
272-
ListBox,
273270
Layout,
274271
Divider,
275-
Text,
276272
Button,
277273
TextBox,
278274
Widget,
@@ -283,10 +279,8 @@ def validate_environment_requirements():
283279
)
284280
from asciimatics.scene import Scene
285281
from asciimatics.screen import Screen
286-
from asciimatics.exceptions import ResizeScreenError, NextScene, StopApplication
287-
from asciimatics.utilities import BoxTool
288-
from asciimatics.constants import SINGLE_LINE, DOUBLE_LINE
289-
from asciimatics.event import KeyboardEvent, MouseEvent
282+
from asciimatics.exceptions import ResizeScreenError, StopApplication
283+
from asciimatics.event import KeyboardEvent
290284
from threading import Thread, Lock, Event
291285
import GPUtil
292286
import io
@@ -296,8 +290,6 @@ def validate_environment_requirements():
296290
import shutil
297291
import urllib.request
298292
import urllib.parse
299-
import signal
300-
from datetime import datetime, timedelta
301293
from tqdm.auto import tqdm
302294
from pathlib import Path
303295

@@ -356,7 +348,7 @@ def terminate_process_on_exit(process):
356348
def schedule_exit(timeout_seconds, errcode):
357349
def f():
358350
time.sleep(timeout_seconds)
359-
LOGGER.info(f"Performing a scheduled exit.")
351+
LOGGER.info("Performing a scheduled exit.")
360352
if TUI_SCREEN:
361353
if sys.platform == "win32":
362354
TUI_SCREEN.close(restore=True)
@@ -1046,7 +1038,7 @@ def requests_get_content(url, *args, **kwargs):
10461038
result = requests.get(url, *args, **kwargs)
10471039
result.raise_for_status()
10481040
return result.content
1049-
except Exception as e:
1041+
except Exception:
10501042
raise Exception(f"GET request to {url} failed")
10511043

10521044

@@ -1250,7 +1242,7 @@ def setup_nnue_pytorch(directory, repo, branch_or_commit):
12501242
)
12511243

12521244
if not is_nnue_pytorch_setup(directory):
1253-
raise Exception(f"Incorrect nnue-pytorch setup or timeout.")
1245+
raise Exception("Incorrect nnue-pytorch setup or timeout.")
12541246

12551247

12561248
class CChessCliRunningTestEntry:
@@ -1429,7 +1421,7 @@ def get_status_string(self):
14291421
return "\n".join(lines)
14301422
elif self._current_convert is not None:
14311423
lines = [
1432-
f"Converting network...",
1424+
"Converting network...",
14331425
f"Run : {self._current_convert[0]}",
14341426
f"Epoch: {self._current_convert[1]}",
14351427
]
@@ -2667,7 +2659,7 @@ def main():
26672659

26682660
# Global (workspace) setup
26692661

2670-
with SystemWideMutex(os.path.join(absolute_workspace_path, f".lock")) as mutex:
2662+
with SystemWideMutex(os.path.join(absolute_workspace_path, ".lock")) as mutex:
26712663
ordo_directory = os.path.join(absolute_workspace_path, "ordo")
26722664
c_chess_cli_directory = os.path.join(absolute_workspace_path, "c-chess-cli")
26732665
books_directory = os.path.join(absolute_workspace_path, "books")
@@ -2687,13 +2679,13 @@ def main():
26872679
)
26882680
try:
26892681
os.makedirs(experiment_directory, exist_ok=False)
2690-
except FileExistsError as e:
2682+
except FileExistsError:
26912683
if args.fail_on_experiment_exists and os.listdir(experiment_directory):
26922684
LOGGER.error(
26932685
f"Directory {experiment_directory} already exists. An experiment must use a new directory."
26942686
)
26952687
LOGGER.error(
2696-
f"Alternatively, override this with the option --resume-training=True or --fail-on-experiment-exists=False."
2688+
"Alternatively, override this with the option --resume-training=True or --fail-on-experiment-exists=False."
26972689
)
26982690
return
26992691

0 commit comments

Comments
 (0)