Tune page: parameter history chart, two-column layout, collapsed settings
Record every SPSA parameter value as results arrive (media/spsa_history/<id>.json, same idea as the LLR history). The Tune page plots how far each parameter has moved from its start, as a share of its allowed range. Hovering or pinning a parameter name follows its line. The page is now a main column (progress, history, results, details) plus a side column (actions, settings), and the settings and parameter details start collapsed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TyAt5S5MAwLBY2idan1SwU
This commit is contained in:
1 parent
9aa7678b62
commit
de5ec59ece
5 files changed
+851
-8
No files matched your search
@@ -0,0 +1,254 @@
|
||||
/* Tune page: layout, collapsible sections, and the parameter history chart. */
|
||||
|
||||
/* ---------- Layout: a main column, and a side column ---------- */
|
||||
|
||||
#content .workload-container.tune-page {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 320px;
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
#content .tune-page > .tune-main {
|
||||
grid-column: 1;
|
||||
grid-row: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
#content .tune-page > .tune-side {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
#content .tune-main > .card,
|
||||
#content .tune-side > .card {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Source order is side first; this puts the story in the right order */
|
||||
#content .tune-main > #spsa-panel { order: 1; }
|
||||
#content .tune-main > #results { order: 2; }
|
||||
#content .tune-main > #parameters { order: 3; }
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
#content .workload-container.tune-page { grid-template-columns: minmax(0, 1fr); }
|
||||
#content .tune-page > .tune-main { grid-column: 1; grid-row: 1; }
|
||||
#content .tune-page > .tune-side { grid-column: 1; grid-row: 2; }
|
||||
}
|
||||
|
||||
/* ---------- Collapsible sections ---------- */
|
||||
|
||||
#content details.config-fold {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.config-fold > summary {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
padding: 14px 18px;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
.config-fold > summary::-webkit-details-marker { display: none; }
|
||||
|
||||
.config-fold > summary .card-title { margin: 0; }
|
||||
|
||||
.config-fold > summary:focus-visible {
|
||||
outline: 2px solid var(--accent, #4c8dff);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.config-hint {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
font-size: 12.5px;
|
||||
color: var(--muted, var(--color-font3, #8b95a7));
|
||||
}
|
||||
|
||||
.config-fold > summary::after {
|
||||
content: '';
|
||||
flex: none;
|
||||
align-self: center;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-right: 1.5px solid currentColor;
|
||||
border-bottom: 1.5px solid currentColor;
|
||||
opacity: .6;
|
||||
transform: rotate(45deg) translateY(-2px);
|
||||
transition: transform .15s ease;
|
||||
}
|
||||
|
||||
.config-fold[open] > summary::after {
|
||||
transform: rotate(-135deg) translateY(-2px);
|
||||
}
|
||||
|
||||
.config-fold[open] > summary {
|
||||
border-bottom: 1px solid var(--line, #2a303a);
|
||||
}
|
||||
|
||||
.config-fold > :not(summary) {
|
||||
padding-left: 18px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.config-fold > table { margin-top: 8px; margin-bottom: 12px; width: calc(100% - 36px); }
|
||||
|
||||
/* ---------- Parameter names double as "show on chart" buttons ---------- */
|
||||
|
||||
button.spsa-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: var(--spsa-ink);
|
||||
background: none;
|
||||
border: 0;
|
||||
font-family: var(--spsa-mono);
|
||||
font-size: 13.5px;
|
||||
}
|
||||
|
||||
button.spsa-name::before {
|
||||
content: '';
|
||||
flex: none;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--row-color, transparent);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.spsa-row.is-shown button.spsa-name::before { opacity: 1; }
|
||||
.spsa-row.is-pinned button.spsa-name { text-decoration: underline; text-underline-offset: 3px; }
|
||||
|
||||
button.spsa-name:focus-visible {
|
||||
outline: 2px solid var(--spsa-fill);
|
||||
outline-offset: 3px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
/* ---------- History chart ---------- */
|
||||
|
||||
.spsa-history {
|
||||
padding: 4px 0 18px;
|
||||
}
|
||||
|
||||
.spsa-history-head h3 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--spsa-ink);
|
||||
}
|
||||
|
||||
.spsa-history-head p {
|
||||
margin: 2px 0 10px;
|
||||
font-size: 13px;
|
||||
color: var(--spsa-muted);
|
||||
}
|
||||
|
||||
.spsa-chart { position: relative; width: 100%; }
|
||||
|
||||
.sch-plot {
|
||||
position: relative;
|
||||
cursor: crosshair;
|
||||
touch-action: pan-y;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.sch-plot:focus-visible {
|
||||
outline: 2px solid var(--spsa-fill);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
|
||||
.sch-svg { display: block; width: 100%; height: auto; overflow: visible; }
|
||||
|
||||
.sch-bg { fill: transparent; }
|
||||
|
||||
.sch-grid { stroke: rgba(197, 204, 217, .09); stroke-width: 1; shape-rendering: crispEdges; }
|
||||
.sch-zero { stroke: var(--spsa-muted); stroke-width: 1; opacity: .65; shape-rendering: crispEdges; }
|
||||
|
||||
.sch-tick {
|
||||
fill: var(--spsa-muted);
|
||||
font: 500 10px var(--spsa-mono);
|
||||
}
|
||||
|
||||
.sch-line {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
.sch-line.is-quiet { stroke: var(--spsa-muted); stroke-width: 1; opacity: .24; }
|
||||
.sch-line.is-on { stroke-width: 2; }
|
||||
|
||||
.sch-label { font: 600 11px var(--spsa-mono); }
|
||||
|
||||
.sch-hover-line {
|
||||
stroke: var(--spsa-ink);
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 2 2;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.sch-hover-line.is-active { opacity: .7; }
|
||||
|
||||
.sch-dot { stroke: var(--color2, #1a1d22); stroke-width: 1.5; }
|
||||
|
||||
.c0 { stroke: #5fa0ff; fill: #5fa0ff; }
|
||||
.c1 { stroke: #6ee7b7; fill: #6ee7b7; }
|
||||
.c2 { stroke: #f2c94c; fill: #f2c94c; }
|
||||
.c3 { stroke: #c4a1ff; fill: #c4a1ff; }
|
||||
.c4 { stroke: #ff8f84; fill: #ff8f84; }
|
||||
|
||||
.sch-line.c0, .sch-line.c1, .sch-line.c2, .sch-line.c3, .sch-line.c4 { fill: none; }
|
||||
.sch-label.c0, .sch-label.c1, .sch-label.c2, .sch-label.c3, .sch-label.c4 { stroke: none; }
|
||||
|
||||
.sch-tip {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
min-width: 150px;
|
||||
padding: 8px 10px;
|
||||
background: rgba(14, 16, 20, .96);
|
||||
border: 1px solid var(--line-strong, #3a3f48);
|
||||
border-radius: 4px;
|
||||
color: var(--spsa-ink);
|
||||
font: 500 12px var(--spsa-mono);
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transition: opacity .12s ease;
|
||||
}
|
||||
|
||||
.sch-tip.is-active { opacity: 1; }
|
||||
|
||||
.sch-tip .t-games { margin-bottom: 4px; color: var(--spsa-muted); }
|
||||
|
||||
.sch-tip .t-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
|
||||
.sch-tip .t-swatch { flex: none; width: 8px; height: 8px; border-radius: 50%; }
|
||||
.sch-tip .t-name { margin-right: auto; padding-right: 12px; }
|
||||
.sch-tip .t-delta { color: var(--spsa-muted); }
|
||||
|
||||
.spsa-note {
|
||||
margin: 8px 0 0;
|
||||
font-size: 12.5px;
|
||||
color: var(--spsa-muted);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.sch-tip, .config-fold > summary::after { transition: none; }
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
/* SPSA history chart (Tune pages).
|
||||
|
||||
The server (mytags.spsa_history_chart) supplies every parameter's value over
|
||||
time as <div class="spsa-chart" data-chart="{json}">. Each line is one
|
||||
parameter, drawn as how far it has travelled from its start value, as a share
|
||||
of its allowed range, so parameters with very different scales share an axis.
|
||||
|
||||
A few lines are highlighted at a time. By default that is the three that moved
|
||||
the most. Hovering a parameter's name in the list follows that one, and
|
||||
clicking a name pins it, so several can be compared. */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
var MINUS = '−';
|
||||
var HEIGHT = 230;
|
||||
var MARGIN = { l: 46, r: 100, t: 12, b: 22 };
|
||||
var COLOURS = 5;
|
||||
var MAX_ON = 8;
|
||||
|
||||
function svg(name, attrs, parent) {
|
||||
var node = document.createElementNS(SVG_NS, name);
|
||||
for (var key in attrs)
|
||||
if (Object.prototype.hasOwnProperty.call(attrs, key))
|
||||
node.setAttribute(key, attrs[key]);
|
||||
if (parent)
|
||||
parent.appendChild(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
function html(name, className, parent) {
|
||||
var node = document.createElement(name);
|
||||
if (className)
|
||||
node.className = className;
|
||||
if (parent)
|
||||
parent.appendChild(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
function clamp(value, lo, hi) {
|
||||
return Math.max(lo, Math.min(hi, value));
|
||||
}
|
||||
|
||||
function percent(value) {
|
||||
var shown = Math.abs(value) < 10 ? Math.abs(value).toFixed(1) : String(Math.round(Math.abs(value)));
|
||||
return (value > 0 ? '+' : value < 0 ? MINUS : '') + shown + '%';
|
||||
}
|
||||
|
||||
function amount(value, integer) {
|
||||
return integer ? String(Math.round(value)) : value.toFixed(4);
|
||||
}
|
||||
|
||||
function commas(value) {
|
||||
return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
function short(name) {
|
||||
return name.length > 13 ? name.slice(0, 12) + '…' : name;
|
||||
}
|
||||
|
||||
/* ---------- Chart ---------- */
|
||||
|
||||
function Chart(root, data, rows) {
|
||||
|
||||
var self = this;
|
||||
|
||||
this.root = root;
|
||||
this.data = data;
|
||||
this.rows = rows; // list items, by parameter index
|
||||
this.pinned = [];
|
||||
this.hover = -1;
|
||||
this.active = -1;
|
||||
this.width = 0;
|
||||
|
||||
// Movement from the start value, as a share of the allowed range
|
||||
this.series = data.names.map(function (name, i) {
|
||||
var span = (data.max[i] - data.min[i]) || 1;
|
||||
return data.points.map(function (point) {
|
||||
return (point[1 + i] - data.start[i]) / span * 100;
|
||||
});
|
||||
});
|
||||
|
||||
// Without a choice, follow whichever parameters moved the most
|
||||
var last = this.series.map(function (line, i) {
|
||||
return { index: i, size: Math.abs(line[line.length - 1]) };
|
||||
});
|
||||
last.sort(function (a, b) { return b.size - a.size || a.index - b.index; });
|
||||
this.defaults = last.slice(0, 3).map(function (entry) { return entry.index; });
|
||||
|
||||
root.textContent = '';
|
||||
|
||||
this.plot = html('div', 'sch-plot', root);
|
||||
this.plot.tabIndex = 0;
|
||||
this.plot.setAttribute('role', 'img');
|
||||
this.plot.setAttribute('aria-label', 'Parameter history. Use the arrow keys to inspect the points.');
|
||||
|
||||
this.svg = svg('svg', { 'class': 'sch-svg', 'aria-hidden': 'true' }, this.plot);
|
||||
this.tip = html('div', 'sch-tip', this.plot);
|
||||
|
||||
this.render();
|
||||
this.bind();
|
||||
}
|
||||
|
||||
Chart.prototype.shown = function () {
|
||||
|
||||
var list = this.pinned.slice();
|
||||
|
||||
if (this.hover >= 0 && list.indexOf(this.hover) < 0)
|
||||
list.push(this.hover);
|
||||
|
||||
if (!list.length)
|
||||
list = this.defaults.slice();
|
||||
|
||||
return list.slice(0, MAX_ON);
|
||||
};
|
||||
|
||||
Chart.prototype.render = function () {
|
||||
|
||||
var W = Math.floor(this.plot.clientWidth);
|
||||
if (W < 160)
|
||||
return;
|
||||
|
||||
this.width = W;
|
||||
|
||||
var H = HEIGHT, m = MARGIN;
|
||||
var iw = W - m.l - m.r, ih = H - m.t - m.b;
|
||||
var points = this.data.points;
|
||||
var xMax = Math.max(points[points.length - 1][0], 1);
|
||||
var shown = this.shown();
|
||||
var series = this.series;
|
||||
|
||||
// Vertical range: everything that moved, and zero
|
||||
var lo = 0, hi = 0;
|
||||
series.forEach(function (line) {
|
||||
line.forEach(function (v) {
|
||||
if (v < lo) lo = v;
|
||||
if (v > hi) hi = v;
|
||||
});
|
||||
});
|
||||
|
||||
var pad = Math.max((hi - lo) * 0.12, 1);
|
||||
lo -= pad; hi += pad;
|
||||
|
||||
function sx(games) { return m.l + iw * (games / xMax); }
|
||||
function sy(value) { return m.t + ih * (1 - (value - lo) / (hi - lo)); }
|
||||
|
||||
this.geo = { W: W, H: H, iw: iw, ih: ih, xMax: xMax, sx: sx, sy: sy };
|
||||
|
||||
var el = this.svg;
|
||||
el.textContent = '';
|
||||
el.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
|
||||
el.setAttribute('width', W);
|
||||
el.setAttribute('height', H);
|
||||
|
||||
svg('rect', { 'class': 'sch-bg', x: m.l, y: m.t, width: iw, height: ih }, el);
|
||||
|
||||
// Horizontal grid, with the zero line emphasised
|
||||
[hi, (hi + lo) / 2, lo].forEach(function (value) {
|
||||
var y = sy(value);
|
||||
svg('line', { 'class': 'sch-grid', x1: m.l, x2: m.l + iw, y1: y, y2: y }, el);
|
||||
svg('text', { 'class': 'sch-tick', x: m.l - 8, y: y, dy: '0.32em', 'text-anchor': 'end' }, el).textContent = percent(value);
|
||||
});
|
||||
|
||||
svg('line', { 'class': 'sch-zero', x1: m.l, x2: m.l + iw, y1: sy(0), y2: sy(0) }, el);
|
||||
svg('text', { 'class': 'sch-tick', x: m.l - 8, y: sy(0), dy: '0.32em', 'text-anchor': 'end' }, el).textContent = '0';
|
||||
|
||||
// Games axis
|
||||
[[0, 'start', m.l], [xMax / 2, 'middle', m.l + iw / 2], [xMax, 'end', m.l + iw]].forEach(function (tick) {
|
||||
var label = svg('text', { 'class': 'sch-tick', x: tick[2], y: H - 5, 'text-anchor': tick[1] }, el);
|
||||
label.textContent = tick[0] === 0 ? '0 games' : commas(tick[0]);
|
||||
});
|
||||
|
||||
// Lines: the quiet ones first, so the highlighted ones sit on top
|
||||
function path(line) {
|
||||
return line.map(function (v, k) {
|
||||
return (k ? 'L' : 'M') + sx(points[k][0]).toFixed(1) + ' ' + sy(v).toFixed(1);
|
||||
}).join('');
|
||||
}
|
||||
|
||||
series.forEach(function (line, i) {
|
||||
if (shown.indexOf(i) < 0)
|
||||
svg('path', { 'class': 'sch-line is-quiet', d: path(line) }, el);
|
||||
});
|
||||
|
||||
shown.forEach(function (i, order) {
|
||||
svg('path', { 'class': 'sch-line is-on c' + (order % COLOURS), d: path(series[i]) }, el);
|
||||
});
|
||||
|
||||
// Names at the end of each highlighted line, kept apart from one another
|
||||
var labels = shown.map(function (i, order) {
|
||||
var line = series[i];
|
||||
return { index: i, order: order, y: sy(line[line.length - 1]) };
|
||||
}).sort(function (a, b) { return a.y - b.y; });
|
||||
|
||||
for (var k = 1; k < labels.length; k++)
|
||||
if (labels[k].y - labels[k - 1].y < 13)
|
||||
labels[k].y = labels[k - 1].y + 13;
|
||||
|
||||
labels.forEach(function (label) {
|
||||
var line = series[label.index];
|
||||
svg('circle', { 'class': 'sch-dot c' + (label.order % COLOURS), cx: sx(points[points.length - 1][0]), cy: sy(line[line.length - 1]), r: 3.5 }, el);
|
||||
svg('text', { 'class': 'sch-label c' + (label.order % COLOURS), x: m.l + iw + 10, y: label.y, dy: '0.32em' }, el).textContent = short(this.data.names[label.index]);
|
||||
}, this);
|
||||
|
||||
// Marker
|
||||
this.hoverLine = svg('line', { 'class': 'sch-hover-line', y1: m.t, y2: m.t + ih }, el);
|
||||
this.hoverDots = shown.map(function (i, order) {
|
||||
return svg('circle', { 'class': 'sch-dot c' + (order % COLOURS), r: 3.5, opacity: 0 }, el);
|
||||
});
|
||||
|
||||
this.syncRows(shown);
|
||||
|
||||
if (this.active >= 0)
|
||||
this.setActive(this.active);
|
||||
};
|
||||
|
||||
/* ---------- Rows in the parameter list ---------- */
|
||||
|
||||
Chart.prototype.syncRows = function (shown) {
|
||||
|
||||
var self = this;
|
||||
|
||||
this.rows.forEach(function (row, i) {
|
||||
|
||||
if (!row)
|
||||
return;
|
||||
|
||||
var order = shown.indexOf(i);
|
||||
var on = order >= 0 && (self.pinned.length || self.hover >= 0 || false);
|
||||
|
||||
row.classList.toggle('is-shown', on);
|
||||
row.classList.toggle('is-pinned', self.pinned.indexOf(i) >= 0);
|
||||
|
||||
if (on)
|
||||
row.style.setProperty('--row-color', ['#5fa0ff', '#6ee7b7', '#f2c94c', '#c4a1ff', '#ff8f84'][order % COLOURS]);
|
||||
else
|
||||
row.style.removeProperty('--row-color');
|
||||
});
|
||||
};
|
||||
|
||||
/* ---------- Inspecting a point ---------- */
|
||||
|
||||
Chart.prototype.nearest = function (x) {
|
||||
|
||||
var g = this.geo, points = this.data.points;
|
||||
var target = clamp((x - MARGIN.l) / g.iw, 0, 1) * g.xMax;
|
||||
var best = 0, distance = Infinity;
|
||||
|
||||
for (var k = 0; k < points.length; k++) {
|
||||
var d = Math.abs(points[k][0] - target);
|
||||
if (d < distance) { distance = d; best = k; }
|
||||
}
|
||||
|
||||
return best;
|
||||
};
|
||||
|
||||
Chart.prototype.setActive = function (index) {
|
||||
|
||||
if (!this.geo)
|
||||
return;
|
||||
|
||||
var g = this.geo, points = this.data.points, data = this.data;
|
||||
|
||||
if (index < 0) {
|
||||
this.active = -1;
|
||||
this.hoverLine.classList.remove('is-active');
|
||||
this.hoverDots.forEach(function (dot) { dot.setAttribute('opacity', 0); });
|
||||
this.tip.classList.remove('is-active');
|
||||
return;
|
||||
}
|
||||
|
||||
this.active = index = clamp(index, 0, points.length - 1);
|
||||
|
||||
var shown = this.shown();
|
||||
var x = g.sx(points[index][0]);
|
||||
|
||||
this.hoverLine.setAttribute('x1', x);
|
||||
this.hoverLine.setAttribute('x2', x);
|
||||
this.hoverLine.classList.add('is-active');
|
||||
|
||||
this.hoverDots.forEach(function (dot, order) {
|
||||
dot.setAttribute('cx', x);
|
||||
dot.setAttribute('cy', g.sy(this.series[shown[order]][index]));
|
||||
dot.setAttribute('opacity', 1);
|
||||
}, this);
|
||||
|
||||
// Tooltip: the games played, then each highlighted parameter's value there
|
||||
var tip = this.tip;
|
||||
tip.textContent = '';
|
||||
html('div', 't-games', tip).textContent = commas(points[index][0]) + ' games';
|
||||
|
||||
shown.forEach(function (i, order) {
|
||||
var row = html('div', 't-row', tip);
|
||||
var swatch = html('span', 't-swatch c' + (order % COLOURS), row);
|
||||
swatch.style.background = ['#5fa0ff', '#6ee7b7', '#f2c94c', '#c4a1ff', '#ff8f84'][order % COLOURS];
|
||||
html('span', 't-name', row).textContent = data.names[i];
|
||||
html('span', 't-value', row).textContent = amount(points[index][1 + i], data.integer[i]);
|
||||
html('span', 't-delta', row).textContent = percent(this.series[i][index]);
|
||||
}, this);
|
||||
|
||||
tip.classList.add('is-active');
|
||||
|
||||
var left = clamp(x + 12, 0, g.W - tip.offsetWidth);
|
||||
if (x + 12 + tip.offsetWidth > g.W - 4)
|
||||
left = clamp(x - tip.offsetWidth - 12, 0, g.W - tip.offsetWidth);
|
||||
|
||||
tip.style.left = left + 'px';
|
||||
tip.style.top = MARGIN.t + 'px';
|
||||
};
|
||||
|
||||
/* ---------- Events ---------- */
|
||||
|
||||
Chart.prototype.redraw = function () {
|
||||
this.render();
|
||||
};
|
||||
|
||||
Chart.prototype.togglePin = function (index) {
|
||||
|
||||
var at = this.pinned.indexOf(index);
|
||||
if (at >= 0)
|
||||
this.pinned.splice(at, 1);
|
||||
else if (this.pinned.length < MAX_ON)
|
||||
this.pinned.push(index);
|
||||
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
Chart.prototype.follow = function (index) {
|
||||
this.hover = index;
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
Chart.prototype.bind = function () {
|
||||
|
||||
var self = this, plot = this.plot;
|
||||
|
||||
function move(event) {
|
||||
if (!self.geo)
|
||||
return;
|
||||
var box = self.svg.getBoundingClientRect();
|
||||
var x = (event.clientX - box.left) * (self.geo.W / (box.width || self.geo.W));
|
||||
self.setActive(self.nearest(x));
|
||||
}
|
||||
|
||||
plot.addEventListener('pointerenter', move);
|
||||
plot.addEventListener('pointermove', move);
|
||||
plot.addEventListener('pointerdown', move);
|
||||
plot.addEventListener('pointerleave', function (event) {
|
||||
if (event.pointerType === 'mouse')
|
||||
self.setActive(-1);
|
||||
});
|
||||
|
||||
plot.addEventListener('keydown', function (event) {
|
||||
|
||||
var last = self.data.points.length - 1;
|
||||
var step = event.shiftKey ? 10 : 1;
|
||||
var index = self.active;
|
||||
|
||||
if (event.key === 'ArrowLeft') index = index < 0 ? last : index - step;
|
||||
else if (event.key === 'ArrowRight') index = index < 0 ? last : index + step;
|
||||
else if (event.key === 'Home') index = 0;
|
||||
else if (event.key === 'End') index = last;
|
||||
else if (event.key === 'Escape') { self.setActive(-1); return; }
|
||||
else return;
|
||||
|
||||
event.preventDefault();
|
||||
self.setActive(clamp(index, 0, last));
|
||||
});
|
||||
|
||||
plot.addEventListener('blur', function () { self.setActive(-1); });
|
||||
|
||||
// Names in the list
|
||||
this.rows.forEach(function (row, i) {
|
||||
|
||||
if (!row)
|
||||
return;
|
||||
|
||||
var button = row.querySelector('.spsa-name');
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
row.addEventListener('mouseenter', function () { self.follow(i); });
|
||||
row.addEventListener('mouseleave', function () { self.follow(-1); });
|
||||
button.addEventListener('focus', function () { self.follow(i); });
|
||||
button.addEventListener('blur', function () { self.follow(-1); });
|
||||
|
||||
button.addEventListener('click', function () {
|
||||
self.togglePin(i);
|
||||
button.setAttribute('aria-pressed', self.pinned.indexOf(i) >= 0 ? 'true' : 'false');
|
||||
});
|
||||
});
|
||||
|
||||
// Keep the chart as wide as its panel
|
||||
if ('ResizeObserver' in window) {
|
||||
var queued = false;
|
||||
new ResizeObserver(function () {
|
||||
if (queued) return;
|
||||
queued = true;
|
||||
window.requestAnimationFrame(function () {
|
||||
queued = false;
|
||||
if (Math.floor(plot.clientWidth) !== self.width)
|
||||
self.render();
|
||||
});
|
||||
}).observe(plot);
|
||||
} else {
|
||||
window.addEventListener('resize', function () {
|
||||
if (Math.floor(plot.clientWidth) !== self.width)
|
||||
self.render();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/* ---------- Start ---------- */
|
||||
|
||||
function note(root, text) {
|
||||
root.textContent = '';
|
||||
html('p', 'spsa-note', root).textContent = text;
|
||||
}
|
||||
|
||||
function start() {
|
||||
|
||||
var root = document.querySelector('.spsa-chart[data-chart]');
|
||||
if (!root)
|
||||
return;
|
||||
|
||||
var data;
|
||||
try {
|
||||
data = JSON.parse(root.getAttribute('data-chart'));
|
||||
} catch (error) {
|
||||
return note(root, 'The history could not be read.');
|
||||
}
|
||||
|
||||
if (!data.names.length || data.points.length < 2 || !data.games)
|
||||
return note(root, 'No games have been played yet. The chart appears with the first results.');
|
||||
|
||||
var items = document.querySelectorAll('#spsa-rows .spsa-row');
|
||||
var rows = [];
|
||||
for (var k = 0; k < items.length; k++)
|
||||
rows[parseInt(items[k].getAttribute('data-index'), 10)] = items[k];
|
||||
|
||||
new Chart(root, data, rows);
|
||||
|
||||
if (!data.recorded) {
|
||||
var message = html('p', 'spsa-note');
|
||||
message.textContent = 'History starts recording with the next result. Until then the chart shows only the start and the current values.';
|
||||
root.parentNode.appendChild(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading')
|
||||
document.addEventListener('DOMContentLoaded', start);
|
||||
else
|
||||
start();
|
||||
|
||||
})();
|
||||
@@ -622,6 +622,60 @@ def spsa_param_panel(workload):
|
||||
'games' : int(workload.games),
|
||||
}
|
||||
|
||||
def spsa_history_chart(workload):
|
||||
|
||||
# Data for the Tune page's history chart, drawn in the browser by spsa_chart.js
|
||||
# Rows are [ games, value, value, ... ], in the same order as the parameter panel
|
||||
|
||||
spsa = workload.spsa
|
||||
keys = sorted(spsa['parameters'].keys(), key=lambda x: spsa['parameters'][x].get('index', -1))
|
||||
params = [spsa['parameters'][key] for key in keys]
|
||||
|
||||
start = [float(p['start']) for p in params]
|
||||
current = [float(p['value']) for p in params]
|
||||
games = int(workload.games)
|
||||
|
||||
stored = OpenBench.utils.load_spsa_history(workload)
|
||||
rows = []
|
||||
|
||||
if stored:
|
||||
column = { name : index for index, name in enumerate(stored.get('names', [])) }
|
||||
for point in stored.get('points', []):
|
||||
row = [int(point[0])]
|
||||
for key, fallback in zip(keys, start):
|
||||
index = column.get(key)
|
||||
row.append(point[1 + index] if index is not None and 1 + index < len(point) else fallback)
|
||||
rows.append(row)
|
||||
|
||||
# The line starts at the start values, and ends on the current state
|
||||
if not rows or rows[0][0] != 0:
|
||||
rows.insert(0, [0] + start)
|
||||
if rows[-1][0] == games and games > 0:
|
||||
rows[-1] = [games] + current
|
||||
elif rows[-1][0] < games:
|
||||
rows.append([games] + current)
|
||||
|
||||
# Never send more than a few hundred points to the browser
|
||||
limit = 200
|
||||
if len(rows) > limit:
|
||||
step = (len(rows) - 1) / float(limit - 1)
|
||||
keep = sorted(set(int(round(i * step)) for i in range(limit)) | { len(rows) - 1 })
|
||||
rows = [rows[i] for i in keep]
|
||||
|
||||
data = {
|
||||
'names' : keys,
|
||||
'start' : start,
|
||||
'min' : [float(p['min']) for p in params],
|
||||
'max' : [float(p['max']) for p in params],
|
||||
'integer' : [not p['float'] for p in params],
|
||||
'points' : [[row[0]] + [round(float(v), 4) for v in row[1:]] for row in rows],
|
||||
'recorded' : bool(stored),
|
||||
'games' : games,
|
||||
}
|
||||
|
||||
payload = html.escape(json.dumps(data, separators=(',', ':')), quote=True)
|
||||
return mark_safe('<div class="spsa-chart" data-chart="%s"></div>' % payload)
|
||||
|
||||
def book_download_link(workload):
|
||||
if workload.book_name in OpenBench.config.OPENBENCH_CONFIG['books']:
|
||||
return OpenBench.config.OPENBENCH_CONFIG['books'][workload.book_name]['source']
|
||||
@@ -688,6 +742,7 @@ register.filter('spsa_param_digest_headers', spsa_param_digest_headers)
|
||||
register.filter('spsa_original_input', spsa_original_input)
|
||||
register.filter('spsa_optimal_values', spsa_optimal_values)
|
||||
register.filter('spsa_param_panel', spsa_param_panel)
|
||||
register.filter('spsa_history_chart', spsa_history_chart)
|
||||
|
||||
register.filter('book_download_link', book_download_link)
|
||||
register.filter('network_download_link', network_download_link)
|
||||
|
||||
@@ -286,6 +286,61 @@ def get_llr_history(test, max_points=LLR_HISTORY_SAMPLE_POINTS):
|
||||
|
||||
return compact_history
|
||||
|
||||
SPSA_HISTORY_MAX_POINTS = 1500
|
||||
|
||||
def spsa_history_path(test_id):
|
||||
return os.path.join(MEDIA_ROOT, 'spsa_history', '%d.json' % (test_id))
|
||||
|
||||
def spsa_param_names(test):
|
||||
|
||||
# Maintain the original order, if there was one
|
||||
return sorted(
|
||||
test.spsa['parameters'].keys(),
|
||||
key=lambda x: test.spsa['parameters'][x].get('index', -1)
|
||||
)
|
||||
|
||||
def load_spsa_history(test):
|
||||
|
||||
# { 'names' : [ ... ], 'points' : [ [ games, value, value, ... ], ... ] }
|
||||
path = spsa_history_path(test.id)
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(path) as fin:
|
||||
history = json.load(fin)
|
||||
return history if history.get('points') else None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def record_spsa_history(test):
|
||||
|
||||
names = spsa_param_names(test)
|
||||
history = load_spsa_history(test) or {}
|
||||
|
||||
# Parameters were renamed, or reordered. Start over
|
||||
if history.get('names') != names:
|
||||
history = { 'names' : names, 'points' : [] }
|
||||
|
||||
point = [int(test.games)]
|
||||
point += [round(float(test.spsa['parameters'][name]['value']), 4) for name in names]
|
||||
|
||||
points = history['points']
|
||||
if points and points[-1][0] == point[0]:
|
||||
points[-1] = point
|
||||
else:
|
||||
points.append(point)
|
||||
|
||||
# Keep the file bounded: drop every other point, but always keep the latest
|
||||
if len(points) > SPSA_HISTORY_MAX_POINTS:
|
||||
last = points[-1]
|
||||
points = points[::2]
|
||||
if points[-1] is not last:
|
||||
points.append(last)
|
||||
|
||||
history['points'] = points
|
||||
write_json_file(spsa_history_path(test.id), history)
|
||||
|
||||
def extract_option(options, option):
|
||||
|
||||
match = re.search(r'(?<={0}=")[^"]*'.format(option), options)
|
||||
@@ -575,6 +630,7 @@ def update_test(request, machine):
|
||||
|
||||
test = Test.objects.select_for_update().get(id=test_id)
|
||||
should_record_llr = False
|
||||
should_record_spsa = False
|
||||
|
||||
if test.finished or test.deleted:
|
||||
return { 'stop' : True }
|
||||
@@ -625,6 +681,7 @@ def update_test(request, machine):
|
||||
param['value'] = max(param['min'], min(param['max'], x))
|
||||
|
||||
test.finished = test.games >= 2 * test.spsa['pairs_per'] * test.spsa['iterations']
|
||||
should_record_spsa = True
|
||||
|
||||
elif test.test_mode == 'DATAGEN':
|
||||
|
||||
@@ -633,6 +690,12 @@ def update_test(request, machine):
|
||||
|
||||
test.save()
|
||||
|
||||
if should_record_spsa:
|
||||
try:
|
||||
record_spsa_history(test)
|
||||
except Exception:
|
||||
pass # History is a nicety, and must never fail a result upload
|
||||
|
||||
if should_record_llr:
|
||||
record_llr_history(test)
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
{% block scripts %}
|
||||
<link rel="stylesheet" href="{% static 'workload.css' %}?{{ static_version }}">
|
||||
<link rel="stylesheet" href="{% static 'spsa_panel.css' %}?{{ static_version }}">
|
||||
<link rel="stylesheet" href="{% static 'spsa_chart.css' %}?{{ static_version }}">
|
||||
<script src="{% static 'spsa_chart.js' %}?{{ static_version }}" defer></script>
|
||||
<script src="{% static 'spsa_panel.js' %}?{{ static_version }}" defer></script>
|
||||
<script src="{% static 'copy_text.js' %}?{{ static_version }}"></script>
|
||||
<script src="{% static 'llr_history.js' %}?{{ static_version }}" defer></script>
|
||||
@@ -15,10 +17,11 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="workload-container">
|
||||
<div class="workload-container{% if type == "TUNE" %} tune-page{% endif %}">
|
||||
{% if type == "TUNE" %}<div class="tune-side">{% endif %}
|
||||
|
||||
<div id="config" class="card">
|
||||
<header class="card-head"><h2 class="card-title">Configuration</h2></header>
|
||||
{% if type == "TUNE" %}<details id="config" class="card config-fold"><summary><span class="card-title">Settings</span><span class="config-hint">Engine, network, book</span></summary>{% else %}<div id="config" class="card">{% endif %}
|
||||
{% if type != "TUNE" %}<header class="card-head"><h2 class="card-title">Configuration</h2></header>{% endif %}
|
||||
<table class="test-config left-align wrappable">
|
||||
|
||||
<tr><td class="td-label">Author</td><td>{{workload.author|capfirst}}</td></tr>
|
||||
@@ -69,7 +72,7 @@
|
||||
{% endif %}
|
||||
|
||||
</table>
|
||||
</div>
|
||||
{% if type == "TUNE" %}</details>{% else %}</div>{% endif %}
|
||||
|
||||
<div id="actions" class="card">
|
||||
<header class="card-head"><h2 class="card-title">Actions</h2></header>
|
||||
@@ -214,6 +217,8 @@
|
||||
|
||||
<!-- SPSA Paramater Summary, for Tunes -->
|
||||
{% if type == "TUNE" %}
|
||||
</div><!-- /tune-side -->
|
||||
<div class="tune-main">
|
||||
{% with panel=workload|spsa_param_panel %}
|
||||
<section id="spsa-panel" class="card spsa-panel">
|
||||
<header class="card-head"><h2 class="card-title">Tuning progress</h2></header>
|
||||
@@ -231,6 +236,14 @@
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="spsa-history">
|
||||
<div class="spsa-history-head">
|
||||
<h3>Movement since the start</h3>
|
||||
<p>Each line is one parameter, as a share of its allowed range. Point at a name below to follow it, or click it to keep it on the chart.</p>
|
||||
</div>
|
||||
{{ workload|spsa_history_chart }}
|
||||
</div>
|
||||
|
||||
<div class="spsa-tools">
|
||||
<input id="spsa-filter" type="search" placeholder="Filter parameters" aria-label="Filter parameters by name" autocomplete="off">
|
||||
<select id="spsa-sort" aria-label="Sort parameters">
|
||||
@@ -243,7 +256,7 @@
|
||||
<ol id="spsa-rows" class="spsa-rows">
|
||||
{% for p in panel.params %}
|
||||
<li class="spsa-row{% if p.bound %} at-bound{% endif %}" data-name="{{ p.name|lower }}" data-drift="{{ p.drift }}" data-index="{{ forloop.counter0 }}">
|
||||
<span class="spsa-name">{{ p.name }}</span>
|
||||
<button type="button" class="spsa-name" aria-pressed="false" title="Show on the chart">{{ p.name }}</button>
|
||||
<div class="spsa-track-wrap">
|
||||
<div class="spsa-track" role="img" aria-label="{{ p.name }} is {{ p.value }}, within {{ p.min }} to {{ p.max }}, started at {{ p.start }}{% if p.bound %}, at its {{ p.bound }} limit{% endif %}" title="Start {{ p.start }}, now {{ p.value }}, C {{ p.c }}, R {{ p.r }}{% if p.bound %}. At its {{ p.bound }} limit.{% endif %}">
|
||||
<span class="spsa-drift" style="left: {{ p.left }}%; width: {{ p.width }}%"></span>
|
||||
@@ -267,8 +280,9 @@
|
||||
</section>
|
||||
{% endwith %}
|
||||
|
||||
<div id="parameters" class="card">
|
||||
<header class="card-head"><h2 class="card-title">Parameter details</h2></header>
|
||||
<details id="parameters" class="card config-fold">
|
||||
<summary><span class="card-title">Parameter details</span><span class="config-hint">Start, limits, C and R</span></summary>
|
||||
|
||||
<table class="stripes wrappable">
|
||||
|
||||
<tr class="table-header">
|
||||
@@ -289,7 +303,7 @@
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
||||
|
||||
<div id="results" class="card">
|
||||
@@ -323,6 +337,7 @@
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% if type == "TUNE" %}</div><!-- /tune-main -->{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user