From d55943d77d8044acb07b8e9b839a879eb2b37cf5 Mon Sep 17 00:00:00 2001 From: Volodymyr Shcherbyna Date: Fri, 4 Sep 2020 06:38:47 +0200 Subject: [PATCH] Implement net files support for NNUE engines (#75) --- Client/Client.py | 22 +++++++++++++++++++++- OpenBench/models.py | 3 +++ OpenBench/utils.py | 11 ++++++++++- Templates/OpenBench/newTest.html | 2 ++ Templates/OpenBench/test.html | 6 ++++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Client/Client.py b/Client/Client.py index 262f121..d1b61e2 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -23,7 +23,6 @@ from __future__ import print_function 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 @@ -241,6 +240,15 @@ def getEngine(data, engine): # Cleanup the zipfile directory shutil.rmtree('tmp') +def getNetworkWeights(network): + + if network: + fname = pathjoin('Engines', os.path.basename(network)).rstrip('/') + if not os.path.isfile(fname): getFile(network, fname) + return os.path.basename(network) + + return None + def getCutechessCommand(arguments, data, nps): # Parse options for Dev @@ -257,6 +265,10 @@ def getCutechessCommand(arguments, data, nps): devCommand = addExtension(data['test']['dev']['sha']) baseCommand = addExtension(data['test']['base']['sha']) + # Download network file(s) if configured + devnetwork = getNetworkWeights(data['test']['dev']['network']) + basenetwork = getNetworkWeights(data['test']['base']['network']) + # Scale the time control for this machine's speed timecontrol = computeAdjustedTimecontrol(arguments, data, nps) @@ -284,12 +296,20 @@ def getCutechessCommand(arguments, data, nps): '{0}-{1}'.format(data['test']['engine'], data['test']['dev']['name']) ) + # Add evaluation weights for the Dev engine if specified + if devnetwork: + devflags = devflags + " option.EvalFile=" + devnetwork + # Options for the Base Engine baseflags = '-engine dir=Engines/ cmd=./{0} proto={1} tc={2}{3} name={4}'.format( baseCommand, data['test']['base']['protocol'], timecontrol, baseoptions, '{0}-{1}'.format(data['test']['engine'], data['test']['base']['name']) ) + # Add evaluation weights for the Base engine if specified + if basenetwork: + baseflags = baseflags + " option.EvalFile=" + basenetwork + # Options for opening selection bookflags = '-openings file=Books/{0} format={1} order=random plies=16'.format( data['test']['book']['name'], data['test']['book']['name'].split('.')[-1] diff --git a/OpenBench/models.py b/OpenBench/models.py index 5e3427c..c05ed46 100644 --- a/OpenBench/models.py +++ b/OpenBench/models.py @@ -87,6 +87,9 @@ class Test(Model): devoptions = CharField(max_length=256) baseoptions = CharField(max_length=256) + devnetwork = CharField(max_length=256) + basenetwork = CharField(max_length=256) + bookname = CharField(max_length=32) timecontrol = CharField(max_length=16) diff --git a/OpenBench/utils.py b/OpenBench/utils.py index fc89a9d..4f4e4a0 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -203,6 +203,10 @@ def verifyNewTest(request): if request.POST[field] not in OpenBench.config.OPENBENCH_CONFIG[parent].keys(): errors.append('{0} was not found in the configuration'.format(fieldName)) + def verifyGithubLink(field, fieldName): + if request.POST[field] and not request.POST[field].startswith('https://github.com/'): + errors.append('{0} must be located on a Github URL'.format(fieldName)) + verifications = [ (verifyInteger, 'priority', 'Priority'), (verifyInteger, 'throughput', 'Throughput'), @@ -221,6 +225,8 @@ def verifyNewTest(request): (verifyOptions, 'baseoptions', 'Hash', 'Base Options'), (verifyConfiguration, 'enginename', 'Engine', 'engines'), (verifyConfiguration, 'bookname', 'Book', 'books'), + (verifyGithubLink, 'devnetwork', 'Dev Network'), + (verifyGithubLink, 'basenetwork', 'Base Network'), ] for verification in verifications: @@ -245,6 +251,8 @@ def createNewTest(request): test.source = request.POST['source'] test.devoptions = request.POST['devoptions'] test.baseoptions = request.POST['baseoptions'] + test.devnetwork = request.POST['devnetwork'] + test.basenetwork = request.POST['basenetwork'] test.bookname = request.POST['bookname'] test.timecontrol = request.POST['timecontrol'] test.priority = int(request.POST['priority']) @@ -376,12 +384,12 @@ def workloadDictionary(test, result, machine): 'book' : OPENBENCH_CONFIG['books'][test.bookname], 'timecontrol' : test.timecontrol, 'engine' : test.engine, - 'dev' : { 'id' : test.dev.id, 'name' : test.dev.name, 'source' : test.dev.source, 'protocol' : test.dev.protocol, 'sha' : test.dev.sha, 'bench' : test.dev.bench, 'options' : test.devoptions, + 'network' : test.devnetwork, }, 'base' : { @@ -389,6 +397,7 @@ def workloadDictionary(test, result, machine): 'source' : test.base.source, 'protocol' : test.base.protocol, 'sha' : test.base.sha, 'bench' : test.base.bench, 'options' : test.baseoptions, + 'network' : test.basenetwork, }, }, } diff --git a/Templates/OpenBench/newTest.html b/Templates/OpenBench/newTest.html index d5081bf..3f96e43 100644 --- a/Templates/OpenBench/newTest.html +++ b/Templates/OpenBench/newTest.html @@ -63,11 +63,13 @@


+

Base Settings




+
diff --git a/Templates/OpenBench/test.html b/Templates/OpenBench/test.html index f098aa7..6b5c889 100644 --- a/Templates/OpenBench/test.html +++ b/Templates/OpenBench/test.html @@ -15,10 +15,16 @@ Dev Bench{{test.dev.bench}} Dev Options{{test.devoptions}} Dev Sha{{test.dev.sha}} + {% if test.devnetwork %} + Dev Network{{test.devnetwork}} + {% endif %} Base Branch{{test.base.name|prettyName}} Base Bench{{test.base.bench}} Base Options{{test.baseoptions}} Base Sha{{test.base.sha}} + {% if test.basenetwork %} + Base Network{{test.basenetwork}} + {% endif %} Source Repo{{test.source}} Opening Book{{test.bookname}} Time Control{{test.timecontrol}}s