gemseo.utils.discipline module#

Discipline utilities.

class DisciplineVariableProperties(current_name, current_name_without_namespace, description, original_name)[source]#

Bases: object

The properties of a discipline variable.

Parameters:
  • current_name (str)

  • current_name_without_namespace (str)

  • description (str)

  • original_name (str)

current_name: str#

The current name of the variable.

current_name_without_namespace: str#

The current name of the variable without namespace.

description: str#

The description of the variable.

original_name: str#

The original name of the variable.

class DummyBaseDiscipline(name='', input_names=(), output_names=())[source]#

Bases: BaseDiscipline

A dummy base discipline that does nothing.

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 "".

  • input_names (Iterable[str]) --

    The names of the input variables, if any.

    By default it is set to ().

  • output_names (Iterable[str]) --

    The names of the output variables, if any.

    By default it is set to ().

cache: BaseCache | None#

The execution and linearization data saved according to the cache type.

execution_statistics: ExecutionStatistics#

The execution statistics of the process.

execution_status: ExecutionStatus#

The execution status of the process.

name: str#

The name of the process.

class DummyDiscipline(name='', input_names=(), output_names=())[source]#

Bases: Discipline

A dummy discipline that does nothing.

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 "".

  • input_names (Iterable[str]) --

    The names of the input variables, if any.

    By default it is set to ().

  • output_names (Iterable[str]) --

    The names of the output variables, if any.

    By default it is set to ().

cache: BaseCache | None#

The execution and linearization data saved according to the cache type.

execution_statistics: ExecutionStatistics#

The execution statistics of the process.

execution_status: ExecutionStatus#

The execution status of the process.

jac: JacobianData#

The Jacobian matrices of the outputs.

The structure is {output_name: {input_name: jacobian_matrix}}.

name: str#

The name of the process.

class VariableRenamer[source]#

Bases: object

Renamer of discipline input and output variable names.

classmethod from_csv(file_path, sep=',')[source]#

Create from a CSV file.

Structured as discipline_name, variable_name, new_variable_name.

Parameters:
  • file_path (str | Path) -- The path to the CSV file.

  • sep (str) --

    The separator character.

    By default it is set to ",".

Returns:

A renamer.

Return type:

Self

classmethod from_dictionary(translations)[source]#

Create from dictionaries.

Parameters:

translations (Mapping[str, Mapping[str, str]]) -- The translations of the discipline input and output variables as {discipline_name: {variable_name: new_variable_name}}.

Returns:

A renamer.

Return type:

VariableRenamer

classmethod from_spreadsheet(file_path)[source]#

Create from a spreadsheet file.

Structured as discipline_name, variable_name, new_variable_name.

Parameters:

file_path (str | Path) -- The path to the spreadsheet file.

Returns:

A renamer.

Return type:

Self

classmethod from_translations(*translations)[source]#

Create from translations.

Parameters:

*translations (VariableTranslation | tuple[str, str, str]) -- The translations of the discipline input and output variables. If tuple, formatted as (discipline_name, variable_name, new_variable_name).

Returns:

A renamer.

Return type:

VariableRenamer

add_translation(translation)[source]#

Add a translation.

Parameters:

translation (VariableTranslation | tuple[str, str, str]) -- A variable translation. If tuple, formatted as (discipline_name, variable_name, new_variable_name).

Raises:

ValueError -- When a variable has already been renamed.

Return type:

None

add_translations_by_discipline(discipline_name, variable_names_to_new_variable_names)[source]#

Add one or more translations for a given discipline.

Parameters:
  • discipline_name (str) -- The name of the discipline.

  • variable_names_to_new_variable_names (Mapping[str, str]) -- The new variable names bound to the old variable names.

Return type:

None

add_translations_by_variable(new_variable_name, discipline_names_to_variable_names)[source]#

Add one or more translations for a same variable.

Parameters:
  • new_variable_name (str) -- The new name of the variable to rename discipline variables.

  • discipline_names_to_variable_names (Mapping[str, str]) -- The variable names bound to the discipline names.

Return type:

None

property translations: tuple[VariableTranslation, ...]#

The translations of the discipline input and output variables.

property translators: Mapping[str, Mapping[str, str]]#

The translators.

As {discipline_name: {variable_name, new_variable_name}}.

class VariableTranslation(discipline_name, variable_name, new_variable_name)[source]#

Bases: NamedTuple

The translation of a discipline input or output variable.

Create new instance of VariableTranslation(discipline_name, variable_name, new_variable_name)

Parameters:
  • discipline_name (str)

  • variable_name (str)

  • new_variable_name (str)

discipline_name: str#

The name of the discipline.

new_variable_name: str#

The new name of the variable.

variable_name: str#

The name of the variable.

check_disciplines_consistency(disciplines, log_message, raise_error)[source]#

Check if disciplines are consistent.

The disciplines are consistent if each output is computed by one and only one discipline.

Parameters:
  • disciplines (Iterable[Discipline]) -- The disciplines of interest.

  • log_message (bool) -- Whether to log a message when the disciplines are not consistent.

  • raise_error (bool) -- Whether to raise an error when the disciplines are not consistent.

Returns:

Whether the disciplines are consistent.

Raises:

ValueError -- When two disciplines compute the same output and raise_error is True.

Return type:

bool

get_all_inputs(disciplines, skip_scenarios=True)[source]#

Return all the input names of the disciplines.

Parameters:
  • disciplines (Iterable[Discipline]) -- The disciplines including potentially Scenario objects.

  • skip_scenarios (bool) --

    If True, skip the Scenario objects. Otherwise, consider their disciplines.

    By default it is set to True.

Returns:

The names of the inputs.

Return type:

list[str]

get_all_outputs(disciplines, skip_scenarios=True)[source]#

Return all the output names of the disciplines.

Parameters:
  • disciplines (Iterable[Discipline | BaseScenario]) -- The disciplines including potentially Scenario objects.

  • skip_scenarios (bool) --

    If True, skip the Scenario objects. Otherwise, consider their disciplines.

    By default it is set to True.

Returns:

The names of the outputs.

Return type:

list[str]

get_discipline_variable_properties(discipline)[source]#

Return the properties of the input and output variables of a discipline.

Parameters:

discipline (Discipline) -- The discipline.

Returns:

The properties of the input variables, then the properties of the output variables.

Return type:

tuple[dict[str, DisciplineVariableProperties], dict[str, DisciplineVariableProperties]]

get_sub_disciplines(disciplines, recursive=False)[source]#

Determine the sub-disciplines.

This method lists the sub-disciplines' disciplines. It will list up to one level of disciplines contained inside another one unless the recursive argument is set to True.

Parameters:
  • disciplines (Iterable[Discipline]) -- The disciplines from which the sub-disciplines will be determined.

  • recursive (bool) --

    If True, the method will look inside any discipline that has other disciplines inside until it reaches a discipline without sub-disciplines, in this case the return value will not include any discipline that has sub-disciplines. If False, the method will list up to one level of disciplines contained inside another one, in this case the return value may include disciplines that contain sub-disciplines.

    By default it is set to False.

Returns:

The sub-disciplines.

Return type:

list[Discipline]

rename_discipline_variables(disciplines, translators)[source]#

Rename input and output variables of disciplines.

Parameters:
  • disciplines (Iterable[Discipline]) -- The disciplines.

  • translators (Mapping[str, Mapping[str, str]]) -- The translators of the form {discipline_name: {variable_name: new_variable_name}}.

Raises:

ValueError -- when a translator uses a wrong variable_name.

Return type:

None