Skip to content
Projects

opencr.ml.dataset

Datasets of CR solutions for surrogates, with provenance and reproducible splits.

generate_dataset samples conditions in given ranges (log-uniform, by a seeded Latin hypercube) and solves the model at each sample, storing the inputs, the quantities (opencr.analysis.quantities) and the provenance: the model’s manifest digest, the OpenCR version, the sampling and the seed. The split into training, validation and test sets is part of the dataset (split), drawn from its own seed, so every surrogate trained on the dataset sees the same split.

Attributes

NameDescription
SPLITSNo description.

Functions

NameDescription
generate_datasetSolve model at log-uniform samples of the condition fields in bounds.
manifest_digestReturn the SHA-256 of the model's manifest (states, reactions, data).
split_indicesReturn the split label (0 train, 1 validation, 2 test) of each sample.

SPLITSattributemodule attribute#

SPLITS = ('train', 'validation', 'test')

generate_datasetfunction#

def generate_dataset(model: Model, conditions: Conditions, bounds: Mapping[str, tuple[float, float]], outputs: Sequence[str], samples: int = 200, seed: int = 0, mode: str = 'quasi-static', fractions: Sequence[float] = (0.7, 0.15, 0.15)) -> xr.Dataset

Solve model at log-uniform samples of the condition fields in bounds.

Parameters

NameTypeDefaultDescription
modelModelrequiredThe model.
conditionsConditionsrequiredThe conditions the sampled fields are set in.
boundsMapping[str, tuple[float, float]]requiredThe range of each sampled field (as for opencr.scan: electron_temperature, electron_density, density:<state>), in eV or m^-3, or quantities.
outputsSequence[str]requiredThe quantities to store.
samplesint200The number of samples.
seedint0The seed of the sampling; the split uses seed + 1.
modestr'quasi-static'The steady-state mode.
fractionsSequence[float](0.7, 0.15, 0.15)The train, validation and test fractions.

Returns

xr.Dataset
A dataset over sample with inputs (sample, parameter),
xr.Dataset
outputs (sample, output), split (0, 1, 2 for train, validation,
xr.Dataset
test) and the provenance in its attributes (with solve_time, the
xr.Dataset
solver’s time per sample in s).

manifest_digestfunction#

def manifest_digest(model: Model) -> str

Return the SHA-256 of the model’s manifest (states, reactions, data).

split_indicesfunction#

def split_indices(samples: int, fractions: Sequence[float] = (0.7, 0.15, 0.15), seed: int = 0) -> np.ndarray

Return the split label (0 train, 1 validation, 2 test) of each sample.