gemseo / caches

Hide inherited members

memory_full_cache module

Caching module to store all the entries in memory.

class gemseo.caches.memory_full_cache.MemoryFullCache(tolerance=0.0, name=None, is_memory_shared=True)[source]

Bases: AbstractFullCache

Cache using memory to cache all the data.

Parameters:
  • is_memory_shared (bool) –

    If True, a shared memory dictionary is used to store the data, which makes the cache compatible with multiprocessing.

    By default it is set to True.

  • tolerance (float) –

    By default it is set to 0.0.

  • name (str | None) –

Warning

If is_memory_shared is False and multiple disciplines point to the same cache or the process is multi-processed, there may be duplicate computations because the cache will not be shared among the processes. This class relies on some multiprocessing features, it is therefore necessary to protect its execution with an if __name__ == '__main__': statement when working on Windows.

class Group(value)

Bases: StrEnum

A data group.

INPUTS = 'inputs'

The label for the input variables.

JACOBIAN = 'jacobian'

The label for the Jacobian.

OUTPUTS = 'outputs'

The label for the output variables.

cache_jacobian(input_data, jacobian_data)

Cache the input and Jacobian data.

Parameters:
  • input_data (DataMapping) – The data containing the input data to cache.

  • jacobian_data (JacobianData) – The Jacobian data to cache.

Return type:

None

cache_outputs(input_data, output_data)

Cache input and output data.

Parameters:
  • input_data (DataMapping) – The data containing the input data to cache.

  • output_data (DataMapping) – The data containing the output data to cache.

Return type:

None

clear()[source]

Clear the cache.

Return type:

None

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
get_all_entries()

Return an iterator over all the entries.

The tolerance is ignored.

Yields:

The entries.

Return type:

Iterator[CacheEntry]

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
to_dataset(name='', categorize=True, input_names=(), output_names=())

Build a Dataset from the cache.

Parameters:
  • name (str) –

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

    By default it is set to “”.

  • 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]) –

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

    By default it is set to ().

  • output_names (Iterable[str]) –

    The names of the outputs to be exported. If empty, use all the outputs. If an output name is also an input name, the output name is suffixed with [out].

    By default it is set to ().

Returns:

A dataset version of the cache.

Return type:

Dataset

to_ggobi(file_path, input_names=None, output_names=None)

Export the cache to an XML file for ggobi tool.

Parameters:
  • file_path (str) – The path of the file to export the cache.

  • input_names (Iterable[str] | None) – The names of the inputs to export. If None, export all of them.

  • output_names (Iterable[str] | None) – The names of the outputs to export. If None, export all of them.

Return type:

None

update(other_cache)

Update from another cache.

Parameters:

other_cache (AbstractFullCache) – The cache to update the current one.

Return type:

None

values() an object providing a view on D's values
property copy: MemoryFullCache

Copy the current cache.

Returns:

A copy of the current cache.

property input_names: list[str]

The names of the inputs of the last entry.

property last_entry: CacheEntry

The last cache entry.

lock: RLockType

The lock used for both multithreading and multiprocessing.

Ensure safe multiprocessing and multithreading concurrent access to the cache.

lock_hashes: RLockType

The lock used for both multithreading and multiprocessing.

Ensure safe multiprocessing and multithreading concurrent access to the cache.

name: str

The name of the cache.

property names_to_sizes: dict[str, int]

The sizes of the variables of the last entry.

For a Numpy array, its size is used. For a container, its length is used. Otherwise, a size of 1 is used.

property output_names: list[str]

The names of the outputs of the last entry.

tolerance: float

The tolerance below which two input arrays are considered equal.

Examples using MemoryFullCache

Memory full cache

Memory full cache

Convert a cache to a dataset

Convert a cache to a dataset