From 1c8e14bf50b612af9f0a4c4fe91e19e82ffcc622 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 3 Jan 2023 15:35:00 -0500 Subject: [PATCH] Implement support for fixed nodes, fixed depth, fixed time --- Client/Client.py | 32 +++++++++++++++++++++++++------- OpenBench/config.py | 2 +- OpenBench/utils.py | 33 ++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Client/Client.py b/Client/Client.py index 747d691..df666fa 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -48,7 +48,7 @@ from itertools import combinations_with_replacement TIMEOUT_HTTP = 30 # Timeout in seconds for HTTP requests TIMEOUT_ERROR = 10 # Timeout in seconds when any errors are thrown TIMEOUT_WORKLOAD = 30 # Timeout in seconds between workload requests -CLIENT_VERSION = '3' # Client version to send to the Server +CLIENT_VERSION = '4' # Client version to send to the Server SYZYGY_WDL_PATH = None # Pathway to WDL Syzygy Tables BASE_GAMES_PER_CORE = 32 # Typical games played per-thread @@ -271,7 +271,25 @@ def run_bench(engine, outqueue): def scale_time_control(workload, nps): - # Searching for X/Y+Z time controls + # Searching for Nodes or Depth time controls ("N=", "D=") + pattern = '(?P((N))|(D))=(?P(\d+))' + results = re.search(pattern, workload['test']['timecontrol'].upper()) + + # No scaling is needed for fixed nodes or fixed depth games + if results: + mode, value = results.group('mode', 'value') + return 'tc=inf %s=%s' % ({'N' : 'nodes', 'D' : 'depth'}[mode], value) + + # Searching for MoveTime or Fixed Time Controls ("MT=") + pattern = '(?P(MT))=(?P(\d+))' + results = re.search(pattern, workload['test']['timecontrol'].upper()) + + # Scale the time based on this machine's NPS. Add a time Margin to avoid time losses. + if results: + mode, value = results.group('mode', 'value') + return 'st=%.2f timemargin=100' % (float(value) * int(workload['test']['nps']) / (1000 * nps)) + + # Searching for "X/Y+Z" time controls pattern = '(?P(\d+/)?)(?P\d*(\.\d+)?)(?P\+(\d+\.)?\d+)?' results = re.search(pattern, workload['test']['timecontrol']) moves, base, inc = results.group('moves', 'base', 'inc') @@ -280,13 +298,13 @@ def scale_time_control(workload, nps): moves = None if moves == '' else moves.rstrip('/') inc = 0.0 if inc is None else inc.lstrip('+') - # Scale the time based on this machines NPS + # Scale the time based on this machine's NPS base = float(base) * int(workload['test']['nps']) / nps inc = float(inc ) * int(workload['test']['nps']) / nps # Format the time control for cutechess - if moves is None: return '%.2f+%.2f' % (base, inc) - return '%d/%.2f+%.2f' % (int(moves), base, inc) + if moves is None: return 'tc=%.2f+%.2f' % (base, inc) + return 'tc=%d/%.2f+%.2f' % (int(moves), base, inc) def kill_cutechess(cutechess): @@ -770,8 +788,8 @@ def build_cutechess_command(arguments, workload, dev_name, base_name, nps): flags = '-repeat -recover -resign %s -draw %s ' flags += '-srand %d -variant %s -concurrency %d -games %d ' - flags += '-engine dir=Engines/ cmd=./%s proto=uci tc=%s%s name=%s ' - flags += '-engine dir=Engines/ cmd=./%s proto=uci tc=%s%s name=%s ' + flags += '-engine dir=Engines/ cmd=./%s proto=uci %s%s name=%s ' + flags += '-engine dir=Engines/ cmd=./%s proto=uci %s%s name=%s ' flags += '-openings file=Books/%s format=%s order=random plies=16 ' flags += '-pgnout PGNs/%s_vs_%s ' diff --git a/OpenBench/config.py b/OpenBench/config.py index 8a2f830..69eef9f 100644 --- a/OpenBench/config.py +++ b/OpenBench/config.py @@ -23,7 +23,7 @@ USE_CROSS_APPROVAL = False OPENBENCH_CONFIG = { # Server Client version control - 'client_version' : '3', + 'client_version' : '4', # Generic Error Messages useful to those setting up their own instance 'error' : { diff --git a/OpenBench/utils.py b/OpenBench/utils.py index 0ecd431..befec4a 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -48,18 +48,33 @@ def extractOption(options, option): def parseTimeControl(time_control): - # Searching for X/Y+Z time controls + # Display Nodes as N=, Depth as D=, MoveTime as MT= + conversion = { + 'N' : 'N', 'nodes' : 'N', + 'D' : 'D', 'depth' : 'D', + 'MT' : 'MT', 'movetime' : 'MT', + } + + # Searching for "nodes=", "depth=", and "movetime=" Time Controls + pattern = '(?P((N)|(D)|(MT)|(nodes)|(depth)|(movetime)))=(?P(\d+))' + if results := re.search(pattern, time_control.upper()): + mode, value = results.group('mode', 'value') + return '%s=%s' % (conversion[mode], value) + + # Searching for "X/Y+Z" time controls pattern = '(?P(\d+/)?)(?P\d*(\.\d+)?)(?P\+(\d+\.)?\d+)?' - results = re.search(pattern, time_control) - moves, base, inc = results.group('moves', 'base', 'inc') + if results := re.search(pattern, time_control): + moves, base, inc = results.group('moves', 'base', 'inc') - # Strip the trailing and leading symbols - moves = None if moves == '' else moves.rstrip('/') - inc = 0.0 if inc is None else inc.lstrip('+') + # Strip the trailing and leading symbols + moves = None if moves == '' else moves.rstrip('/') + inc = 0.0 if inc is None else inc.lstrip('+') - # Format the time control for cutechess - if moves is None: return '%.1f+%.2f' % (float(base), float(inc)) - return '%d/%.1f+%.2f' % (int(moves), float(base), float(inc)) + # Format the time control for cutechess + if moves is None: return '%.1f+%.2f' % (float(base), float(inc)) + return '%d/%.1f+%.2f' % (int(moves), float(base), float(inc)) + + raise Exception('Unable to parse Time Control (%s)' % (time_control)) def getPendingTests():