Configuration and I/O¶
schema ¶
Experiment configuration files (YAML) and model references.
Configuration is data only: files are parsed with yaml.safe_load and
validated against a strict schema (unknown keys are errors). The one way a
config can lead to code running is the model: reference, which names a
Python model explicitly - the same trust model as pointing pytest at a
test file. Model files referenced by path must live inside the config file's
directory unless the caller opts out, which prevents ../../ tricks.
loaded_model_files ¶
loaded_model_files() -> dict[str, str]
Module name -> path of model files loaded by path (re-loaded in worker processes).
preload_model_files ¶
preload_model_files(files: Mapping[str, str]) -> None
Worker-process initializer: import user model files under the same module names.
resolve_model ¶
resolve_model(ref: str, *, base_dir: str | Path | None = None, allow_outside: bool = True) -> Model
Resolve builtin:<name>, path/to/file.py[:attr] or package.module:attr.
With allow_outside=False file references must resolve inside base_dir.
build_experiment ¶
build_experiment(config: ExperimentConfig, *, base_dir: str | Path | None = None, allow_outside: bool = False) -> Any
Turn a validated config into a ready-to-run :class:~simulsi.Experiment.
io ¶
Safe, dependency-light export and import of results.
- JSON is always available. NaN and infinities are written as
nullso files stay valid JSON for other tools (browsers reject bareNaN). - CSV uses the standard library.
- Parquet needs the optional
pyarrow+pandasextras.
Loading never uses pickle or eval: only JSON is read back.
to_jsonable ¶
to_jsonable(obj: Any) -> Any
Convert numpy scalars/arrays, dataclasses, tuples and non-finite floats for JSON.
csv_text ¶
csv_text(rows: Sequence[Mapping[str, Any]]) -> str
Dict rows as CSV text; the header is the union of keys in first-seen order.
write_csv ¶
write_csv(rows: Sequence[Mapping[str, Any]], path: str | Path) -> Path
Write dict rows; the header is the union of keys in first-seen order.
safe_child ¶
safe_child(base: str | Path, name: str) -> Path
Resolve base/name and refuse paths that escape base (path traversal).