gemseo / mda

Show inherited members

newton module

A set of Newton algorithm variants for solving MDAs.

Root finding methods include:

Each of these methods is implemented by a class in this module. Both inherit from a common abstract cache.

class gemseo.mda.newton.MDANewtonRaphson(disciplines, max_mda_iter=10, relax_factor=0.99, name=None, grammar_type=GrammarType.JSON, linear_solver='DEFAULT', tolerance=1e-06, linear_solver_tolerance=1e-12, warm_start=False, use_lu_fact=False, coupling_structure=None, log_convergence=False, linear_solver_options=None, newton_linear_solver_name='DEFAULT', newton_linear_solver_options=None)[source]

Bases: MDARoot

Newton solver for MDA.

The Newton-Raphson method is parameterized by a relaxation factor \(\alpha \in (0, 1]\) to limit the length of the steps taken along the Newton direction. The new iterate is given by:

\[x_{k+1} = x_k - \alpha f'(x_k)^{-1} f(x_k)\]

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

Parameters:
  • disciplines (Sequence[MDODiscipline]) – The disciplines from which to compute the MDA.

  • max_mda_iter (int) –

    The maximum iterations number for the MDA algorithm.

    By default it is set to 10.

  • relax_factor (float) –

    The relaxation factor in the Newton step.

    By default it is set to 0.99.

  • name (str | None) – The name to be given to the MDA. If None, use the name of the class.

  • grammar_type (MDODiscipline.GrammarType) –

    The type of the input and output grammars.

    By default it is set to “JSONGrammar”.

  • linear_solver (str) –

    The name of the linear solver.

    By default it is set to “DEFAULT”.

  • tolerance (float) –

    The tolerance of the iterative direct coupling solver; the norm of the current residuals divided by initial residuals norm shall be lower than the tolerance to stop iterating.

    By default it is set to 1e-06.

  • linear_solver_tolerance (float) –

    The tolerance of the linear solver in the adjoint equation.

    By default it is set to 1e-12.

  • warm_start (bool) –

    Whether the second iteration and ongoing start from the previous coupling solution.

    By default it is set to False.

  • use_lu_fact (bool) –

    Whether to store a LU factorization of the matrix when using adjoint/forward differentiation. to solve faster multiple RHS problem.

    By default it is set to False.

  • coupling_structure (MDOCouplingStructure | None) – The coupling structure to be used by the MDA. If None, it is created from disciplines.

  • log_convergence (bool) –

    Whether to log the MDA convergence, expressed in terms of normed residuals.

    By default it is set to False.

  • linear_solver_options (Mapping[str, Any]) – The options passed to the linear solver factory.

  • newton_linear_solver_name (str) –

    The description is missing.

    By default it is set to “DEFAULT”.

  • newton_linear_solver_options (Mapping[str, Any] | None) – The options for the Newton linear solver.

all_couplings: list[str]

The names of the coupling variables.

assembly: JacobianAssembly
cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

coupling_structure: MDOCouplingStructure

The coupling structure to be used by the MDA.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: dict[str, dict[str, ndarray]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

lin_cache_tol_fact: float

The tolerance factor to cache the Jacobian.

linear_solver: str

The name of the linear solver.

linear_solver_options: dict[str, Any]

The options of the linear solver.

linear_solver_tolerance: float

The tolerance of the linear solver in the adjoint equation.

matrix_type: JacobianAssembly.JacobianType

The type of the matrix.

max_mda_iter: int

The maximum iterations number for the MDA algorithm.

name: str

The name of the discipline.

norm0: float | None

The reference residual, if any.

normed_residual: float

The normed residual.

output_grammar: BaseGrammar

The output grammar.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

reset_history_each_run: bool

Whether to reset the history of MDA residuals before each run.

residual_history: list[float]

The history of MDA residuals.

residual_variables: Mapping[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.

scaling: ResidualScaling

The scaling method applied to MDA residuals for convergence monitoring.

strong_couplings: list[str]

The names of the strong coupling variables.

tolerance: float

The tolerance of the iterative direct coupling solver.

use_lu_fact: bool

Whether to store a LU factorization of the matrix.

warm_start: bool

Whether the second iteration and ongoing start from the previous solution.

class gemseo.mda.newton.MDAQuasiNewton(disciplines, max_mda_iter=10, name=None, grammar_type=GrammarType.JSON, method='hybr', use_gradient=False, tolerance=1e-06, linear_solver_tolerance=1e-12, warm_start=False, use_lu_fact=False, coupling_structure=None, linear_solver='DEFAULT', linear_solver_options=None)[source]

Bases: MDARoot

Quasi-Newton solver for MDA.

Quasi-Newton methods include numerous variants ( Broyden, Levenberg-Marquardt, …). The name of the variant should be provided as a parameter method of the class.

The new iterate is given by:

\[\begin{split}x_{k+1} = x_k - \\rho_k B_k f(x_k)\end{split}\]

where \(\\rho_k\) is a coefficient chosen in order to minimize the convergence and \(B_k\) is an approximation of the inverse of the Jacobian \(Df(x_k)^{-1}\).

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

Parameters:
  • disciplines (Sequence[MDODiscipline]) – The disciplines from which to compute the MDA.

  • max_mda_iter (int) –

    The maximum iterations number for the MDA algorithm.

    By default it is set to 10.

  • name (str | None) – The name to be given to the MDA. If None, use the name of the class.

  • grammar_type (MDODiscipline.GrammarType) –

    The type of the input and output grammars.

    By default it is set to “JSONGrammar”.

  • method (str) –

    The name of the method in scipy root finding, among QUASI_NEWTON_METHODS.

    By default it is set to “hybr”.

  • use_gradient (bool) –

    Whether to use the analytic gradient of the discipline.

    By default it is set to False.

  • tolerance (float) –

    The tolerance of the iterative direct coupling solver; the norm of the current residuals divided by initial residuals norm shall be lower than the tolerance to stop iterating.

    By default it is set to 1e-06.

  • linear_solver_tolerance (float) –

    The tolerance of the linear solver in the adjoint equation.

    By default it is set to 1e-12.

  • warm_start (bool) –

    Whether the second iteration and ongoing start from the previous coupling solution.

    By default it is set to False.

  • use_lu_fact (bool) –

    Whether to store a LU factorization of the matrix when using adjoint/forward differentiation. to solve faster multiple RHS problem.

    By default it is set to False.

  • coupling_structure (MDOCouplingStructure | None) – The coupling structure to be used by the MDA. If None, it is created from disciplines.

  • linear_solver (str) –

    The name of the linear solver.

    By default it is set to “DEFAULT”.

  • linear_solver_options (Mapping[str, Any]) – The options passed to the linear solver factory.

Raises:

ValueError – If the method is not a valid quasi-Newton method.

ANDERSON = 'anderson'
BROYDEN1 = 'broyden1'
BROYDEN2 = 'broyden2'
DF_SANE = 'df-sane'
DIAG_BROYDEN = 'diagbroyden'
EXCITING_MIXING = 'excitingmixing'
HYBRID = 'hybr'
KRYLOV = 'krylov'
LEVENBERG_MARQUARDT = 'lm'
LINEAR_MIXING = 'linearmixing'
QUASI_NEWTON_METHODS = ['hybr', 'lm', 'broyden1', 'broyden2', 'anderson', 'linearmixing', 'diagbroyden', 'excitingmixing', 'krylov', 'df-sane']
all_couplings: list[str]

The names of the coupling variables.

assembly: JacobianAssembly
cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

coupling_structure: MDOCouplingStructure

The coupling structure to be used by the MDA.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: dict[str, dict[str, ndarray]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

lin_cache_tol_fact: float

The tolerance factor to cache the Jacobian.

linear_solver: str

The name of the linear solver.

linear_solver_options: dict[str, Any]

The options of the linear solver.

linear_solver_tolerance: float

The tolerance of the linear solver in the adjoint equation.

matrix_type: JacobianAssembly.JacobianType

The type of the matrix.

max_mda_iter: int

The maximum iterations number for the MDA algorithm.

name: str

The name of the discipline.

norm0: float | None

The reference residual, if any.

normed_residual: float

The normed residual.

output_grammar: BaseGrammar

The output grammar.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

reset_history_each_run: bool

Whether to reset the history of MDA residuals before each run.

residual_history: list[float]

The history of MDA residuals.

residual_variables: Mapping[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.

scaling: ResidualScaling

The scaling method applied to MDA residuals for convergence monitoring.

strong_couplings: list[str]

The names of the strong coupling variables.

tolerance: float

The tolerance of the iterative direct coupling solver.

use_lu_fact: bool

Whether to store a LU factorization of the matrix.

warm_start: bool

Whether the second iteration and ongoing start from the previous solution.

class gemseo.mda.newton.MDARoot(disciplines, max_mda_iter=10, name=None, grammar_type=GrammarType.JSON, tolerance=1e-06, linear_solver_tolerance=1e-12, warm_start=False, use_lu_fact=False, coupling_structure=None, log_convergence=False, linear_solver='DEFAULT', linear_solver_options=None)[source]

Bases: MDA

Abstract class implementing MDAs based on (Quasi-)Newton methods.

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

Parameters:
  • disciplines (Sequence[MDODiscipline]) – The disciplines from which to compute the MDA.

  • max_mda_iter (int) –

    The maximum iterations number for the MDA algorithm.

    By default it is set to 10.

  • name (str | None) – The name to be given to the MDA. If None, use the name of the class.

  • grammar_type (MDODiscipline.GrammarType) –

    The type of the input and output grammars.

    By default it is set to “JSONGrammar”.

  • tolerance (float) –

    The tolerance of the iterative direct coupling solver; the norm of the current residuals divided by initial residuals norm shall be lower than the tolerance to stop iterating.

    By default it is set to 1e-06.

  • linear_solver_tolerance (float) –

    The tolerance of the linear solver in the adjoint equation.

    By default it is set to 1e-12.

  • warm_start (bool) –

    Whether the second iteration and ongoing start from the previous coupling solution.

    By default it is set to False.

  • use_lu_fact (bool) –

    Whether to store a LU factorization of the matrix when using adjoint/forward differentiation. to solve faster multiple RHS problem.

    By default it is set to False.

  • coupling_structure (MDOCouplingStructure | None) – The coupling structure to be used by the MDA. If None, it is created from disciplines.

  • log_convergence (bool) –

    Whether to log the MDA convergence, expressed in terms of normed residuals.

    By default it is set to False.

  • linear_solver (str) –

    The name of the linear solver.

    By default it is set to “DEFAULT”.

  • linear_solver_options (Mapping[str, Any]) – The options passed to the linear solver factory.

execute_all_disciplines(input_local_data, update_local_data=True)[source]

Execute all self.disciplines.

Parameters:
  • input_local_data (Mapping[str, ndarray]) – The input data of the disciplines.

  • update_local_data (bool) –

    Whether to update the local data from the disciplines.

    By default it is set to True.

Return type:

None

all_couplings: list[str]

The names of the coupling variables.

assembly: JacobianAssembly
cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

coupling_structure: MDOCouplingStructure

The coupling structure to be used by the MDA.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: dict[str, dict[str, ndarray]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

lin_cache_tol_fact: float

The tolerance factor to cache the Jacobian.

linear_solver: str

The name of the linear solver.

linear_solver_options: dict[str, Any]

The options of the linear solver.

linear_solver_tolerance: float

The tolerance of the linear solver in the adjoint equation.

matrix_type: JacobianAssembly.JacobianType

The type of the matrix.

max_mda_iter: int

The maximum iterations number for the MDA algorithm.

name: str

The name of the discipline.

norm0: float | None

The reference residual, if any.

normed_residual: float

The normed residual.

output_grammar: BaseGrammar

The output grammar.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

reset_history_each_run: bool

Whether to reset the history of MDA residuals before each run.

residual_history: list[float]

The history of MDA residuals.

residual_variables: Mapping[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.

scaling: ResidualScaling

The scaling method applied to MDA residuals for convergence monitoring.

strong_couplings: list[str]

The names of the strong coupling variables.

tolerance: float

The tolerance of the iterative direct coupling solver.

use_lu_fact: bool

Whether to store a LU factorization of the matrix.

warm_start: bool

Whether the second iteration and ongoing start from the previous solution.

Examples using MDANewtonRaphson

Hybrid Jacobi/Newton MDA

Hybrid Jacobi/Newton MDA

Newton-Raphson MDA

Newton-Raphson MDA

Examples using MDAQuasiNewton

Quasi-Newton MDA

Quasi-Newton MDA