Skip to content

amisc.typing

Module with type hints for the AMISC package.

Includes:

  • MultiIndex — tuples of integers or similar string representations
  • Dataset — a type hint for the input/output dicts handled by Component.model
  • TrainIteration — the results of a single training iteration
  • CompressionData — a dictionary spec for passing data to/from Variable.compress()
  • LATENT_STR_ID — a string identifier for latent coefficients of field quantities

CompressionData

Bases: TypedDict

Configuration dict for passing compression data to/from Variable.compress().

Field quantity shapes

Field quantity data can take on any arbitrary shape, which we indicate with qty.shape. For example, a 3d structured grid might have qty.shape = (10, 15, 10). Unstructured data might just have qty.shape = (N,) for \(N\) points in an unstructured grid. Regardless, Variable.compress() will flatten this and compress to a single latent vector of size latent_size. That is, qty.shapelatent_size.

Compression coordinates

Field quantity data must be specified along with its coordinate locations. If the coordinate locations are different from what was used when building the compression map (i.e. the SVD data matrix), then they will be interpolated to/from the SVD coordinates.

ATTRIBUTE DESCRIPTION
coords

(qty.shape, dim) the coordinate locations of the qty data; coordinates exist in dim space (e.g. dim=2 for 2d Cartesian coordinates). Defaults to the coordinates used when building the construction map (i.e. the coordinates of the data in the SVD data matrix)

TYPE: ndarray

latent

(..., latent_size) array of latent space coefficients for a field quantity; this is what is returned by Variable.compress() and what is expected as input by Variable.reconstruct().

TYPE: ndarray

qty

(..., qty.shape) array of uncompressed field quantity data for this qty within the fields list. Each qty in this list will be its own key:value pair in the CompressionData structure

TYPE: ndarray

Dataset

Bases: TypedDict

Type hint for the input/output dicts of a call to Component.model. The keys are the variable names and the values are the corresponding np.ndarrays. There are also a few special keys that can be returned by the model that are described below.

The model can return additional items that are not part of Component.outputs. These items are returned as object arrays in the output.

This data structure is very similar to the Dataset class in the xarray package. Later versions might consider migrating to xarray for more advanced data manipulation.

ATTRIBUTE DESCRIPTION
model_cost

the computational cost (seconds of CPU time) of a single model evaluation

TYPE: float | list | ArrayLike

output_path

the path to the output file or directory written by the model

TYPE: str | Path

errors

a dict with the indices where the model evaluation failed with context about the errors

TYPE: dict

MultiIndex

Bases: tuple

A multi-index is a tuple of integers, can be converted from a string.

TrainIteration

Bases: TypedDict

Gives the results of a single training iteration.

ATTRIBUTE DESCRIPTION
component

the name of the component selected for refinement at this iteration

TYPE: str

alpha

the selected candidate model fidelity multi-index

TYPE: MultiIndex

beta

the selected candidate surrogate fidelity multi-index

TYPE: MultiIndex

num_evals

the number of model evaluations performed during this iteration

TYPE: int

added_cost

the total added computational cost of the new model evaluations

TYPE: float

added_error

the error/difference between the refined surrogate and the previous surrogate

TYPE: float

test_error

the error of the refined surrogate on the test set (optional)

TYPE: Optional[dict[str, float]]