diff --git a/Client/Client.py b/Client/Client.py index ec8f767..8f4a911 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -24,24 +24,30 @@ import argparse, ast, hashlib, json, math, multiprocessing, os import platform, re, requests, shutil, subprocess, sys, time, zipfile +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + HTTP_TIMEOUT = 30 # Timeout in seconds for requests WORKLOAD_TIMEOUT = 60 # Timeout when there is no work ERROR_TIMEOUT = 60 # Timeout when an error is thrown GAMES_PER_CONCURRENCY = 32 # Total games to play per concurrency CUSTOM_SETTINGS = { - 'ETHEREAL' : { 'args' : [] }, # Configuration for Ethereal - 'LASER' : { 'args' : [] }, # Configuration for Laser - 'WEISS' : { 'args' : [] }, # Configuration for Weiss - 'DEMOLITO' : { 'args' : [] }, # Configuration for Demolito - 'RUBICHESS' : { 'args' : [] }, # Configuration for RubiChess + 'Ethereal' : { 'args' : [] }, # Configuration for Ethereal + 'Laser' : { 'args' : [] }, # Configuration for Laser + 'Weiss' : { 'args' : [] }, # Configuration for Weiss + 'Demolito' : { 'args' : [] }, # Configuration for Demolito + 'Rubichess' : { 'args' : [] }, # Configuration for RubiChess }; +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + # Treat Windows and Linux systems differently IS_WINDOWS = platform.system() == 'Windows' IS_LINUX = platform.system() != 'Windows' +COMPILERS = {} # Mapping of Engines to Compilers + def addExtension(name): return name + ["", ".exe"][IS_WINDOWS] @@ -68,8 +74,55 @@ def killCutechess(cutechess): cutechess.wait() cutechess.stdout.close() - except Exception as error: - return + except KeyboardInterrupt: sys.exit() + except Exception as error: pass + + +def getCompilationSettings(server): + + # Get a dictionary of engine -> compilers + data = requests.get( + pathjoin(server, 'getCompilers'), + timeout=HTTP_TIMEOUT).content.decode('utf-8') + data = ast.literal_eval(data) + + for engine, compilers in data.items(): + for compiler in compilers: + + # Compilers may require a specific version + if '>=' in compiler: command, version = compiler.split('>=') + else: command = compiler; version = (0, 0, 0) + + # Try to execute the compiler from the command line + try: stdout, stderr = subprocess.Popen( + [command, '--version'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ).communicate() + except OSError: continue + + # Parse the version number reported by the compiler + stdout = stdout.decode('utf-8') + match = re.search(r'[0-9]+\.[0-9]+\.[0-9]+', stdout).group() + actual = tuple(map(int, match.split('.'))) + + # Compiler was not sufficient + if actual < version: continue + + # Compiler was sufficient + COMPILERS[engine] = { + 'command' : command, 'version' : match, + 'default' : compiler == compilers[0] + }; break + + # Report each engine configuration we can build for + for engine in [engine for engine in data.keys() if engine in COMPILERS]: + command, version = COMPILERS[engine]['command'], COMPILERS[engine]['version'] + print("Found {0} {1} for {2}".format(command, version, engine)) + + # Report each engine configuration we cannot build for + for engine in [engine for engine in data.keys() if engine not in COMPILERS]: + print("Unable to find compiler for {0}".format(engine)) def getFile(source, output): @@ -130,7 +183,6 @@ def getMachineID(): def getEngine(data, engine): - # Log the fact that we are setting up a new engine print('Engine {0}'.format(data['test']['engine'])) print('Branch {0}'.format(engine['name'])) print('Commit {0}'.format(engine['sha'])) @@ -141,18 +193,23 @@ def getEngine(data, engine): tokens = engine['source'].split('/') unzipname = '{0}-{1}'.format(tokens[-3], tokens[-1].replace('.zip', '')) getAndUnzipFile(engine['source'], '{0}.zip'.format(engine['name']), 'tmp') - pathway = pathjoin('tmp/{0}/'.format(unzipname), data['test']['path']) + pathway = pathjoin('tmp/{0}/'.format(unzipname), data['test']['build']['path']) - # Check CUSTOM_SETTINGS for a custom configuration - command = ['make', 'EXE={0}'.format(engine['name'])] - if data['test']['engine'].upper() in CUSTOM_SETTINGS: - config = CUSTOM_SETTINGS[data['test']['engine'].upper()] - command.extend(config['args']) + # Use base command and an EXE= hook + command = [data['test']['build']['command']] + command.append('EXE={0}'.format(engine['name'])) + + # Use a CC= hook if we are using the non-default compiler + if not COMPILERS[data['test']['engine']]['default']: + command.append('CC={0}'.format(COMPILERS[data['test']['engine']]['command'])) + + # Add any other custom compilation options if we have them + if data['test']['engine'] in CUSTOM_SETTINGS: + command.extend(CUSTOM_SETTINGS[data['test']['engine']]['args']) # Build the engine. If something goes wrong with the # compilation process, we will figure this out later on - subprocess.Popen(command, cwd=pathway).wait() - print("") # Leave a new line to seperate output + subprocess.Popen(command, cwd=pathway).wait(); print("") # Move the binary to the /Engines/ directory output = '{0}{1}'.format(pathway, engine['name']) @@ -436,6 +493,7 @@ def reportResults(arguments, data, wins, losses, draws, crashes, timelosses): # Hit the server with the updated test results url = pathjoin(arguments.server, 'submitResults') try: return requests.post(url, data=data, timeout=HTTP_TIMEOUT).text + except KeyboardInterrupt: sys.exit() except: print('[NOTE] Unable To Reach Server'); return "Unable" @@ -518,7 +576,6 @@ def completeWorkload(workRequestData, arguments): print('[ERROR] Invalid Login Credentials') sys.exit() - # Bad machines will be registered again if data == 'Bad Machine': workRequestData['machineid'] = 'None' @@ -565,6 +622,10 @@ def main(): # Make sure we have cutechess installed getCutechess(arguments.server) + # Determine how we will compile engines + print("\nChecking for installed Compilers",) + getCompilationSettings(arguments.server) + # Create the Engines directory if it does not exist if not os.path.isdir('Engines'): os.mkdir('Engines') @@ -572,9 +633,11 @@ def main(): # Continually pull down and complete workloads while True: try: completeWorkload(workRequestData, arguments) + except KeyboardInterrupt: sys.exit() except Exception as error: print ('[ERROR] {0}'.format(str(error))) time.sleep(ERROR_TIMEOUT) + if __name__ == '__main__': main() diff --git a/OpenBench/config.py b/OpenBench/config.py index b6c0b3b..4e7c42b 100644 --- a/OpenBench/config.py +++ b/OpenBench/config.py @@ -77,10 +77,12 @@ OPENBENCH_CONFIG = { 'engines' : { 'Ethereal' : { + 'proto' : 'uci', 'nps' : 1275000, - 'path' : '/src/', + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['gcc'] }, 'source' : 'https://github.com/AndyGrant/Ethereal', + 'testmodes' : { 'stc' : { 'threads' : 1, 'hash' : 8, 'timecontrol' : '12.0+0.12' }, 'ltc' : { 'threads' : 1, 'hash' : 64, 'timecontrol' : '60.0+0.6' }, @@ -90,10 +92,12 @@ OPENBENCH_CONFIG = { }, 'Laser' : { + 'proto' : 'uci', 'nps' : 710000, - 'path' : '/src/', + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['g++'] }, 'source' : 'https://github.com/jeffreyan11/uci-chess-engine', + 'testmodes' : { 'stc' : { 'threads' : 1, 'hash' : 8, 'timecontrol' : '10.0+0.1' }, 'ltc' : { 'threads' : 1, 'hash' : 64, 'timecontrol' : '60.0+0.6' }, @@ -103,10 +107,12 @@ OPENBENCH_CONFIG = { }, 'Weiss' : { + 'proto' : 'uci', 'nps' : 2675000, - 'path' : '/src/', + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['gcc'] }, 'source' : 'https://github.com/TerjeKir/weiss', + 'testmodes' : { 'stc' : { 'threads' : 1, 'hash' : 32, 'timecontrol' : '10.0+0.1' }, 'ltc' : { 'threads' : 1, 'hash' : 128, 'timecontrol' : '60.0+0.6' }, @@ -116,10 +122,12 @@ OPENBENCH_CONFIG = { }, 'Demolito' : { + 'proto' : 'uci', 'nps' : 1250000, - 'path' : '/src/', + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['gcc', 'clang'] }, 'source' : 'https://github.com/lucasart/Demolito', + 'testmodes' : { 'stc' : { 'threads' : 1, 'hash' : 8, 'timecontrol' : '8.0+0.08' }, 'ltc' : { 'threads' : 1, 'hash' : 32, 'timecontrol' : '32.0+0.32'}, @@ -129,10 +137,12 @@ OPENBENCH_CONFIG = { }, 'RubiChess' : { + 'proto' : 'uci', 'nps' : 1000000, - 'path' : '/src/', + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['g++'] }, 'source' : 'https://github.com/Matthies/RubiChess', + 'testmodes' : { 'stc' : { 'threads' : 1, 'hash' : 8, 'timecontrol' : '10.0+0.1' }, 'ltc' : { 'threads' : 1, 'hash' : 64, 'timecontrol' : '60.0+0.6' }, @@ -140,5 +150,20 @@ OPENBENCH_CONFIG = { 'smpltc' : { 'threads' : 8, 'hash' : 256, 'timecontrol' : '20.0+0.2' }, }, }, + + 'FabChess' : { + + 'proto' : 'uci', + 'nps' : 1000000, + 'build' : { 'path' : '/src/', 'command' : 'make', 'compilers' : ['cargo>=1.43.0'] }, + 'source' : 'https://github.com/fabianvdW/FabChess', + + 'testmodes' : { + 'stc' : { 'threads' : 1, 'hash' : 8, 'timecontrol' : '10.0+0.1' }, + 'ltc' : { 'threads' : 1, 'hash' : 64, 'timecontrol' : '60.0+0.6' }, + 'smpstc' : { 'threads' : 8, 'hash' : 64, 'timecontrol' : '5.0+0.05' }, + 'smpltc' : { 'threads' : 8, 'hash' : 256, 'timecontrol' : '20.0+0.2' }, + }, + } }, } diff --git a/OpenBench/urls.py b/OpenBench/urls.py index e2e490a..2fe7897 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -49,8 +49,9 @@ urlpatterns = [ django.urls.path(r'test//', OpenBench.views.test), django.urls.path(r'newTest/', OpenBench.views.newTest), - # Links for the Client to update the Server + # Links for the Client to work with the Server django.urls.path(r'getFiles/', OpenBench.views.getFiles), + django.urls.path(r'getCompilers/', OpenBench.views.getCompilers), django.urls.path(r'getWorkload/', OpenBench.views.getWorkload), django.urls.path(r'wrongBench/', OpenBench.views.wrongBench), django.urls.path(r'submitNPS/', OpenBench.views.submitNPS), diff --git a/OpenBench/utils.py b/OpenBench/utils.py index aa71a2d..0627d48 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -345,7 +345,7 @@ def workloadDictionary(machine, result, test): 'test' : { 'id' : test.id, 'nps' : OPENBENCH_CONFIG['engines'][test.engine]['nps'], - 'path' : OPENBENCH_CONFIG['engines'][test.engine]['path'], + 'build' : OPENBENCH_CONFIG['engines'][test.engine]['build'], 'book' : OPENBENCH_CONFIG['books'][test.bookname], 'timecontrol' : test.timecontrol, 'engine' : test.engine, diff --git a/OpenBench/views.py b/OpenBench/views.py index 01112f0..cef2f28 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -450,6 +450,15 @@ def getFiles(request): # Core Files should be sitting in framework's repo return HttpResponse(OpenBench.config.OPENBENCH_CONFIG['corefiles']) +@csrf_exempt +@not_minified_response +def getCompilers(request): + + data = {} # Return all engine-compiler information + for engine, config in OpenBench.config.OPENBENCH_CONFIG['engines'].items(): + data[engine] = config['build']['compilers'] + return HttpResponse(str(data)) + @csrf_exempt @not_minified_response def getWorkload(request):