# Adding your own code

> Teach HiveBoard a simulation code it does not know, or replace a built-in one: one YAML spec in the engines folder of the data folder, then a restart.

Source: https://hiveboard.dev/docs/codes/your-own-codes · Section: Simulation codes · HiveBoard 0.1.7 · Updated 2026-10-19

## In short

- A simulation code is one YAML file, its spec. Put it in the engines folder of HiveBoard's data folder and start HiveBoard again.
- A file whose id is that of a built-in code replaces that code whole.
- Connections → Settings → Simulation codes shows the folder, every code that loaded, and every file that was refused, with the reason.
- A file that fails a check is skipped whole, so a typo can never half-apply.

HiveBoard reads twenty codes out of the box, but nothing about a code is
written into the program itself: each one is a YAML file, its **spec**, that
says which files a job folder holds, how to recognise them, and what to read
from them. To add a code — your group's own program, or one HiveBoard does not
carry — you write such a file and put it in the `engines` folder of HiveBoard's
data folder. No change to HiveBoard is needed.

The format is the one the built-in codes use, described key by key in the
[engine spec reference](/docs/codes/engine-spec-reference). This page is about
where the file goes and how to tell whether it worked.

## Where the file goes

Into the `engines` folder inside [the data folder](/docs/settings/data-folder) —
normally `~/.hiveboard/engines/`. The exact path is under **Your own codes** in
Connections → Settings → **Simulation codes**, with a **Copy** button. Create
the folder if it is not there yet.

- Only files ending in `.yaml` are read (not `.yml`).
- Save the file as UTF-8 text; a file in another encoding is refused.
- One file per code. The file name does not matter; the `id` inside it does.

## Adding a code, step by step

1. Write the spec and save it as, say, `mycode.yaml`.
2. Put it in the `engines` folder.
3. Quit HiveBoard and start it again: specs are read once, at start-up. On
   Windows, quit from the tray icon's menu, **Quit HiveBoard**.
4. Open Connections → Settings → **Simulation codes**. Your code is in the
   table, marked **yours**, with **Your own file** under **From**.
5. Every server set to all codes now looks for it. A server limited to some
   codes needs it ticked on its **Software** tab
   ([codes per server](/docs/codes/codes-per-server)).

> [!WARNING]
> Quitting HiveBoard ends every sign-in. A server that needs a password, a
> one-time code or a key's passphrase waits for you to sign in again.

## A small example

A made-up program, *MyCode*, reads an input `*.mci` and writes an output
`*.mco` that starts with `MyCode version …` and prints `Total energy = …` once
per step. This spec recognises it, tells an optimisation from a single point,
and draws progress, two numbers and a chart:

```yaml
schema: 1
id: mycode
name: MyCode
short: MyCode
family: other
summary: Our group's own solver
appearance:
  hue: 30
  glyph: flask

files:
  input:
    patterns: ["*.mci"]
    note: Input deck
  output:
    patterns: ["*.mco"]
    note: Main output

detect:
  listing:
    strong: ["*.mci", "*.mco"]
  content:
    output: ['MyCode version \d']

reads:
  tail:
    file: output
    how: tail
    bytes: 20000
  energies:
    file: output
    how: grep
    needle: "Total energy ="
    max: 400
  nsteps:
    file: output
    how: count
    needle: "Total energy ="

kinds:
  - id: opt
    label: Optimisation
    glyph: relax
    when:
      input: '(?im)^\s*task\s*=\s*opt'
  - id: single
    label: Single point
    glyph: bolt

values:
  energy:
    from: energies
    regex: '=\s*(?P<v>-?\d+\.\d+)'
  energies:
    from: energies
    regex: '=\s*(?P<v>-?\d+\.\d+)'
    take: all
  steps:
    from: nsteps
    regex: '(?P<v>\d+)'
    type: int
  maxsteps:
    from: input
    regex: '(?i)maxsteps\s*=\s*(?P<v>\d+)'
    type: int
    default: 100

status:
  finished:
    from: tail
    regex: 'MyCode finished'

progress:
  - when: ["kind=opt"]
    done: steps
    total: maxsteps
    unit: step

metrics:
  - label: Energy
    value: "{energy:.6f} Ha"
  - label: Steps
    value: "{steps} / {maxsteps}"
    when: ["kind=opt"]

series:
  - label: Energy per step
    y: energies
    x_label: step
    y_label: "E − E_last (Ha)"
    transform: relative_last

headlines:
  - when: [finished]
    text: "Finished after {steps} steps."
  - when: ["kind=opt"]
    text: "Optimising: step {steps} of {maxsteps}."
```

