Skip to content

Commit 717d0f6

Browse files
committed
Generalize the EvalFile net option detection
Stockfish will use more than one net with official-stockfish/Stockfish#4915 Get all the couples "option" and "net names" from the output of the `stockfish uci` command. Raise worker version to 227 (also server side)
1 parent e9a6f05 commit 717d0f6

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

server/fishtest/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
on how frequently the main instance flushes its run cache.
2929
"""
3030

31-
WORKER_VERSION = 226
31+
WORKER_VERSION = 227
3232

3333
"""
3434
begin api_schema

worker/games.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ def github_api(repo):
231231
return repo.replace("https://github.com", "https://api.github.com/repos")
232232

233233

234-
def required_net(engine):
235-
net = None
234+
def required_nets(engine):
235+
nets = {}
236+
pattern = re.compile(r"(EvalFile\w*)\s+.*\s+(nn-[a-f0-9]{12}.nnue)")
236237
print("Obtaining EvalFile of {} ...".format(os.path.basename(engine)))
237238
try:
238239
with subprocess.Popen(
@@ -243,10 +244,10 @@ def required_net(engine):
243244
close_fds=not IS_WINDOWS,
244245
) as p:
245246
for line in iter(p.stdout.readline, ""):
246-
if "EvalFile" in line:
247-
m = re.search("nn-[a-f0-9]{12}.nnue", line)
248-
if m:
249-
net = m.group(0)
247+
match = pattern.search(line)
248+
if match:
249+
nets[match.group(1)] = match.group(2)
250+
250251
except (OSError, subprocess.SubprocessError) as e:
251252
raise WorkerException(
252253
"Unable to obtain name for required net. Error: {}".format(str(e))
@@ -257,7 +258,7 @@ def required_net(engine):
257258
"UCI exited with non-zero code {}".format(format_return_code(p.returncode))
258259
)
259260

260-
return net
261+
return nets
261262

262263

263264
def required_nets_from_source():
@@ -693,7 +694,13 @@ def setup_engine(
693694
# skip temporary the profiled build for apple silicon, see
694695
# https://stackoverflow.com/questions/71580631/how-can-i-get-code-coverage-with-clang-13-0-1-on-mac
695696
make_cmd = "build" if arch == "apple-silicon" else "profile-build"
696-
cmd = f"make -j {concurrency} {make_cmd} ARCH={arch} COMP={comp}".split()
697+
cmd = [
698+
"make",
699+
f"-j{concurrency}",
700+
f"{make_cmd}",
701+
f"ARCH={arch}",
702+
f"COMP={comp}",
703+
]
697704

698705
# append -DNNUE_EMBEDDING_OFF to existing CXXFLAGS environment variable, if any
699706
cxx = os.environ.get("CXXFLAGS", "") + " -DNNUE_EMBEDDING_OFF"
@@ -721,16 +728,11 @@ def setup_engine(
721728
if p.returncode:
722729
raise WorkerException("Executing {} failed. Error: {}".format(cmd, errors))
723730

724-
# TODO: 'make strip' works fine with the new Makefile,
725-
# 'try' should be safely dropped in the future
726-
try:
727-
subprocess.run(
728-
["make", "strip", f"COMP={comp}"],
729-
stderr=subprocess.DEVNULL,
730-
check=True,
731-
)
732-
except Exception as e:
733-
print("Exception stripping binary:\n", e, sep="", file=sys.stderr)
731+
subprocess.run(
732+
["make", "strip", f"COMP={comp}"],
733+
stderr=subprocess.DEVNULL,
734+
check=True,
735+
)
734736

735737
# We called setup_engine() because the engine was not cached.
736738
# Only another worker running in the same folder can have built the engine.
@@ -1340,17 +1342,14 @@ def parse_options(s):
13401342
file=sys.stderr,
13411343
)
13421344

1343-
# Add EvalFile with full path to cutechess options, and download the networks if missimg.
1344-
net_base = required_net(base_engine)
1345-
if net_base:
1346-
base_options = base_options + ["option.EvalFile={}".format(net_base)]
1347-
net_new = required_net(new_engine)
1348-
if net_new:
1349-
new_options = new_options + ["option.EvalFile={}".format(net_new)]
1345+
# Add EvalFile* with full path to cutechess options, and download the networks if missing.
1346+
for option, net in required_nets(base_engine).items():
1347+
base_options.append("option.{}={}".format(option, net))
1348+
establish_validated_net(remote, testing_dir, net)
13501349

1351-
for net in (net_base, net_new):
1352-
if net:
1353-
establish_validated_net(remote, testing_dir, net)
1350+
for option, net in required_nets(new_engine).items():
1351+
new_options.append("option.{}={}".format(option, net))
1352+
establish_validated_net(remote, testing_dir, net)
13541353

13551354
# PGN files output setup.
13561355
pgn_name = "results-" + worker_info["unique_key"] + ".pgn"

worker/sri.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__version": 226, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "AlzBfLw8QpQx5mQmOXedSHxcBG5v+Jw5pyW3gTeUsdDzi+23Jhf7T8gcIUGQFu0A", "games.py": "x0RFYFYsRObu/828o5qz0BBA9sAhiyiLSDJQvxFXpuqTEgZWZfN+jo5JFVUiemHX"}
1+
{"__version": 227, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "31vTijpebTtgec7U05c6RIcXrbfGN9XDnPOUxmKXjUz4FTNFEKS+PBz4tFWdkwEo", "games.py": "STN/cCkhHaV9Lntp2Dpi+DDDwKUvSp72LBTafWlCUFSb2nrOYS8RvW552k0USFTG"}

worker/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Several packages are called "expression".
5656
# So we make sure to use the locally installed one.
5757

58-
WORKER_VERSION = 226
58+
WORKER_VERSION = 227
5959
FILE_LIST = ["updater.py", "worker.py", "games.py"]
6060
HTTP_TIMEOUT = 30.0
6161
INITIAL_RETRY_TIME = 15.0

0 commit comments

Comments
 (0)