Formulation

In this example, we will discover the different functions of the API related to MDO formulations: their names, their options and their sub-options.

from __future__ import absolute_import, division, print_function, unicode_literals

from future import standard_library

from gemseo.api import (
    configure_logger,
    get_available_formulations,
    get_formulation_options_schema,
    get_formulation_sub_options_schema,
    get_formulations_options_defaults,
    get_formulations_sub_options_defaults,
)

configure_logger()

standard_library.install_aliases()

Get available formulations

The get_available_formulations() function returns the list of MDO formulations available in GEMSEO or in external modules

print(get_available_formulations())

Out:

['BiLevel', 'DisciplinaryOpt', 'IDF', 'MDF']

Get formulation schemas for (sub-)options

For a given MDO formulation, e.g. "MDF", we can:

print(get_formulation_options_schema("MDF"))

Out:

{'type': 'object', 'properties': {'maximize_objective': {'type': 'boolean', 'description': 'if True, the objective function\nis maximized, by default, a minimization is performed.\n:type maximize_objective: bool\n'}, 'main_mda_class': {'type': 'string', 'description': 'classname of the main MDA, typically the\nMDAChain,  but one can force to use MDAGaussSeidel for instance\n:type main_mda_class: str\n'}, 'sub_mda_class': {'type': 'string', 'description': 'the type of MDA  to be used,\nshall be the class name. (default MDAJacobi)\n:type sub_mda_class: str\n'}}, 'required': ['main_mda_class', 'maximize_objective', 'sub_mda_class']}
print(get_formulations_options_defaults("MDF"))

Out:

{'maximize_objective': False, 'main_mda_class': 'MDAChain', 'sub_mda_class': 'MDAJacobi'}
print(get_formulation_sub_options_schema("MDF", main_mda_class="MDAGaussSeidel"))

Out:

{'type': 'object', 'properties': {'name': {'description': 'the name of the chain\n:type name: str\n'}, 'max_mda_iter': {'type': 'integer', 'description': 'maximum number of iterations\n:type max_mda_iter: int\n'}, 'grammar_type': {'type': 'string', 'description': 'the type of grammar to use for IO declaration\neither JSON_GRAMMAR_TYPE or SIMPLE_GRAMMAR_TYPE\n:type grammar_type: str\n'}, 'tolerance': {'type': 'number', 'description': 'tolerance of the iterative direct coupling solver,\nnorm of the current residuals divided by initial residuals norm\nshall be lower than the tolerance to stop iterating\n:type tolerance: float\n'}, 'linear_solver_tolerance': {'type': 'number', 'description': 'Tolerance of the linear solver\nin the adjoint equation\n:type linear_solver_tolerance: float\n'}, 'warm_start': {'type': 'boolean', 'description': 'if True, the second iteration and ongoing\nstart from the previous coupling solution\n:type warm_start: bool\n'}, 'use_lu_fact': {'type': 'boolean', 'description': 'if True, when using adjoint/forward\ndifferenciation, store a LU factorization of the matrix\nto solve faster multiple RHS problem\n:type use_lu_fact: bool\n'}, 'norm0': {'description': 'reference value of the norm of the residual to compute\nthe decrease stop criteria.\nIterations stops when norm(residual)/norm0<tolerance\n:type norm0: float'}}, 'required': ['grammar_type', 'linear_solver_tolerance', 'max_mda_iter', 'tolerance', 'use_lu_fact', 'warm_start']}
print(get_formulations_sub_options_defaults("MDF", main_mda_class="MDAGaussSeidel"))

Out:

{'name': None, 'max_mda_iter': 10, 'grammar_type': 'JSON', 'tolerance': 1e-06, 'linear_solver_tolerance': 1e-12, 'warm_start': False, 'use_lu_fact': False, 'norm0': None}

Total running time of the script: ( 0 minutes 0.003 seconds)

Gallery generated by Sphinx-Gallery