Skip to content

Commit

Permalink
Read SPSA from File
Browse files Browse the repository at this point in the history
This is to allow for large tunes, skips dependent on cutechess and window command line restrictions for large amount of params.

Should work with https://github.com/official-stockfish/Stockfish/compare/master...Disservin:Stockfish:read-tune-from-file?expand=1
  • Loading branch information
peregrineshahin committed Apr 7, 2024
1 parent c8173d2 commit ce04003
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,32 +1080,40 @@ def launch_cutechess(
w_params = req["w_params"]
b_params = req["b_params"]

def generate_tune_options(params):
options = [
"{},{}".format(
param["name"], math.floor(param["value"] + random.uniform(0, 1))
)
for param in params
]
return ",".join(options)

# Generate option strings for white and black parameters
w_tune_options = generate_tune_options(w_params)
b_tune_options = generate_tune_options(b_params)

# Write option names and values to a file
with open("w_tune_options.csv", "w") as f:
f.write(w_tune_options)

with open("b_tune_options.csv", "w") as f:
f.write(b_tune_options)
else:
w_params = []
b_params = []

# Run cutechess-cli binary.
# Stochastic rounding and probability for float N.p: (N, 1-p); (N+1, p)
idx = cmd.index("_spsa_")
cmd = (
cmd[:idx]
+ [
"option.{}={}".format(
x["name"], math.floor(x["value"] + random.uniform(0, 1))
)
for x in w_params
]
+ (["option.TuneFile=w_tune_options.csv"] if len(w_params) != 0 else [])
+ cmd[idx + 1 :]
)
idx = cmd.index("_spsa_")
cmd = (
cmd[:idx]
+ [
"option.{}={}".format(
x["name"], math.floor(x["value"] + random.uniform(0, 1))
)
for x in b_params
]
+ (["option.TuneFile=b_tune_options.csv"] if len(b_params) != 0 else [])
+ cmd[idx + 1 :]
)

Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 232, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "DRLqEwLvuSBzNt6k3MYtlC87bp6uwdUZ/O7Xs3/d+gDox0jTOT6SO/FNWzsXVs51", "games.py": "PrNaUxAFP0wPV/jCLivA0g9mcO1vq1Og1nN3vuPa408qcKoAYuza5ZHgDCZitkQG"}
{"__version": 232, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "DRLqEwLvuSBzNt6k3MYtlC87bp6uwdUZ/O7Xs3/d+gDox0jTOT6SO/FNWzsXVs51", "games.py": "S7FQKQ2fm198OA1hO1OB9dw9YiZ/WQ+vdya7ghErxQTdvtkm20wptl1OREWr+oTX"}

0 comments on commit ce04003

Please sign in to comment.