csnlp.wrappers.NlpScaling#

class csnlp.wrappers.NlpScaling(nlp, scaler, warns=True)[source]#

Bases: NonRetroactiveWrapper[SymType]

Wraps an instance of csnlp.Nlp to facilitate the scaling of its parameters and/or variables as well as the automatic scaling of expressions (e.g., objective and constraints).

Parameters:
nlpNlp[T]

The NLP problem to be wrapped.

scalerScaler

A class for scaling the NLP’s quantities. See csnlp.core.scaling for a collection of these.

warnsbool, optional

If True, warns each time a variable or parameter is created which has not been registered to the scaler and thus cannot be scaled; otherwise, it will not raise warnings.

Methods

constraint(name, lhs, op, rhs[, soft, simplify])

See csnlp.Nlp.constraint.

is_wrapped(wrapper_type)

Gets whether the NLP instance is wrapped or not by the given wrapper type.

minimize(objective)

See csnlp.Nlp.minimize.

parameter(name[, shape])

See csnlp.Nlp.parameter.

scale(expr)

Scales an expression with the MPC's scaled variables and parameters.

solve([pars, vals0])

See csnlp.Nlp.solve.

solve_multi([pars, vals0, return_all_sols, ...])

See csnlp.MultistartNlp.solve_multi.

unscale(expr)

Unscales an expression with the MPC's unscaled variables and parameters.

variable(name[, shape, discrete, lb, ub])

See csnlp.Nlp.variable.

Attributes

scaled_parameters

Gets the scaled parameters of the NLP scheme.

scaled_variables

Gets the scaled variables of the NLP scheme.

unscaled_parameters

Gets the unscaled parameters of the NLP scheme.

unscaled_variables

Gets the unscaled variables of the NLP scheme.

unwrapped

'Returns the original NLP of the wrapper.

constraint(name, lhs, op, rhs, soft=False, simplify=True)[source]#

See csnlp.Nlp.constraint.

Return type:

tuple[TypeVar(SymType, SX, MX), ...]

is_wrapped(wrapper_type)#

Gets whether the NLP instance is wrapped or not by the given wrapper type.

Parameters:
wrapper_typetype of Wrapper

Type of wrapper to check if the NLP is wrapped with.

Returns:
bool

True if wrapped by an instance of wrapper_type; False, otherwise.

Return type:

bool

minimize(objective)[source]#

See csnlp.Nlp.minimize.

Return type:

None

parameter(name, shape=(1, 1))[source]#

See csnlp.Nlp.parameter.

Return type:

TypeVar(SymType, SX, MX)

scale(expr)[source]#

Scales an expression with the MPC’s scaled variables and parameters.

Parameters:
exprcasadi.SX or MX

The expression to be scaled.

Returns:
casadi.SX or MX

The scaled expression.

Return type:

TypeVar(SymType, SX, MX)

property scaled_parameters: dict[str, SymType]#

Gets the scaled parameters of the NLP scheme.

property scaled_variables: dict[str, SymType]#

Gets the scaled variables of the NLP scheme.

solve(pars=None, vals0=None)[source]#

See csnlp.Nlp.solve.

Return type:

Solution[TypeVar(SymType, SX, MX)]

solve_multi(pars=None, vals0=None, return_all_sols=False, return_stacked_sol=False)[source]#

See csnlp.MultistartNlp.solve_multi.

Return type:

Union[Solution[TypeVar(SymType, SX, MX)], list[Solution[TypeVar(SymType, SX, MX)]]]

unscale(expr)[source]#

Unscales an expression with the MPC’s unscaled variables and parameters.

Parameters:
exprcasadi.SX or MX

The expression to be unscaled.

Returns:
casadi.SX or MX

The unscaled expression.

Return type:

TypeVar(SymType, SX, MX)

property unscaled_parameters: dict[str, SymType]#

Gets the unscaled parameters of the NLP scheme.

property unscaled_variables: dict[str, SymType]#

Gets the unscaled variables of the NLP scheme.

property unwrapped: Nlp[SymType]#

‘Returns the original NLP of the wrapper.

variable(name, shape=(1, 1), discrete=False, lb=-inf, ub=inf)[source]#

See csnlp.Nlp.variable.

Return type:

tuple[TypeVar(SymType, SX, MX), TypeVar(SymType, SX, MX), TypeVar(SymType, SX, MX)]

Examples using csnlp.wrappers.NlpScaling#

How scaling can help convergence

How scaling can help convergence