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
| Name | Description |
|---|---|
SPLITS | No description. |
Functions
| Name | Description |
|---|---|
generate_dataset | Solve model at log-uniform samples of the condition fields in bounds. |
manifest_digest | Return the SHA-256 of the model's manifest (states, reactions, data). |
split_indices | Return 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.DatasetSolve model at log-uniform samples of the condition fields in bounds.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | Model | required | The model. |
conditions | Conditions | required | The conditions the sampled fields are set in. |
bounds | Mapping[str, tuple[float, float]] | required | The range of each sampled field (as for opencr.scan:
electron_temperature, electron_density, density:<state>),
in eV or m^-3, or quantities. |
outputs | Sequence[str] | required | The quantities to store. |
samples | int | 200 | The number of samples. |
seed | int | 0 | The seed of the sampling; the split uses seed + 1. |
mode | str | 'quasi-static' | The steady-state mode. |
fractions | Sequence[float] | (0.7, 0.15, 0.15) | The train, validation and test fractions. |
Returns
xr.Dataset- A dataset over
samplewithinputs(sample, parameter), xr.Datasetoutputs(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) -> strReturn 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.ndarrayReturn the split label (0 train, 1 validation, 2 test) of each sample.