Unify create_test and create_tune
This commit is contained in:
1 parent
6a53772659
commit
0b17de9426
9 files changed
+342
-538
No files matched your search
@@ -240,6 +240,10 @@
|
||||
padding-bottom: 3rem;
|
||||
}
|
||||
|
||||
.pl-half {
|
||||
padding-left: 0.125rem;
|
||||
}
|
||||
|
||||
.pl-1 {
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
@@ -260,6 +264,10 @@
|
||||
padding-left: 3rem;
|
||||
}
|
||||
|
||||
.pr-half {
|
||||
padding-right: 0.125rem;
|
||||
}
|
||||
|
||||
.pr-1 {
|
||||
padding-right: 0.25rem;
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
|
||||
var config = JSON.parse(document.getElementById('json-config' ).textContent);
|
||||
var networks = JSON.parse(document.getElementById('json-networks').textContent);
|
||||
var repos = JSON.parse(document.getElementById('json-repos' ).textContent);
|
||||
|
||||
function create_network_options(field_id, engine) {
|
||||
|
||||
var has_default = false;
|
||||
var network_options = document.getElementById(field_id);
|
||||
|
||||
// Delete all existing Networks
|
||||
while (network_options.length)
|
||||
network_options.remove(0);
|
||||
|
||||
// Add each Network that matches the given engine
|
||||
for (const network of networks) {
|
||||
|
||||
if (network.engine !== engine)
|
||||
continue;
|
||||
|
||||
var opt = document.createElement('option');
|
||||
opt.text = network.name;
|
||||
opt.value = network.sha256;
|
||||
opt.selected = network.default;
|
||||
network_options.add(opt)
|
||||
|
||||
has_default = has_default || network.default;
|
||||
}
|
||||
|
||||
{ // Add a None option and set it to default if there was not one yet
|
||||
var opt = document.createElement('option');
|
||||
opt.text = 'None';
|
||||
opt.value = '';
|
||||
opt.selected = !has_default;
|
||||
network_options.add(opt);
|
||||
}
|
||||
}
|
||||
|
||||
function create_testmode_buttons(engine) {
|
||||
|
||||
// Clear out all of the existing buttons
|
||||
var button_div = document.getElementById('test-mode-buttons');
|
||||
while (button_div.hasChildNodes())
|
||||
button_div.removeChild(button_div.lastChild);
|
||||
|
||||
var index = 0;
|
||||
for (let mode in config.engines[engine].tune_modes) {
|
||||
|
||||
// Create a new button for the test mode
|
||||
var btn = document.createElement('button')
|
||||
btn.innerHTML = mode;
|
||||
btn.onclick = function() { set_test_mode(mode); };
|
||||
|
||||
// Apply all of our CSS bootstrapping
|
||||
btn.classList.add('anchorbutton');
|
||||
btn.classList.add('btn-preset');
|
||||
btn.classList.add('mt-2');
|
||||
btn.classList.add('w-100');
|
||||
|
||||
// Put the button in a div, so we can handle padding
|
||||
var div = document.createElement('div')
|
||||
div.appendChild(btn)
|
||||
div.classList.add('col-half');
|
||||
|
||||
// Left pad everything but the first
|
||||
if ((index % 4) != 0)
|
||||
div.classList.add('pl-1');
|
||||
|
||||
// Right pad everything but the last
|
||||
if ((index % 4) != 3)
|
||||
div.classList.add('pr-1');
|
||||
|
||||
button_div.append(div);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
function extract_mode_config(mode_str) {
|
||||
|
||||
// Find test mode configuration for the engine
|
||||
var selection = document.getElementById('engine');
|
||||
var engine = selection.options[selection.selectedIndex].value;
|
||||
return config.engines[engine].tune_modes[mode_str];
|
||||
}
|
||||
|
||||
function set_engine_options(mode_str) {
|
||||
|
||||
// Extract UCI options for both the engine
|
||||
var options = extract_mode_config(mode_str)['options'];
|
||||
document.getElementById('options').value = options;
|
||||
}
|
||||
|
||||
function set_test_mode(mode_str) {
|
||||
|
||||
const selection = document.getElementById('engine');
|
||||
const engine = selection.options[selection.selectedIndex].value;
|
||||
const mode = extract_mode_config(mode_str);
|
||||
|
||||
document.getElementById('book_name' ).value = mode['book'] || config.engines[engine].book;
|
||||
document.getElementById('time_control' ).value = mode['timecontrol'] || '10.0+0.1';
|
||||
|
||||
set_engine_options(mode_str);
|
||||
}
|
||||
|
||||
|
||||
/* External */
|
||||
|
||||
function set_engine(engine) {
|
||||
|
||||
// Always update the Engine and Repository to the defaults
|
||||
document.getElementById('engine').value = engine;
|
||||
document.getElementById('repo' ).value = repos[engine] || config.engines[engine].source
|
||||
|
||||
// Create dropdown of all Networks associated with the engine
|
||||
create_network_options('network', engine);
|
||||
|
||||
// Set default UCI options as if we were running an STC when changing
|
||||
set_engine_options('STC');
|
||||
|
||||
// Engine decides the Adjudication and Book settings
|
||||
document.getElementById('book_name' ).value = config.engines[engine].book;
|
||||
document.getElementById('win_adj' ).value = config.engines[engine].win_adj;
|
||||
document.getElementById('draw_adj' ).value = config.engines[engine].draw_adj;
|
||||
|
||||
set_test_mode('STC');
|
||||
create_testmode_buttons(engine)
|
||||
}
|
||||
|
||||
function enforce_default_text(id, text) {
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
var field = document.getElementById(id);
|
||||
|
||||
field.addEventListener('input', function() {
|
||||
|
||||
if (field.value.startsWith(text) || field.value === text)
|
||||
return;
|
||||
|
||||
if (field.value.endsWith('/'))
|
||||
field.value = text + field.value.substr(text.length).replace(/\/+$/, '');
|
||||
else
|
||||
field.value = text + field.value.substr(text.length);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -36,15 +36,18 @@ function create_network_options(field_id, engine) {
|
||||
}
|
||||
}
|
||||
|
||||
function create_preset_buttons(engine) {
|
||||
function create_preset_buttons(engine, workload_type) {
|
||||
|
||||
// Clear out all of the existing buttons
|
||||
var button_div = document.getElementById('test-mode-buttons');
|
||||
while (button_div.hasChildNodes())
|
||||
button_div.removeChild(button_div.lastChild);
|
||||
|
||||
const presets = workload_type == 'TEST' ? config.engines[engine].test_presets
|
||||
: workload_type == 'TUNE' ? config.engines[engine].tune_presets : {};
|
||||
|
||||
var index = 0;
|
||||
for (let mode in config.engines[engine].test_presets) {
|
||||
for (let mode in presets) {
|
||||
|
||||
// Don't include the global defaults
|
||||
if (mode == 'default')
|
||||
@@ -53,12 +56,12 @@ function create_preset_buttons(engine) {
|
||||
// Create a new button for the test mode
|
||||
var btn = document.createElement('button')
|
||||
btn.innerHTML = mode;
|
||||
btn.onclick = function() { apply_preset(mode); };
|
||||
btn.onclick = function() { apply_preset(mode, workload_type); };
|
||||
|
||||
// Apply all of our CSS bootstrapping
|
||||
btn.classList.add('anchorbutton');
|
||||
btn.classList.add('btn-preset');
|
||||
btn.classList.add('mt-2');
|
||||
btn.classList.add('mt-1');
|
||||
btn.classList.add('w-100');
|
||||
|
||||
// Put the button in a div, so we can handle padding
|
||||
@@ -68,11 +71,11 @@ function create_preset_buttons(engine) {
|
||||
|
||||
// Left pad everything but the first
|
||||
if ((index % 4) != 0)
|
||||
div.classList.add('pl-1');
|
||||
div.classList.add('pl-half');
|
||||
|
||||
// Right pad everything but the last
|
||||
if ((index % 4) != 3)
|
||||
div.classList.add('pr-1');
|
||||
div.classList.add('pr-half');
|
||||
|
||||
button_div.append(div);
|
||||
index++;
|
||||
@@ -90,11 +93,16 @@ function get_base_engine() {
|
||||
return selection.options[selection.selectedIndex].value;
|
||||
}
|
||||
|
||||
function add_defaults_to_preset(engine, preset) {
|
||||
function get_presets(engine, preset, workload_type) {
|
||||
return workload_type == 'TEST' ? config.engines[engine].test_presets[preset]
|
||||
: workload_type == 'TUNE' ? config.engines[engine].tune_presets[preset] : {};
|
||||
}
|
||||
|
||||
// Use both the defaults, and this specific preset's settings
|
||||
const default_settings = config.engines[engine].test_presets['default'] || {};
|
||||
const preset_settings = config.engines[engine].test_presets[preset] || {};
|
||||
|
||||
function add_defaults_to_preset(engine, preset, workload_type) {
|
||||
|
||||
const default_settings = get_presets(engine, 'default', workload_type);
|
||||
const preset_settings = get_presets(engine, preset, workload_type);
|
||||
|
||||
let settings = {}
|
||||
|
||||
@@ -107,7 +115,6 @@ function add_defaults_to_preset(engine, preset) {
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
function set_engine(engine, target) {
|
||||
|
||||
document.getElementById(target + '_engine').value = engine;
|
||||
@@ -146,7 +153,7 @@ function set_option(option_name, option_value) {
|
||||
}
|
||||
}
|
||||
|
||||
function retain_specific_options(engine, preset) {
|
||||
function retain_specific_options(engine, preset, workload_type) {
|
||||
|
||||
// This is not applicable for self-play
|
||||
if (get_dev_engine() == get_base_engine())
|
||||
@@ -154,14 +161,18 @@ function retain_specific_options(engine, preset) {
|
||||
|
||||
// Extract the Threads and Hash settings from the Dev Options
|
||||
|
||||
const dev_options = document.getElementById('dev_options').value;
|
||||
const dev_threads = dev_options.match(/\bThreads\s*=\s*(\d+)\b/)[1];
|
||||
const dev_hash = dev_options.match(/\bHash\s*=\s*(\d+)\b/)[1];
|
||||
const dev_options = document.getElementById('dev_options').value;
|
||||
|
||||
const threads_match = dev_options.match(/\bThreads\s*=\s*(\d+)\b/);
|
||||
const hash_match = dev_options.match(/\bHash\s*=\s*(\d+)\b/);
|
||||
|
||||
const dev_threads = threads_match ? threads_match[1] : null;
|
||||
const dev_hash = hash_match ? hash_match[1] : null;
|
||||
|
||||
// From the base options, replace the Threads= and Hash=
|
||||
|
||||
let base_options = add_defaults_to_preset(engine, preset)['base_options']
|
||||
|| add_defaults_to_preset(engine, preset)['both_options'];
|
||||
let base_options = add_defaults_to_preset(engine, preset, workload_type)['base_options']
|
||||
|| add_defaults_to_preset(engine, preset, workload_type)['both_options'];
|
||||
|
||||
base_options = base_options.replace(/\bThreads\s*=\s*\d+\b/g, 'Threads=' + dev_threads);
|
||||
base_options = base_options.replace(/\bHash\s*=\s*\d+\b/g, 'Hash=' + dev_hash);
|
||||
@@ -170,10 +181,10 @@ function retain_specific_options(engine, preset) {
|
||||
}
|
||||
|
||||
|
||||
function apply_preset(preset) {
|
||||
function apply_preset(preset, workload_type) {
|
||||
|
||||
// Add the defaults to the preset-specific options
|
||||
const settings = add_defaults_to_preset(get_dev_engine(), preset)
|
||||
const settings = add_defaults_to_preset(get_dev_engine(), preset, workload_type)
|
||||
|
||||
for (const option in settings) {
|
||||
|
||||
@@ -185,28 +196,30 @@ function apply_preset(preset) {
|
||||
|
||||
else {
|
||||
set_option(option.replace('both_', 'dev_'), settings[option]);
|
||||
set_option(option.replace('both_', 'base_'), settings[option]);
|
||||
|
||||
if (workload_type != 'TUNE')
|
||||
set_option(option.replace('both_', 'base_'), settings[option]);
|
||||
}
|
||||
}
|
||||
|
||||
// For cross-engine, keep the original Hash/Threads, but
|
||||
// For cross-engine tests, keep the original Hash/Threads, but
|
||||
// add any other settings that might be specific to the engine
|
||||
retain_specific_options(get_base_engine(), preset);
|
||||
if (workload_type != 'TUNE') {
|
||||
try {
|
||||
retain_specific_options(get_base_engine(), preset, workload_type);
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
|
||||
function change_engine(engine, target) {
|
||||
function change_engine(engine, target, workload_type) {
|
||||
|
||||
// Set the Engine, Repo, and init the Networks dropdown
|
||||
set_engine(engine, target);
|
||||
|
||||
// 1. Always set base, when setting the dev engine
|
||||
// 2. When changing the dev engine, update the test-mode buttons
|
||||
if (target == 'dev')
|
||||
create_preset_buttons(engine, workload_type);
|
||||
|
||||
if (target == 'dev') {
|
||||
if (target == 'dev' && workload_type == 'TEST')
|
||||
set_engine(engine, 'base');
|
||||
create_preset_buttons(engine);
|
||||
}
|
||||
|
||||
// Always reinit to STC for clarity to the user
|
||||
apply_preset('STC');
|
||||
}
|
||||
apply_preset('STC', workload_type);
|
||||
}
|
||||
@@ -4,6 +4,9 @@ function enforce_default_text(id, text) {
|
||||
|
||||
var field = document.getElementById(id);
|
||||
|
||||
if (!field)
|
||||
return;
|
||||
|
||||
field.addEventListener('input', function() {
|
||||
|
||||
if (field.value.startsWith(text) || field.value === text)
|
||||
|
||||
@@ -35,6 +35,7 @@ import OpenBench.utils
|
||||
import OpenBench.views
|
||||
|
||||
from OpenBench.models import *
|
||||
from OpenBench.config import OPENBENCH_CONFIG
|
||||
from OpenBench.workloads.verify_workload import verify_workload
|
||||
|
||||
def create_workload(request, workload_type):
|
||||
@@ -48,9 +49,24 @@ def create_workload(request, workload_type):
|
||||
return OpenBench.views.redirect(request, '/login/', error='Only enabled users can create tests')
|
||||
|
||||
if request.method == 'GET':
|
||||
data = { 'networks' : list(Network.objects.all().values()) }
|
||||
template = 'create_test.html' if workload_type == 'TEST' else 'create_tune.html'
|
||||
return OpenBench.views.render(request, template, data)
|
||||
|
||||
data = { 'networks' : list(Network.objects.all().values()) }
|
||||
|
||||
if workload_type == 'TEST':
|
||||
data['workload'] = workload_type
|
||||
data['dev_text'] = 'Dev'
|
||||
data['dev_title_text'] = 'Dev'
|
||||
data['submit_text'] = 'Create Engine Test'
|
||||
data['submit_endpoint'] = '/newTest/'
|
||||
|
||||
if workload_type == 'TUNE':
|
||||
data['workload'] = workload_type
|
||||
data['dev_text'] = ''
|
||||
data['dev_title_text'] = 'Engine'
|
||||
data['submit_text'] = 'Create SPSA Tune'
|
||||
data['submit_endpoint'] = '/newTune/'
|
||||
|
||||
return OpenBench.views.render(request, 'create_workload.html', data)
|
||||
|
||||
if workload_type == 'TEST':
|
||||
workload, errors = create_new_test(request)
|
||||
@@ -70,7 +86,7 @@ def create_workload(request, workload_type):
|
||||
summary = 'CREATE P=%d TP=%d' % (workload.priority, workload.throughput)
|
||||
LogEvent.objects.create(author=username, summary=summary, log_file='', test_id=workload.id)
|
||||
|
||||
if not OpenBench.config.USE_CROSS_APPROVAL and profile.approver:
|
||||
if not OPENBENCH_CONFIG['use_cross_approval'] and profile.approver:
|
||||
workload.approved = True; workload.save()
|
||||
|
||||
return OpenBench.views.redirect(request, '/index/', warning=warning)
|
||||
|
||||
Reference in new issue
Block a user