What each part does:

- **`files`** names the two roles, `input` and `output`; everything else
  refers to these roles, never to file names. Each `note` is what the Files
  tab shows in its **What it is** column.
- **`detect`** says a folder holding `*.mci` or `*.mco` may be MyCode, and
  that the banner at the top of the output proves it.
- **`reads`** fetches the end of the output, the lines holding
  `Total energy =` (the last 400) and a count of them. With the top of the
  input, that is all the summary command reads.
- **`kinds`** calls a job an optimisation when its input says `task = opt`,
  and a single point otherwise (the last kind is the default).
- **`values`** turns the text into numbers: the last energy, all of them for
  the chart, the step count, and the step limit from the input (100 when the
  input does not say).
- **`progress`**, **`metrics`**, **`series`** and **`headlines`** say what
  the job pane shows.

With this file in place, a running job whose folder holds an input with
`task = opt` and `maxsteps = 50`, and an output with three energies so far, is
tagged MyCode · Optimisation. Its pane reads "Optimising: step 3 of 50.", the
progress bar stands at 6 %, the **Energy** and **Steps** cards show the last
energy and `3 / 50`, and the chart has three points.

## Replacing a built-in code

A file whose `id` is that of a built-in code — `qe`, `lammps`, any of the
twenty — replaces the built-in spec. It replaces it **whole**: nothing of the
built-in spec is kept or merged, so your file has to say everything the code
needs. In the catalogue that code then reads **Your own file**.

## When a file is refused

Every spec is checked when HiveBoard starts. A file that fails a check is
skipped whole — a typo cannot half-apply — and the reason is kept:

- Settings → **General** says how many code files could not be loaded, with a
  link, **see why**.
- Settings → **Simulation codes** opens with a card listing each refused file
  and what is wrong with it.

The message names the file, the place in it and the problem. A misspelt key,
for example (wrapped here to fit):

```text
mycode.yaml (mycode).reads.tail: unknown key(s)
['bites']. Known here: ['bytes', 'file', 'first',
'how', 'icase', 'max', 'needle'].
```

The usual causes are a misspelt key (unknown keys are refused, not ignored), a
regular expression that only one of HiveBoard's two builds would read the same
way, a file-name pattern with a character a shell would act on, or a role, read
or value that is used but never defined. Fix the file and start HiveBoard
again. The rules are in the [spec reference](/docs/codes/engine-spec-reference).

## Removing a code

Delete the file, or move it out of the folder, and start HiveBoard again. A
server limited to that code alone then recognises nothing until you choose its
codes again on its **Software** tab.

## On another computer

The `engines` folder is part of the data folder: copy it along with the rest.
Two things do not carry it:

- `--portable` copies your settings, keys and trusted hosts into the portable
  folder, but not `engines` ([portable mode](/docs/settings/portable-mode)).
- An export of your servers carries which codes each server looks for, not the
  specs. On import, a code that computer does not know is dropped from the
  server's list ([export and import](/docs/connections/export-import)).

> [!BUILD]
> The Python build reads the same folder and the same format. It also has a
> tool for trying a spec on a job folder on your own computer, through the very
> commands HiveBoard sends to a cluster:
> `python -m hiveboard.engines.check <folder>` prints the code it chose, the
> kind, headline, progress, numbers, charts, warnings and geometry, and
> `--commands` adds the shell commands it ran.

## Check yourself

1. You saved a corrected spec into the engines folder while HiveBoard was running. When does it take effect?
   - The next time HiveBoard starts ← the answer
   - At the next refresh of the job list
   - When you open a job of that code
   - Immediately
   Why: Specs are read once, at start-up; quit HiveBoard and start it again.

2. Your file has the id qe, like the built-in Quantum ESPRESSO spec. What happens?
   - Your file replaces the built-in spec whole ← the answer
   - The two are merged key by key
   - Yours is refused as a duplicate
   - Both are tried and the higher priority wins
   Why: A file whose id matches a built-in code replaces it; nothing of the built-in one is kept.

## Try it in the app

- Open Connections → Settings → **Simulation codes** and copy the folder named under **Your own codes**.

## Related

- [Engine spec reference](https://hiveboard.dev/docs/codes/engine-spec-reference.md)
- [How codes are recognised](https://hiveboard.dev/docs/codes/how-codes-are-recognised.md)
- [Codes per server](https://hiveboard.dev/docs/codes/codes-per-server.md)
- [The data folder](https://hiveboard.dev/docs/settings/data-folder.md)
