gemseo / caches

simple_cache module

Caching module to store only one entry.

class gemseo.caches.simple_cache.SimpleCache(tolerance=0.0, name=None)[source]

Bases: gemseo.core.cache.AbstractCache

Dictionary-based cache storing a unique entry.

When caching an input data different from this entry, this entry is replaced by a new one initialized with this input data.

Parameters
  • tolerance (float) –

    The tolerance below which two input arrays are considered equal: norm(new_array-cached_array)/(1+norm(cached_array)) <= tolerance. If this is the case for all the input names, then the cached output data shall be returned rather than re-evaluating the discipline. This tolerance could be useful to optimize CPU time. It could be something like 2 * numpy.finfo(float).eps.

    By default it is set to 0.0.

  • name (str | None) –

    A name for the cache. If None, use the class name.

    By default it is set to None.

Return type

None

cache_jacobian(input_data, jacobian_data)[source]

Cache the input and Jacobian data.

Parameters
  • input_data (Mapping[str, Any]) – The data containing the input data to cache.

  • jacobian_data (Mapping[str, Mapping[str, numpy.ndarray]]) – The Jacobian data to cache.

Return type

None

cache_outputs(input_data, output_data)[source]

Cache input and output data.

Parameters
  • input_data (Mapping[str, Any]) – The data containing the input data to cache.

  • output_data (Mapping[str, Any]) – The data containing the output data to cache.

Return type

None

clear()[source]

Clear the cache.

Return type

None

export_to_dataset(name=None, by_group=True, categorize=True, input_names=None, output_names=None)

Build a Dataset from the cache.

Parameters
  • name (str | None) –

    A name for the dataset. If None, use the name of the cache.

    By default it is set to None.

  • by_group (bool) –

    Whether to store the data by group in Dataset.data, in the sense of one unique NumPy array per group. If categorize is False, there is a unique group: Dataset.PARAMETER_GROUP`. If categorize is True, the groups are stored in Dataset.INPUT_GROUP and Dataset.OUTPUT_GROUP. If by_group is False, store the data by variable names.

    By default it is set to True.

  • categorize (bool) –

    Whether to distinguish between the different groups of variables. Otherwise, group all the variables in Dataset.PARAMETER_GROUP`.

    By default it is set to True.

  • input_names (Iterable[str] | None) –

    The names of the inputs to be exported. If None, use all the inputs.

    By default it is set to None.

  • output_names (Iterable[str] | None) –

    The names of the outputs to be exported. If None, use all the outputs.

    By default it is set to None.

Returns

A dataset version of the cache.

Return type

Dataset

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
property input_names: list[str]

The names of the inputs of the last entry.

property last_entry: gemseo.core.cache.CacheEntry

The last cache entry.

name: str

The name of the cache.

property names_to_sizes: dict[str, int]

The sizes of the variables of the last entry.

property output_names: list[str]

The names of the outputs of the last entry.

property penultimate_entry: gemseo.core.cache.CacheEntry

The penultimate cache entry.

tolerance: float

The tolerance below which two input arrays are considered equal.