Select Openings Better
Refer to https://github.com/AndyGrant/OpenBench/pull/168
This commit is contained in:
1 parent
ffb038b063
commit
804b0a7126
3 files changed
+41
-16
No files matched your search
+22
-15
@@ -392,7 +392,7 @@ class Cutechess:
|
|||||||
## and a small number of secondary arguments that are not housed in the Configuration
|
## and a small number of secondary arguments that are not housed in the Configuration
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def basic_settings(config, seed):
|
def basic_settings(config):
|
||||||
|
|
||||||
# Assume Fischer if FRC, 960, or FISCHER appears in the Opening Book
|
# Assume Fischer if FRC, 960, or FISCHER appears in the Opening Book
|
||||||
book_name = config.workload['test']['book']['name'].upper()
|
book_name = config.workload['test']['book']['name'].upper()
|
||||||
@@ -400,7 +400,7 @@ class Cutechess:
|
|||||||
variant = ['standard', 'fischerandom'][is_frc]
|
variant = ['standard', 'fischerandom'][is_frc]
|
||||||
|
|
||||||
# Always include -repeat and -recover
|
# Always include -repeat and -recover
|
||||||
return '-repeat -recover -srand %d -variant %s' % (seed, variant)
|
return '-repeat -recover -variant %s' % (variant)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def concurrency_settings(config):
|
def concurrency_settings(config):
|
||||||
@@ -435,12 +435,18 @@ class Cutechess:
|
|||||||
return '%s %s %s' % (win_flags, draw_flags, syzygy_flags)
|
return '%s %s %s' % (win_flags, draw_flags, syzygy_flags)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def book_settings(config):
|
def book_settings(config, cutechess_idx):
|
||||||
|
|
||||||
# Can handle EPD and PGN Books, which must be specified
|
# Can handle EPD and PGN Books, which must be specified
|
||||||
book_name = config.workload['test']['book']['name']
|
book_name = config.workload['test']['book']['name']
|
||||||
book_suffix = book_name.split('.')[-1]
|
book_suffix = book_name.split('.')[-1]
|
||||||
return '-openings file=Books/%s format=%s order=random plies=16' % (book_name, book_suffix)
|
|
||||||
|
# Start position is determined partially by cutechess index
|
||||||
|
pairs = config.workload['distribution']['games-per-cutechess'] // 2
|
||||||
|
start = config.workload['test']['book_index'] + cutechess_idx * pairs
|
||||||
|
|
||||||
|
return '-openings file=Books/%s format=%s order=random start=%d -srand %d' % (
|
||||||
|
book_name, book_suffix, start, config.workload['test']['book_seed'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def engine_settings(config, command, branch, scale_factor, cutechess_idx):
|
def engine_settings(config, command, branch, scale_factor, cutechess_idx):
|
||||||
@@ -478,12 +484,13 @@ class Cutechess:
|
|||||||
return '-engine dir=Engines/ cmd=./%s proto=uci %s%s name=%s-%s' % (command, control, options, name, branch)
|
return '-engine dir=Engines/ cmd=./%s proto=uci %s%s name=%s-%s' % (command, control, options, name, branch)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pgnout_settings(config, seed):
|
def pgnout_settings(config, timestamp, cutechess_idx):
|
||||||
|
|
||||||
test_id = int(config.workload['test']['id'])
|
test_id = int(config.workload['test']['id'])
|
||||||
result_id = int(config.workload['result']['id'])
|
result_id = int(config.workload['result']['id'])
|
||||||
|
|
||||||
return '-pgnout PGNs/%d.%d.%d.pgn' % (test_id, result_id, seed)
|
# Format: <Test>-<Result>-<Time>-<Index>.pgn
|
||||||
|
return '-pgnout PGNs/%d.%d.%d.%d.pgn' % (test_id, result_id, timestamp, cutechess_idx)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_results(results, line):
|
def update_results(results, line):
|
||||||
@@ -661,12 +668,12 @@ class ResultsReporter(object):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print ('[Note] Failed to upload results to server...')
|
print ('[Note] Failed to upload results to server...')
|
||||||
|
|
||||||
def send_errors(self, seed, cutechess_cnt):
|
def send_errors(self, timestamp, cutechess_cnt):
|
||||||
|
|
||||||
for x in range(cutechess_cnt):
|
for x in range(cutechess_cnt):
|
||||||
|
|
||||||
# Reuse logic that was given to Cutechess to decide the PGN name
|
# Reuse logic that was given to Cutechess to decide the PGN name
|
||||||
fname = Cutechess.pgnout_settings(self.config, seed + x).split()[1]
|
fname = Cutechess.pgnout_settings(self.config, timestamp, x).split()[1]
|
||||||
|
|
||||||
# For any game with weird Termination, report it
|
# For any game with weird Termination, report it
|
||||||
for header, moves in PGNHelper.slice_pgn_file(fname):
|
for header, moves in PGNHelper.slice_pgn_file(fname):
|
||||||
@@ -1066,20 +1073,20 @@ def complete_workload(config):
|
|||||||
# Launch and manage all of the Cutechess workers
|
# Launch and manage all of the Cutechess workers
|
||||||
with ThreadPoolExecutor(max_workers=cutechess_cnt) as executor:
|
with ThreadPoolExecutor(max_workers=cutechess_cnt) as executor:
|
||||||
|
|
||||||
seed = time.time()
|
timestamp = time.time()
|
||||||
results = multiprocessing.Queue()
|
results = multiprocessing.Queue()
|
||||||
abort_flag = threading.Event()
|
abort_flag = threading.Event()
|
||||||
|
|
||||||
tasks = [] # Create each of the Cutechess workers
|
tasks = [] # Create each of the Cutechess workers
|
||||||
for x in range(cutechess_cnt):
|
for x in range(cutechess_cnt):
|
||||||
cmd = build_cutechess_command(config, dev_name, base_name, scale_factor, seed + x, x)
|
cmd = build_cutechess_command(config, dev_name, base_name, scale_factor, timestamp, x)
|
||||||
tasks.append(executor.submit(run_and_parse_cutechess, config, cmd, x, results, abort_flag))
|
tasks.append(executor.submit(run_and_parse_cutechess, config, cmd, x, results, abort_flag))
|
||||||
|
|
||||||
# Process the Queue until we exit, finish, or are told to stop by the server
|
# Process the Queue until we exit, finish, or are told to stop by the server
|
||||||
try:
|
try:
|
||||||
rr = ResultsReporter(config, tasks, results, abort_flag)
|
rr = ResultsReporter(config, tasks, results, abort_flag)
|
||||||
rr.process_until_finished()
|
rr.process_until_finished()
|
||||||
rr.send_errors(seed, cutechess_cnt)
|
rr.send_errors(timestamp, cutechess_cnt)
|
||||||
Cutechess.kill_everything(dev_name, base_name)
|
Cutechess.kill_everything(dev_name, base_name)
|
||||||
|
|
||||||
# Kill everything during an Exception, but print it
|
# Kill everything during an Exception, but print it
|
||||||
@@ -1278,15 +1285,15 @@ def run_benchmarks(config, branch, engine, network):
|
|||||||
# Set NPS to 0 if we had any errors
|
# Set NPS to 0 if we had any errors
|
||||||
return 0 if not bench or error else nps
|
return 0 if not bench or error else nps
|
||||||
|
|
||||||
def build_cutechess_command(config, dev_cmd, base_cmd, scale_factor, seed, cutechess_idx):
|
def build_cutechess_command(config, dev_cmd, base_cmd, scale_factor, timestamp, cutechess_idx):
|
||||||
|
|
||||||
flags = ' ' + Cutechess.basic_settings(config, seed)
|
flags = ' ' + Cutechess.basic_settings(config)
|
||||||
flags += ' ' + Cutechess.concurrency_settings(config)
|
flags += ' ' + Cutechess.concurrency_settings(config)
|
||||||
flags += ' ' + Cutechess.adjudication_settings(config)
|
flags += ' ' + Cutechess.adjudication_settings(config)
|
||||||
flags += ' ' + Cutechess.engine_settings(config, dev_cmd, 'dev', scale_factor, cutechess_idx)
|
flags += ' ' + Cutechess.engine_settings(config, dev_cmd, 'dev', scale_factor, cutechess_idx)
|
||||||
flags += ' ' + Cutechess.engine_settings(config, base_cmd, 'base', scale_factor, cutechess_idx)
|
flags += ' ' + Cutechess.engine_settings(config, base_cmd, 'base', scale_factor, cutechess_idx)
|
||||||
flags += ' ' + Cutechess.book_settings(config)
|
flags += ' ' + Cutechess.book_settings(config, cutechess_idx)
|
||||||
flags += ' ' + Cutechess.pgnout_settings(config, seed)
|
flags += ' ' + Cutechess.pgnout_settings(config, timestamp, cutechess_idx)
|
||||||
|
|
||||||
return ['cutechess-ob.exe', './cutechess-ob'][IS_LINUX] + flags
|
return ['cutechess-ob.exe', './cutechess-ob'][IS_LINUX] + flags
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ class Test(Model):
|
|||||||
|
|
||||||
# Misc information
|
# Misc information
|
||||||
author = CharField(max_length=64)
|
author = CharField(max_length=64)
|
||||||
|
|
||||||
|
# Opening book settings
|
||||||
book_name = CharField(max_length=32)
|
book_name = CharField(max_length=32)
|
||||||
|
book_index = IntegerField(default=1)
|
||||||
|
|
||||||
# Dev Engine, and all of its settings
|
# Dev Engine, and all of its settings
|
||||||
dev = ForeignKey('Engine', PROTECT, related_name='dev')
|
dev = ForeignKey('Engine', PROTECT, related_name='dev')
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ import OpenBench.utils
|
|||||||
from OpenBench.config import OPENBENCH_CONFIG
|
from OpenBench.config import OPENBENCH_CONFIG
|
||||||
from OpenBench.models import Result, Test
|
from OpenBench.models import Result, Test
|
||||||
|
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
|
||||||
def get_workload(machine):
|
def get_workload(machine):
|
||||||
|
|
||||||
# Select a workload from the possible ones, if we can
|
# Select a workload from the possible ones, if we can
|
||||||
@@ -228,7 +231,19 @@ def workload_to_dictionary(test, result, machine):
|
|||||||
|
|
||||||
workload['distribution'] = game_distribution(test, machine)
|
workload['distribution'] = game_distribution(test, machine)
|
||||||
workload['spsa'] = spsa_to_dictionary(test, workload)
|
workload['spsa'] = spsa_to_dictionary(test, workload)
|
||||||
workload['reporting_type'] = test.spsa['reporting_type']
|
workload['reporting_type'] = test.spsa.get('reporting_type', 'BATCHED')
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
|
||||||
|
test = Test.objects.select_for_update().get(id=test.id)
|
||||||
|
workload['test']['book_seed' ] = test.id
|
||||||
|
workload['test']['book_index'] = test.book_index
|
||||||
|
|
||||||
|
cutechess_cnt = workload['distribution']['cutechess-count']
|
||||||
|
pairs_per_cnt = workload['distribution']['games-per-cutechess'] // 2
|
||||||
|
|
||||||
|
test.book_index += cutechess_cnt * pairs_per_cnt
|
||||||
|
test.save()
|
||||||
|
|
||||||
return workload
|
return workload
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user