---
title: Experiments
description: An experiment board that compares training runs by curves, a hyperparameter sweep, and configs.
category: TemplateData
status: beta
since: 0.9.1
tags: [template, ml, training, charts, comparison]
syncStatus: reviewed
verified: false
---

> **Template constraints (docs site)**: the rules below come from the Nexus template spec. Follow them when you rewrite or reproduce this page.
>
> - Put the whole page inside `TemplateFrame`, which owns expand, collapse and sizing. Do not import `Tx*` components explicitly; they are auto-registered.
> - Start scripted playback from `@enter`, never from `onMounted`.
> - Bind keyboard shortcuts on the template root, never on `window` or `document`.
> - Show feedback in a `TxToastPanel` inside the stage. Do not use `toast()`, `clearToasts()`, `TxToastHost`, `TxTouchTip`, `TxBottomDialog` or `TxBlowDialog`.
> - The full rules are in `docs/engineering/specs/frontend/nexus-docs-templates.md`.

## Usage

### Run comparison
:::TuffDemoWrapper{demo="TemplateExperimentsDemo" code-lang="vue" description="Once in view, r6 trains on from step 1,200 to the end in about 6 seconds; stop it, tick the runs to compare, or switch the metric at any time."}
---
code: |
  <script setup lang="ts">
  import type { HeatmapSelection, LearningCurveRun } from '@talex-touch/tuffex/charts'
  import { ChartPalette } from '@talex-touch/tuffex/charts'
  import { computed, reactive, ref } from 'vue'
  import TemplateFrame from './TemplateFrame.vue'

  // Six runs from a seeded generator: train/loss every 50 steps, validation every 200
  const live = reactive({ step: 1200, status: 'running' }) // r6 is still training
  const metric = ref('valAcc') // valAcc, valLoss or trainLoss
  const compared = ref(['r1', 'r2', 'r3', 'r4', 'r5', 'r6'])
  const view = ref<[number, number] | null>(null) // the step range a drag zoomed into

  // Each curve takes the chart palette's Nth colour; its row checkbox wears the same one
  const RUN_COLOR = Object.fromEntries(RUNS.map((run, index) => [run.id, ChartPalette.categoricalVar(index)]))
  const curveRuns = computed<LearningCurveRun[]>(() => RUNS.map(run => ({
    name: run.id,
    color: RUN_COLOR[run.id],
    data: run.id === 'r6'
      ? SERIES.r6[metric.value].filter(([step]) => step <= live.step)
      : SERIES[run.id][metric.value],
  })))

  // Hides the scale bar but keeps the colour mapping; one object, since TxEChart redraws on every new option
  const HEAT_OPTION = { visualMap: { show: false }, tooltip: { formatter: heatTooltip } }

  // After @enter, 80 steps every 100ms reach step 6,000 in about 6 seconds; Stop clears the timer
  function tick() {
    live.step = Math.min(6000, live.step + 80)
    if (live.step < 6000)
      later(100, tick)
    else
      finish() // marks the run finished and opens the TxToastPanel
  }

  // Boxing heatmap cells compares only those runs; clearing the box restores the comparison
  function onHeatSelect(selection: HeatmapSelection | null) {
    compared.value = selection
      ? selection.cells.map(cell => GRID_RUNS[cell.row][cell.column])
      : beforeBox
  }
  </script>

  <template>
    <TemplateFrame title="Experiments" @enter="start">
      <template #default="{ width, height }">
        <header class="exp-head">
          <TxWorkingIndicator v-if="live.status === 'running'" variant="dots" label="Training r6" :show-elapsed="false" />
          <TxFlatRadio v-model="metric" size="sm">
            <TxFlatRadioItem value="valAcc" label="val/acc" />
            <TxFlatRadioItem value="valLoss" label="val/loss" />
            <TxFlatRadioItem value="trainLoss" label="train/loss" />
          </TxFlatRadio>
          <TxButton size="sm" icon="i-carbon-stop-filled-alt" @click="stop">Stop</TxButton>
        </header>

        <section class="exp-chart">
          <TxChartLegendItem
            v-for="run in RUNS" :key="run.id" :name="run.id" :color="RUN_COLOR[run.id]"
            :inactive="!compared.includes(run.id)" @click="toggle(run.id)"
          />
          <TxLearningCurve
            v-model:window="view" :runs="curveRuns" :hidden-runs="hidden" :highlighted-run="hovered"
            x-axis-name="Training step" :y-axis-name="METRIC_LABEL[metric]" :height="chartHeight(width, height)"
          />
        </section>

        <aside class="exp-side">
          <TxHeatmapChart
            :values="heatValues" :rows="['bs 64', 'bs 128']" :columns="['lr 1e-4', 'lr 3e-4', 'lr 1e-3']"
            :min="0.75" :max="0.92" show-label :selectable="heatSelectable" :option="HEAT_OPTION"
            @select="onHeatSelect" @click="focusCell"
          />
          <TxDescriptions size="sm" :columns="1">
            <TxDescriptionsItem v-for="item in configItems" :key="item.key" :label="item.label">
              {{ item.value }}
            </TxDescriptionsItem>
          </TxDescriptions>
        </aside>

        <TxDataTable
          row-key="id" :columns="columns" :data="rows" :row-class="rowClass" sticky-header
          @row-click="({ row }) => (focused = row.id)"
        >
          <template #cell-pick="{ row }">
            <!-- The checkbox wears its run's curve colour; @click.stop keeps it from also clicking the row -->
            <span :style="PICK_STYLE[row.id]" @click.stop>
              <TxCheckbox :model-value="compared.includes(row.id)" @update:model-value="toggle(row.id)" />
            </span>
          </template>
          <template #cell-status="{ row }">
            <TxStatusBadge size="sm" :status="STATUS_TONE[row.status]" :text="STATUS_TEXT[row.status]" />
          </template>
        </TxDataTable>
      </template>
    </TemplateFrame>
  </template>

  <style scoped>
  /* Layout follows TemplateFrame's container width only: < 640 three tabs, 640–959 side tabs, ≥ 960 all three regions */
  @container template (min-width: 960px) {
    .exp-body { grid-template-areas: 'chart side' 'runs side'; }
  }
  </style>
