diff --git a/Client/OpenBench.py b/Client/OpenBench.py index 62f19cf..7ccc0a5 100644 --- a/Client/OpenBench.py +++ b/Client/OpenBench.py @@ -1,4 +1,4 @@ -import ast, argparse, time, sys, platform, multiprocessing +import ast, argparse, time, sys, platform, multiprocessing, hashlib import shutil, subprocess, requests, zipfile, os, math, json # Run from any location ... @@ -49,6 +49,7 @@ def getNameAsExe(program): def getFile(source, outname): # Read a file from the given source and save it locally + print('Downloading : {0}'.format(source)) request = requests.get(url=source, stream=True) with open(outname, 'wb') as fout: for chunk in request.iter_content(chunk_size=1024): @@ -83,10 +84,11 @@ def getEngine(data): if os.path.isfile('Engines/' + exe): return - # Log the fact that we are downloading a new engine - print('\nEngine :', data['name']) - print( 'Commit :', data['sha']) - print( 'Source :', source) + # Log the fact that we are setting up a new engine + print('\nSETTING UP ENGINE') + print('Engine :', data['name']) + print('Commit :', data['sha']) + print('Source :', source) # Extract and delete the zip file getFile(source, name + '.zip') @@ -208,7 +210,7 @@ def getCutechessCommand(data, scalefactor): bookflags = ( '-openings' - ' file=' + data['test']['bookname'] + + ' file=' + data['test']['book']['name'] + ' format=pgn' ' order=random' ' plies=16' @@ -259,7 +261,7 @@ def getBenchSignature(engine): # Log and return computed bench and speed print ('Bench for {0} is {1}'.format(engine['name'], bench[0])) - print ('NPS for {0} is {1}\n'.format(engine['name'], int(avg))) + print ('NPS for {0} is {1}'.format(engine['name'], int(avg))) return (bench[0], avg) def reportWrongBench(data, engine): @@ -304,12 +306,8 @@ def reportResults(data, wins, losses, draws, crashes, timeloss): def completeWorkload(data): - # Download engines and opening book + # Download and verify bench of dev engine getEngine(data['test']['dev']) - getEngine(data['test']['base']) - getFile(data['test']['booksource'], data['test']['bookname']) - - # Verify the bench of the dev engine devbench, devnps = getBenchSignature(data['test']['dev']) if devbench != int(data['test']['dev']['bench']): print (' Invalid Bench. Got {0} Expected {1}'.format( @@ -317,7 +315,8 @@ def completeWorkload(data): reportWrongBench(data, data['test']['dev']) return - # Verify the bench of the base engine + # Download and verify bench of base engine + getEngine(data['test']['base']) basebench, basenps = getBenchSignature(data['test']['base']) if basebench != int(data['test']['base']['bench']): print (' Invalid Bench. Got {0} Expected {1}'.format( @@ -325,11 +324,23 @@ def completeWorkload(data): reportWrongBench(data, data['test']['base']) return + # Download and verify sha of the opening book + print('\nVERIFYING OPENING BOOK') + if not os.path.isfile(data['test']['book']['name']): + getFile(data['test']['book']['source'], data['test']['book']['name']) + with open(data['test']['book']['name']) as fin: + digest = hashlib.sha256(fin.read().encode('utf-8')).hexdigest() + print ('Correct SHA : {0}'.format(digest.upper())) + print ('MY Book SHA : {0}'.format(data['test']['book']['sha'].upper())) + if (digest != data['test']['book']['sha']): + print (' Invalid SHA for {0}'.format(data['test']['book']['name'])) + sys.exit() + # Compute and report CPU scaling factor avgnps = (devnps + basenps) / 2.0 reportNPS(data, avgnps) scalefactor = 2650000 / avgnps - print ('FACTOR : {0}'.format(round(1 / scalefactor, 2))) + print ('\nFACTOR : {0}'.format(round(1 / scalefactor, 2))) # Compute and report cutechess-cli string command = getCutechessCommand(data, scalefactor) diff --git a/OpenBench/config.py b/OpenBench/config.py index fba5694..4345897 100644 --- a/OpenBench/config.py +++ b/OpenBench/config.py @@ -1,24 +1,55 @@ FRAMEWORK_REPO_URL = 'http://github.com/AndyGrant/OpenBench/' FRAMEWORK_DEFAULTS = { + 'config' : { + + # Framework source, must be changed for your instance + 'framework' : 'http://github.com/AndyGrant/OpenBench/', + + # Links for side bar 'source' : 'http://github.com/AndyGrant/EtherealDev/', 'homepage' : 'http://github.com/AndyGrant/Ethereal', - 'framework' : 'http://github.com/AndyGrant/OpenBench/', - 'engine' : 'Ethereal', - 'timecontrol' : '5.0+0.05', + + # Configured engines for the framework. To scale NPS for your engine, + # in order to match the time controls used here, do the following. + # Average a few bench runs for the latest version of Ethereal. Now + # take a few bench runs for the latest version of the new engine. + # Scale your NPS to match Ethereal's NPS of 2,500,000 + 'engines' : { + 'Ethereal' : {'nps' : 2500000}, + }, + + # Default engine test options + 'protocol' : 'uci', + 'threads' : 1, 'hash' : 8, 'threads' : 1, - 'protocol' : 'uci', + 'timecontrol' : '5.0+0.05', + + # SPRT bounds and confidence values 'elolower' : 0.0, 'eloupper' : 5.0, 'alpha' : 0.10, 'beta' : 0.10, - 'threads' : 1, - 'books' : [ - '2moves_v1.pgn', - '8moves_v3.pgn', - ], + # Book confgiruation. When addding a book, follow the provided template. + # The SHA is defined by hashlib.sha256(book).hexdigest(). OpenBench.py + # (Client File) has an example to show you how to find a hash digest + 'books' : { + '2moves_v1.pgn' : { + 'name' : '2moves_v1.pgn', + 'sha' : '46aed7f2696618b2b914942032957b7a97a8f343bf54ba83e20a47818f0d42e0', + 'source' : FRAMEWORK_REPO_URL + 'raw/master/Books/2moves_v1.pgn', + 'default' : True, + }, + + '8moves_v3.pgn' : { + 'name' : '8moves_v3.pgn', + 'sha' : '04fcce1488a94f3b7795cef6f74d89016eb278328897c1018e6162c5967273f5', + 'source' : FRAMEWORK_REPO_URL + 'raw/master/Books/8moves_v3.pgn', + 'default' : False, + } + }, } } diff --git a/OpenBench/utils.py b/OpenBench/utils.py index 66c2fb3..4e039ff 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -204,8 +204,7 @@ def workloadDictionary(machine, result, test): 'result' : { 'id' : result.id, }, 'test' : { 'id' : test.id, - 'bookname' : test.bookname, - 'booksource' : FRAMEWORK_REPO_URL + 'raw/master/Books/' + test.bookname, + 'book' : FRAMEWORK_DEFAULTS['config']['books'][test.bookname], 'timecontrol' : test.timecontrol, 'dev' : { 'id' : test.dev.id, diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index dfcb85a..61d174c 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -35,7 +35,6 @@ {% endblock %} diff --git a/Templates/OpenBench/newTest.html b/Templates/OpenBench/newTest.html index 44b3aaf..cf11063 100644 --- a/Templates/OpenBench/newTest.html +++ b/Templates/OpenBench/newTest.html @@ -33,8 +33,12 @@