gemseo / core

Show inherited members

discipline_data module

Provide a dict-like class for storing disciplines data.

class gemseo.core.discipline_data.DisciplineData(data=None, input_to_namespaced=None, output_to_namespaced=None)[source]

Bases: MutableMapping[str, Any]

A dict-like class for handling disciplines data.

This class replaces a standard dictionary that was previously used for storing discipline data. It allows handling values bound to pandas.DataFrame as if they were multiple items bound to numpy.ndarray. Then, an object of this class may be used as if it was a standard dictionary containing numpy.ndarray, which is the assumption made by the clients of the MDODiscipline subclasses.

As compared to a standard dictionary, the methods of this class may hide the values bound to pandas.DataFrame and instead expose the items of those later as if they belonged to the dictionary.

If a dict-like object is provided when creating a DisciplineData object, its contents is shared with this latter, such that any changes performed via a DisciplineData object is reflected into the passed in dict-like object.

If a DisciplineData is created from another one, their contents are shared.

A separator, by default ~, is used to identify the keys of the items that are bound to an array inside a pandas.DataFrame. Such a key is composed of the key from the shared dict-like object, the separator and the name of the target column of the pandas.DataFrame. When such a key is queried, a numpy.ndarray view of the pandas.DataFrame column is provided.

Printing a DisciplineData object prints the shared dict-like object.

Nested dictionaries are also supported.

Warning

Nested DataFrame (i.e. in a nested dictionary) are not supported.

Examples

>>> from gemseo.core.discipline_data import DisciplineData
>>> import numpy as np
>>> import pandas as pd
>>> data = {
...     "x": 0,
...     "y": pd.DataFrame(data={"a": np.array([0])}),
... }
>>> disc_data = DisciplineData(data)
>>> disc_data["x"]
0
>>> disc_data["y"]
   a
0  0
>>> # DataFrame content can be accessed with the ~ separator.
>>> disc_data["y~a"]
array([0])
>>> # New columns can be inserted into a DataFrame with the ~ separator.
>>> disc_data["y~b"] = np.array([1])
>>> data["y"]["b"]
0    1
Name: b, dtype: int64
>>> # New DataFrame can be added.
>>> disc_data["z~c"] = np.array([2])
>>> data["z"]
   c
0  2
>>> type(data["z"])
<class 'pandas.core.frame.DataFrame'>
>>> # DataFrame's columns can be deleted.
>>> del disc_data["z~c"]
>>> data["z"]
Empty DataFrame
Columns: []
Index: [0]
>>> # Iterating is only done over the exposed keys.
>>> list(disc_data)
['x', 'y~a', 'y~b']
>>> # The length is consistent with the iterator.
>>> len(disc_data)
3

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • data (MutableData | None) – A dict-like object or a DisciplineData object. If None, an empty dictionary is used.

  • input_to_namespaced (NamespacesMapping | None) – The mapping from input data names to their prefixed names.

  • output_to_namespaced (NamespacesMapping | None) – The mapping from output data names to their prefixed names.

clear() None.  Remove all items from D.[source]
Return type:

None

copy(keys=(), with_namespace=True)[source]

Create a shallow copy.

Parameters:
  • keys (Iterable[str]) –

    The names of the items to keep, if empty then keep them all.

    By default it is set to ().

  • with_namespace (bool) –

    Whether to the keys are prefixed with the namespace.

    By default it is set to True.

Returns:

The shallow copy.

Return type:

DisciplineData

restrict(*keys)[source]

Remove all but the given keys.

Parameters:

*keys (str) – The keys of the elements to keep.

Return type:

None

update(other, exclude=())[source]

Update from another mapping but for some keys.

Parameters:
  • other (Mapping[str, Any]) – The data to update from.

  • exclude (Iterable[str]) –

    The keys that shall not be updated.

    By default it is set to ().

Return type:

None

SEPARATOR = '~'

The character used to separate the shared dict key from the column of a pandas DataFrame.

Examples using DisciplineData

Empirical estimation of statistics

Empirical estimation of statistics

MDA

MDA

Plug a surrogate discipline in a Scenario

Plug a surrogate discipline in a Scenario

Gauss-Seidel MDA

Gauss-Seidel MDA

Hybrid Jacobi/Newton MDA

Hybrid Jacobi/Newton MDA

Jacobi MDA

Jacobi MDA

MDA residuals

MDA residuals

MDAChain

MDAChain

MDAChain with independent parallel MDAs

MDAChain with independent parallel MDAs

Newton-Raphson MDA

Newton-Raphson MDA

Quasi-Newton MDA

Quasi-Newton MDA