---
:::

## Overview

A board comparing the training runs of `corebox-intent-mini`, the on-device classifier that sorts a CoreBox query into one of 12 intents, laid out like TensorBoard or W&B: six runs sweep a learning rate × batch size grid, and one of them, r6, is still training. Every number is sample data from a seeded generator, so each render draws the same runs.

- The first time it scrolls into view, r6 trains on from step 1,200 and reaches step 6,000 in about 6 seconds: its curve grows, its best value and duration update in the runs table, and near step 4,600 it overtakes r3 as the best run, taking the trophy with it. It then reads Finished and a toast says "r6 finished · best 0.912 (sample data)"; the toast closes after 3.2 seconds and stays open while the pointer or focus rests on it. With reduced motion it shows the finished state at once, with no timers and no toast.
- Stop interrupts r6 at any time: it reads Stopped, a toast gives the step it stopped at, and the button becomes Resume, which trains on from there. Once the run has finished the button is disabled.
- Choose the runs to compare in three ways: click legend items; tick the first column of the runs table (each checkbox wears its curve's colour, and the header ticks all or none); or drag across cells of the sweep heatmap to compare only those runs. Click any cell or press Escape to clear the box and restore the comparison from before it; using the legend or the checkboxes while boxed lets the box go. While the pointer or focus rests on a legend item or a table row, that run's curve stays clear and the others dim.
- Click a row of the runs table (or Tab to it and press Enter) or a heatmap cell to see that run's config; the header switches the curves between val/acc, val/loss and train/loss. Drag across the curves to zoom into a range of steps, and drag a zoomed chart to pan; double-click the curves or click the Zoomed chip at the top right to see every step again.
- The data tells a few typical stories: r4's learning rate is too high, so its loss diverges after about step 1,900 and the run is killed at 2,150; r5 over-fits after about step 2,800, and its val/loss climbs back; r2 was stopped by hand at step 3,200.
- Wide (≥ 960px) shows the curves, the side column (sweep above config) and the runs table together; at 640–959px the side panel beside the curves switches between Sweep and Config tabs; narrow (< 640px) splits the board into Curves / Runs / Sweep tabs, with the config under the runs table or the heatmap.

## Customization

- To use real runs, give each one its scalars as `[step, value]` arrays, as TensorBoard scalars or a W&B history export provide them; for a config trained under several seeds, pass `seeds` instead and the curve becomes their mean with a ± one-standard-deviation band. Replace the timed stream with the points your trainer pushes (SSE / WebSocket).
- The chart palette has six colours and cycles by position, so a seventh run would share the first run's colour; with more runs, give each curve its own `color` and use the same value for its table checkbox (`PICK_STYLE`).
- TxHeatmapChart keeps its box to itself, with no controlled prop: to clear it from outside, turn `selectable` off for one tick and back on (the template's `dropBox()`), which neither remounts the chart nor starts ECharts over. Cell labels print the values as they are, and `option` replaces arrays when it merges, so there is no way to reformat only the series labels; that is why every sample value has three decimals and no trailing zero. Customize the tooltip with `option.tooltip.formatter`.
- Keep `option` one object: TxEChart re-themes and redraws the whole chart on every new `option`, and each time r6's best improves, the heatmap redraws once. Hide the scale bar with `option.visualMap.show = false`, not `:visual-map="false"`, which also drops the colour mapping.
- The first column is not TxDataTable's own `selectable`: that checkbox's accessible name is fixed to the English Select row, and it cannot take a colour per row. TxDataTable has no row hover event either, so the template listens for `pointerover` / `focusin` around it and reads the run from the row's `data-run` to emphasize its curve.

## Related components

| Region | Components | Role |
|---|---|---|
| Header | [TxWorkingIndicator](/docs/dev/components/working-indicator), [TxStatusBadge](/docs/dev/components/status-badge), [TxFlatRadio](/docs/dev/components/flat-radio), [TxButton](/docs/dev/components/button) | r6's state, the curve metric, and Stop / Resume |
| Curves | [TxLearningCurve](/docs/dev/components/learning-curve), [TxChartLegendItem](/docs/dev/components/charts) | Smoothed runs side by side, zoom, and legend toggles |
| Runs table | [TxDataTable](/docs/dev/components/data-table), [TxCheckbox](/docs/dev/components/checkbox), [TxStatusBadge](/docs/dev/components/status-badge) | Picking runs to compare, status, hyperparameters and bests |
| Sweep | [TxHeatmapChart](/docs/dev/components/echart-charts) | Best val/acc by lr × batch; boxing cells compares them |
| Config | [TxDescriptions](/docs/dev/components/descriptions), [TxTag](/docs/dev/components/tag) | The focused run's hyperparameters and environment |
| Tabs (column / narrow) | [TxFlatRadio](/docs/dev/components/flat-radio) | Sweep / Config, or Curves / Runs / Sweep |
| Finish notice | [TxToastPanel](/docs/dev/components/toast-panel) | A result card that closes after 3.2 seconds |
