cosapp.core.numerics.root

Module provides dispatch to different non-linear algorithms.

Functions

get_kwargs()

Returns kwargs as a dictionary, using inspect.currentframe

root(fun, x0[, args, method, options])

Classes

BaseNumericalSolver([options])

CustomSolver([tol, factor, max_iter, ...])

Custom Newton-Raphson solver.

NumpySolver(method[, options])

Encapsulation of scipy.optimize.root

class cosapp.core.numerics.root.BaseNumericalSolver(options={})[source]

Bases: ABC

classmethod from_options(options: Dict[str, Any]) ConcreteSolver[source]
property options: Dict[str, Any]
abstract solve(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[Any] = (), *other_args, **kwargs) SolverResults | OptimizeResult[source]
transfer_options(options: Dict[str, Any]) None[source]
class cosapp.core.numerics.root.CustomSolver(tol='auto', factor=1.0, max_iter=100, verbose=False, eps=1.1920928955078125e-07, jac_update_tol=0.01, history=False, partial_jac=True, partial_jac_tries=5, tol_update_period=4, tol_to_noise_ratio=16)[source]

Bases: BaseNumericalSolver

Custom Newton-Raphson solver.

static lu_factor(matrix: ndarray)[source]
solve(fresidues: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[float | str] = (), jac=None, recorder=None, **options) SolverResults[source]

Customized Newton-Raphson algorithm to solve fresidues starting with x0.

Parameters:
  • fresidues (Callable[[Sequence[float], Any], numpy.ndarray[float]]) – Callable residues function

  • x0 (Sequence[float]) – Initial solution guess

  • args (Tuple[Any, ...]) – Additional arguments for fun

  • options (dict, optional) – A dictionary of problem-dependent solver options.

  • Options

  • -------

  • jac_lup ((ndarray[float], ndarray[int]), optional) – LU decomposition of Jacobian given as tuple (LU, perm) to reuse as initial direction

  • jac (ndarray, optional) – Jacobian to reuse for partial update

  • compute_jacobian (bool) – Force to update the Jacobian matrix even if the provided one is useful

  • lower_bound (numpy.ndarray) – Min values for parameters iterated by solver.

  • upper_bound (numpy.ndarray) – Max values for parameters iterated by solver.

  • abs_step (numpy.ndarray) – Max absolute step for parameters iterated by solver.

  • rel_step (numpy.ndarray) – Max relative step for parameters iterated by solver.

Returns:

The solution represented as a SolverResults object. See cosapp.core.numerics.basics.SolverResults for details.

Return type:

SolverResults

class cosapp.core.numerics.root.NumpySolver(method: str, options={})[source]

Bases: BaseNumericalSolver

Encapsulation of scipy.optimize.root

solve(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[float | str] = (), jac=None, callback=None) OptimizeResult[source]

Cancel residues produced by fun starting with x0 as initial guess.

Parameters:
  • fun (Callable[[Sequence[float], Any], numpy.ndarray[float]]) – Callable residues function

  • x0 (Sequence[float]) – Initial solution guess

  • args (Tuple[Any, ...]) – Additional arguments passed to fun

  • jac (bool or callable, optional) – If jac is a Boolean and is True, fun is assumed to return the value of Jacobian along with the objective function. If False, the Jacobian will be estimated numerically. jac can also be a callable returning the Jacobian of fun. In this case, it must accept the same arguments as fun. (default: None)

  • callback (Callable, optional) – Optional callback function. It is called on every iteration as callback(x, r), where x is the current solution and r the corresponding residual.

Returns:

The solution represented as a OptimizeResult object. Important attributes are: x the solution array, success a Boolean flag indicating if the algorithm exited successfully and message which describes the cause of the termination. See cosapp.core.numerics.basics.SolverResults for a description of other attributes.

Return type:

scipy.optimize.OptimizeResult

cosapp.core.numerics.root.get_kwargs()[source]

Returns kwargs as a dictionary, using inspect.currentframe

cosapp.core.numerics.root.root(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[Any] = (), method: NonLinearMethods = NonLinearMethods.POWELL, options: Dict[str, Any] = {}) SolverResults | OptimizeResult[source]