From 692b2d0afb1fd03d8aa28faef09ba66acbac2cc1 Mon Sep 17 00:00:00 2001 From: "Shahin M. Shahin" <41402573+peregrineshahin@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:30:18 +0300 Subject: [PATCH] Read SPSA from File 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 --- worker/games.py | 35 ++++++++++++++++++++++------------- worker/sri.txt | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/worker/games.py b/worker/games.py index 64463a3c5..0f30e7b61 100644 --- a/worker/games.py +++ b/worker/games.py @@ -1150,32 +1150,41 @@ def launch_cutechess( w_params = req["w_params"] b_params = req["b_params"] + def generate_tune_options(params): + # Stochastic rounding and probability for float N.p: (N, 1-p); (N+1, p) + 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 :] ) diff --git a/worker/sri.txt b/worker/sri.txt index ee2cad5b6..3cba2942d 100644 --- a/worker/sri.txt +++ b/worker/sri.txt @@ -1 +1 @@ -{"__version": 241, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "BMuQUpxZAKF0aP6ByTZY1r06MfPoIbdG2xraTrDQQRKgvhzJo6CKmeX2P8vX/QDm", "games.py": "9dFaa914vpqT7q4LLx2LlDdYwK6QFVX3h7+XRt18ATX0lt737rvFeBIiqakkttNC"} +{"__version": 241, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "BMuQUpxZAKF0aP6ByTZY1r06MfPoIbdG2xraTrDQQRKgvhzJo6CKmeX2P8vX/QDm", "games.py": "EPw6bVCRgJT/e7COnAzV+OSUn/yXbhybzfU9oNnBxf/ommjXTByBzUMsh+V+D7Ic"}