Skip to content

Commit

Permalink
Generalize the EvalFile net option detection
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ppigazzini committed Feb 23, 2024
1 parent e9a6f05 commit 717d0f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion server/fishtest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
on how frequently the main instance flushes its run cache.
"""

WORKER_VERSION = 226
WORKER_VERSION = 227

"""
begin api_schema
Expand Down
55 changes: 27 additions & 28 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ def github_api(repo):
return repo.replace("https://github.com", "https://api.github.com/repos")


def required_net(engine):
net = None
def required_nets(engine):
nets = {}
pattern = re.compile(r"(EvalFile\w*)\s+.*\s+(nn-[a-f0-9]{12}.nnue)")
print("Obtaining EvalFile of {} ...".format(os.path.basename(engine)))
try:
with subprocess.Popen(
Expand All @@ -243,10 +244,10 @@ def required_net(engine):
close_fds=not IS_WINDOWS,
) as p:
for line in iter(p.stdout.readline, ""):
if "EvalFile" in line:
m = re.search("nn-[a-f0-9]{12}.nnue", line)
if m:
net = m.group(0)
match = pattern.search(line)
if match:
nets[match.group(1)] = match.group(2)

except (OSError, subprocess.SubprocessError) as e:
raise WorkerException(
"Unable to obtain name for required net. Error: {}".format(str(e))
Expand All @@ -257,7 +258,7 @@ def required_net(engine):
"UCI exited with non-zero code {}".format(format_return_code(p.returncode))
)

return net
return nets


def required_nets_from_source():
Expand Down Expand Up @@ -693,7 +694,13 @@ def setup_engine(
# skip temporary the profiled build for apple silicon, see
# https://stackoverflow.com/questions/71580631/how-can-i-get-code-coverage-with-clang-13-0-1-on-mac
make_cmd = "build" if arch == "apple-silicon" else "profile-build"
cmd = f"make -j {concurrency} {make_cmd} ARCH={arch} COMP={comp}".split()
cmd = [
"make",
f"-j{concurrency}",
f"{make_cmd}",
f"ARCH={arch}",
f"COMP={comp}",
]

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

# TODO: 'make strip' works fine with the new Makefile,
# 'try' should be safely dropped in the future
try:
subprocess.run(
["make", "strip", f"COMP={comp}"],
stderr=subprocess.DEVNULL,
check=True,
)
except Exception as e:
print("Exception stripping binary:\n", e, sep="", file=sys.stderr)
subprocess.run(
["make", "strip", f"COMP={comp}"],
stderr=subprocess.DEVNULL,
check=True,
)

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

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

for net in (net_base, net_new):
if net:
establish_validated_net(remote, testing_dir, net)
for option, net in required_nets(new_engine).items():
new_options.append("option.{}={}".format(option, net))
establish_validated_net(remote, testing_dir, net)

# PGN files output setup.
pgn_name = "results-" + worker_info["unique_key"] + ".pgn"
Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 226, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "AlzBfLw8QpQx5mQmOXedSHxcBG5v+Jw5pyW3gTeUsdDzi+23Jhf7T8gcIUGQFu0A", "games.py": "x0RFYFYsRObu/828o5qz0BBA9sAhiyiLSDJQvxFXpuqTEgZWZfN+jo5JFVUiemHX"}
{"__version": 227, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "31vTijpebTtgec7U05c6RIcXrbfGN9XDnPOUxmKXjUz4FTNFEKS+PBz4tFWdkwEo", "games.py": "STN/cCkhHaV9Lntp2Dpi+DDDwKUvSp72LBTafWlCUFSb2nrOYS8RvW552k0USFTG"}
2 changes: 1 addition & 1 deletion worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Several packages are called "expression".
# So we make sure to use the locally installed one.

WORKER_VERSION = 226
WORKER_VERSION = 227
FILE_LIST = ["updater.py", "worker.py", "games.py"]
HTTP_TIMEOUT = 30.0
INITIAL_RETRY_TIME = 15.0
Expand Down

0 comments on commit 717d0f6

Please sign in to comment.