gemseo.core.discipline.base_discipline module#
The base class defining the concept of discipline.
- class BaseDiscipline(name='')[source]#
Bases:
BaseMonitoredProcess
The base class defining the concept of discipline.
A discipline computes output data from input data using its
execute()
method. These data are in dictionary form, i.e.{variable_name: variable_value, ...}
. The input-output data resulting from an execution can be accessed vialocal_data
or separately viaget_input_data()
andget_output_data()
.For both input and output variables, default values can be provided using the mappings
default_input_data
anddefault_output_data
. In this case, the discipline will use these default input values at execution when an input value is not provided and these default output values in the case ofvirtual_execution
.In other aspects, the
cache
can store zero, one or more discipline evaluations depending on theCacheType
. This cache is set at instantiation and can be changed with theset_cache()
method.Lastly, a discipline is equipped with an
input_grammar
to check the input data and anoutput_grammar
to check the output data. This validation depends on theGrammarType
, e.g. name verification, data type verification, etc.Initialize self. See help(type(self)) for accurate signature.
- Parameters:
name (str) --
The name of the discipline. If empty, use the name of the class.
By default it is set to "".
- class CacheType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
StrEnum
The type of cache.
- HDF5 = 'HDF5Cache'#
Store all the execution data on the disk.
- MEMORY_FULL = 'MemoryFullCache'#
Store all the execution data in memory.
- NONE = ''#
Store nothing.
- SIMPLE = 'SimpleCache'#
Store the last execution data.
- class GrammarType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
StrEnum
The name of the grammar class.
- JSON = 'JSONGrammar'#
- PYDANTIC = 'PydanticGrammar'#
- SIMPLE = 'SimpleGrammar'#
- SIMPLER = 'SimplerGrammar'#
- add_namespace_to_input(input_name, namespace)[source]#
Rename an input name with a namespace prefix.
The updated input name will be
namespace
+namespaces_separator
+input_name
.
- add_namespace_to_output(output_name, namespace)[source]#
Rename an output name with a namespace prefix.
The updated output name will be
namespace
+namespaces_separator
+output_name
.
- execute(input_data=mappingproxy({}))[source]#
Execute the discipline, i.e. compute output data from input data.
If
virtual_execution
isTrue
, this method returns thedefault_output_data
. Otherwise, it calls the_run()
method performing the true execution and returns the corresponding output data. This_run()
method must be implemented in subclasses.- Parameters:
input_data (StrKeyMapping) --
The input data. Complete this dictionary with the
default_input_data
.By default it is set to {}.
- Returns:
The input and output data.
- Return type:
- set_cache(cache_type, tolerance=0.0, **kwargs)[source]#
Set the type of cache to use and the tolerance level.
This method defines when the output data have to be cached according to the distance between the corresponding input data and the input data already cached for which output data are also cached.
The cache can be either a
SimpleCache
recording the last execution or a cache storing all executions, e.g.MemoryFullCache
andHDF5Cache
. Caching data can be either in-memory, e.g.SimpleCache
andMemoryFullCache
, or on the disk, e.g.HDF5Cache
.
- GRAMMAR_DIRECTORY: ClassVar[str | Path] = ''#
The directory in which to search for the grammar files if not the class one.
- default_grammar_type: ClassVar[_GrammarType] = 'JSONGrammar'#
The default type of grammar.
- property default_output_data: Defaults#
The default output data used when
virtual_execution
isTrue
.
- property input_grammar: BaseGrammar#
The input grammar.
- property local_data: DisciplineData#
The current input and output data.
- property output_grammar: BaseGrammar#
The output grammar.
- virtual_execution: ClassVar[bool] = False#
Whether
execute()
returns thedefault_output_data
.A virtual execution mocks the input-output process without performing the true execution.
- class CacheType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnum
The types of cache.
- HDF5 = 'HDF5Cache'#
Store all the execution data on the disk.
- MEMORY_FULL = 'MemoryFullCache'#
Store all the execution data in memory.
- NONE = ''#
Store nothing.
- SIMPLE = 'SimpleCache'#
Store the last execution data.