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 division, unicode_literals

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()

Out:

<RootLogger root (INFO)>

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:

{'$schema': 'http://json-schema.org/schema#', 'type': 'object', 'properties': {'maximize_objective': {'description': 'If True, the objective function is maximized.', 'type': 'boolean'}, 'main_mda_class': {'description': 'The name of the class used for the main MDA, typically', 'type': 'string'}, 'sub_mda_class': {'description': 'The name of the class used for the sub-MDA.', 'type': 'string'}}, '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:

{'$schema': 'http://json-schema.org/schema#', 'type': 'object', 'properties': {'name': {'description': 'the name of the chain :type name: str', 'type': 'null'}, 'max_mda_iter': {'description': 'maximum number of iterations :type max_mda_iter: int', 'type': 'integer'}, 'grammar_type': {'description': 'the type of grammar to use for IO declaration either JSON_GRAMMAR_TYPE or SIMPLE_GRAMMAR_TYPE :type grammar_type: str', 'type': 'string'}, 'tolerance': {'description': 'tolerance of the iterative direct coupling solver, norm of the current residuals divided by initial residuals norm shall be lower than the tolerance to stop iterating :type tolerance: float', 'type': 'number'}, 'linear_solver_tolerance': {'description': 'Tolerance of the linear solver in the adjoint equation :type linear_solver_tolerance: float', 'type': 'number'}, 'warm_start': {'description': 'if True, the second iteration and ongoing start from the previous coupling solution :type warm_start: bool', 'type': 'boolean'}, 'use_lu_fact': {'description': 'if True, when using adjoint/forward differenciation, store a LU factorization of the matrix to solve faster multiple RHS problem :type use_lu_fact: bool', 'type': 'boolean'}, 'over_relax_factor': {'description': 'relaxation coefficient, used to make the method more robust, if 0<over_relax_factor<1 or faster if 1<over_relax_factor<=2. If over_relax_factor =1., it is deactivated :type over_relax_factor: float', 'type': 'number'}}, 'required': ['grammar_type', 'linear_solver_tolerance', 'max_mda_iter', 'over_relax_factor', '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, 'over_relax_factor': 1.0}

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

Gallery generated by Sphinx-Gallery