nnpd.core.api

The extension surface. No Gaussian settings or metric names live here.

Classes

Product

A reusable dataset; dependencies are resolved and cached before build().

Metric

Plot

Experiment

What is trained: problem, prior, training data, model and training procedure.

Analysis

What is computed from trained models: shared datasets, metrics and plots. Never trains.

Context

Functions

implementation_hash(→ dict)

Hash complete source modules, not just the registration function.

load_experiment(→ Experiment)

Instantiate the trusted module:class named by "experiment" in the training settings.

load_analysis(→ Analysis)

Instantiate the trusted module:class named by "analysis" in the analysis settings.

Module Contents

nnpd.core.api.implementation_hash(functions: tuple[Callable, ...], version: str) → dict

Hash complete source modules, not just the registration function.

Declare helper modules in Product.sources or Experiment.sources. External simulators/data releases should be identified explicitly in the recipe/version.

class nnpd.core.api.Product

A reusable dataset; dependencies are resolved and cached before build().

build: Callable[[Context, Mapping[str, nnpd.core.storage.Artifact], nnpd.core.storage.Writer], dict]
needs: tuple[str, ...] = ()
settings: Callable[[Context], dict]
sources: tuple[Callable, ...] = ()
version: str = '1'
class nnpd.core.api.Metric
compute: Callable[[Context, Mapping[str, nnpd.core.storage.Artifact]], Any]
needs: tuple[str, ...] = ()
class nnpd.core.api.Plot
draw: Callable[[Context, Mapping[str, nnpd.core.storage.Artifact]], Mapping[str, Any]]
needs: tuple[str, ...] = ()
class nnpd.core.api.Experiment

Bases: abc.ABC

What is trained: problem, prior, training data, model and training procedure.

Selected by “experiment” in the training settings. The runner owns execution and files.

name = 'experiment'
version = '1'
members(settings: dict) → list[dict]

A fixed comparison cohort within each sweep configuration.

validate(settings: dict) → None

Fail before any sampling or training, including for invalid alternatives.

estimate(settings: dict, member: dict) → dict

Training workload shown by the plan.

abstractmethod make_problem(settings: dict) → Any
abstractmethod make_prior(settings: dict, member: dict, problem: Any) → Any
abstractmethod sample_training(context: Context, writer: nnpd.core.storage.Writer) → dict
abstractmethod build_model(context: Context) → torch.nn.Module
abstractmethod train(context: Context, model: torch.nn.Module) → dict

Modify model in place; return JSON-serializable training history.

signature(stage: str, context: Context) → dict

Override for cross-run sharing; conservative default uses all training settings.

sources(stage: str) → tuple[Callable, ...]

Include modules implementing transitive scientific dependencies.

model_seed(context: Context) → int
class nnpd.core.api.Analysis

What is computed from trained models: shared datasets, metrics and plots. Never trains.

Selected by “analysis” in the analysis settings. “training” and “model” are the reserved datasets every product, metric and plot may depend on.

name = 'analysis'
validate(settings: dict) → None

Fail before anything is computed.

estimate(settings: dict, problem: Any, prior: Any) → dict

Workload of analyzing one trained model; limit violations go in “errors”.

products() → dict[str, Product]
metrics() → dict[str, Metric]
plots() → dict[str, Plot]
nnpd.core.api.load_experiment(specification: str) → Experiment

Instantiate the trusted module:class named by “experiment” in the training settings.

nnpd.core.api.load_analysis(specification: str) → Analysis

Instantiate the trusted module:class named by “analysis” in the analysis settings.

class nnpd.core.api.Context
experiment: Experiment
training_settings: dict
member: dict
store: nnpd.core.storage.Store
runtime: nnpd.core.runtime.Runtime
run_dir: pathlib.Path
analysis: Analysis | None = None
analysis_settings: dict | None = None
problem: Any
prior: Any
artifacts: dict[str, nnpd.core.storage.Artifact]
seed(namespace: str, *, base: int | None = None, member: bool = True) → int
rng(namespace: str, *, base: int | None = None, member: bool = True)
property model: torch.nn.Module
require(name: str) → nnpd.core.storage.Artifact

Get or build a named dataset. Cycles and unknown dependencies fail clearly.

dependencies(names: tuple[str, ...]) → dict[str, nnpd.core.storage.Artifact]