Skip to content

Commit

Permalink
Initial State, Save_Rate, and Final Results
Browse files Browse the repository at this point in the history
  • Loading branch information
Vast342 committed Dec 27, 2023
1 parent 09053e1 commit bfc6c93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ games: number of games played per SPSA iteration, make sure this is a multiple o
tc: The time control the matches are going to be played at. Increment is automatically `tc / 100`.
threads: This corresponds to concurrency it cutechess, not the threads of the engine.
save_rate: The number of games between times saving the state to a file
```

3 changes: 2 additions & 1 deletion cutechess.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"games": 16,
"tc": 5,
"hash": 8,
"threads": 1
"threads": 1,
"save_rate": 10
}
3 changes: 2 additions & 1 deletion cutechess.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(
games: int = 120,
tc: float = 5.0,
hash: int = 8,
threads: int = 1
threads: int = 1,
save_rate: int = 10
):
self.engine = engine
self.book = book
Expand Down
21 changes: 20 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def main():

start_t = t

print("Initial state: ")
for param in spsa.params:
print(param)
print()
try:
while True:
start = time.time()
Expand All @@ -73,14 +77,29 @@ def main():

graph.update(spsa.t, copy.deepcopy(spsa.params))
graph.save("graph.png")

if ((spsa.t / cutechess.games) % cutechess.save_rate) == 0:
print("Saving state...")
save_state(spsa)

print(
f"iterations: {spsa.t / cutechess.games} ({(avg_time / (spsa.t / cutechess.games - start_t)):.2f}s per iter)")
print(
f"iterations: {spsa.t} ({(avg_time / (spsa.t - start_t)):.2f}s per iter)")
f"games: {spsa.t} ({(avg_time / (spsa.t - start_t)):.2f}s per game)")
for param in spsa.params:
print(param)
print()
finally:
print("Saving state...")
save_state(spsa)
print("Final results: ")
print(
f"iterations: {spsa.t / cutechess.games} ({(avg_time / (spsa.t / cutechess.games - start_t)):.2f}s per iter)")
print(
f"games: {spsa.t} ({(avg_time / (spsa.t - start_t)):.2f}s per game)")
print("Final parameters: ")
for param in spsa.params:
print(param)


if __name__ == "__main__":
Expand Down

0 comments on commit bfc6c93

Please sign in to comment.