Skip to main content

judge.write_run_toml

judge.write_run_toml(out, record)

Write run.toml into out and return its text.

Scalars and lists of scalars of record are top-level keys and come first; each mapping becomes a [table]; each non-empty list of mappings becomes an array of tables [[name]]. Every key of record is written or the call raises: nothing is dropped. Keys that are not bare-key safe are quoted. The text is parsed again with tomllib and must give back record, and the file is replaced atomically, so a failure leaves neither a run.toml nor a temporary file behind (an existing one stays as it was). The file has mode 0644.

Parameters

Name Type Description Default
out Path The run directory. required
record Mapping[str, object] The run record. required

Returns

Name Type Description
str str The text that was written.

Raises

Name Type Description
ValueError If a key is not a string, a value is None or has no TOML form, the text does not encode as UTF-8, or the parsed text differs from record.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen.judge import write_run_toml

with TemporaryDirectory() as tmp:
    text = write_run_toml(
        Path(tmp),
        {
            "unit": "core.calc",
            "generator": {"model": "m"},
            "attempt": [{"n": 1, "evaluations_failed": 0}],
        },
    )
    print(text)
unit = "core.calc"

[generator]
model = "m"

[[attempt]]
n = 1
evaluations_failed = 0