/** * Reads a training run config into the schema's defaults and types it. * * `#training/config/admission` checks the corpus sources a typed config admits, and * `#training/config/resolved` writes the versioned resolved config the Rust trainer and sampler read. * * The merge and coercion reproduce those of the deleted Python loader (`config/load.py`). * A known key replaces the default and an unknown key is refused with its dotted path and file. * * A numeric string converts only under a field annotated exactly `int` or `float`. * The three held-out floor lists are validated with the Python loader's messages. * * The resolver then refuses three values the Python loader admits. * The first is a non-string `country_weights` key. * * `DataConfig.__post_init__` refuses it only at construction, and a loaded * YAML is merged after construction. * The second is a value whose type its field doesn't declare. * * The third is a mapping key that a JSON object reader would move out of its YAML position. */ import { type CountrySet } from "@mailwoman/codex/country/sets"; import type { PathBuilderLike } from "path-ts"; import { type PythonMapping, type PythonValue } from "#training/config/python-yaml"; import { type ConfigSectionSpec, type TrainingConfig } from "#training/config/schema"; /** * The Python exception class a refusal corresponds to, so a comparison with * the Python loader reads one field. */ export declare const ConfigErrorKind: { readonly Key: "KeyError"; readonly Type: "TypeError"; readonly Value: "ValueError"; }; export type ConfigErrorKind = (typeof ConfigErrorKind)[keyof typeof ConfigErrorKind]; /** * A config the loader refuses, with the message the Python loader raises for it. */ export declare class TrainingConfigError extends Error { readonly kind: ConfigErrorKind; constructor(kind: ConfigErrorKind, message: string); } /** * One dataclass instance as the loader fills it: each declared field's current value. */ export interface ConfigInstance { spec: ConfigSectionSpec; values: Map; } /** * A field's value: a YAML value, a nested section, or a floor list's entries. */ export type ConfigValue = PythonValue | ConfigInstance | ConfigInstance[]; /** * A dataclass instance holding every default, as `Config()` builds it. */ export declare function defaultConfigInstance(spec?: ConfigSectionSpec): ConfigInstance; interface MergeContext { strict: boolean; path: string; source: string; } /** * Merges `src` into `dst` key by key, as `merge_into` does. * * A key the dataclass doesn't declare is refused under `strict` and skipped otherwise. * A mapping under a nested section merges into it, and every other value replaces * the field through {@linkcode coerceField}. * * @throws {TrainingConfigError} naming the dotted key and the config source. */ export declare function mergeIntoConfig(dst: ConfigInstance, src: PythonMapping, context?: Partial): void; /** * Options for {@linkcode readTrainingConfig}. */ export interface ReadTrainingConfigOptions { /** * Refuses an unknown key. * * Every training entry point stays strict, because a skipped key leaves a setting at its default. * Only tooling that reads part of a config turns it off. * * @default true */ strict?: boolean; } /** * Loads YAML text over the schema defaults, as `load_config` loads a file. * `source` names the file in a refusal. * * @throws {TrainingConfigError} for an unknown key, a malformed floor list or a non-string country key. */ export declare function readTrainingConfigText(text: string, source: string, options?: ReadTrainingConfigOptions): ConfigInstance; /** * Loads the YAML file at `path` over the schema defaults, as `load_config` does. */ export declare function readTrainingConfig(path: PathBuilderLike, options?: ReadTrainingConfigOptions): Promise; /** * Checks a loaded config's values against their declared types and returns them as JSON values. * * @throws {TrainingConfigError} naming every field whose value its declaration doesn't admit. */ export declare function typedTrainingConfig(config: ConfigInstance, source: string): TrainingConfig; /** * The countries a config admits: the `data.country_weights` keys with a positive weight, in key order. * * A country at weight zero admits no row. * * @throws {TypeError} When a key isn't an ISO 3166-1 alpha-2 code, naming the config. */ export declare function weightedCountries(config: TrainingConfig, source?: string): WeightedCountries; /** * The branded set {@linkcode weightedCountries} returns. */ export type WeightedCountries = CountrySet<{ declaredBy: string; }>; /** * The version of the built corpus a config trains on: `data.corpus_dir`'s last segment without `corpus-`. */ export declare function trainingCorpusVersion(config: TrainingConfig): string; /** * `train.csv_log_path` with `{output_dir}` filled, as Python's `str.format` fills it. * * @throws When the template names another field. */ export declare function trainingCSVLogPath(config: TrainingConfig): string; export {}; //# sourceMappingURL=load.d.ts.map