CustomScalerBase Class#

class idaes.core.scaling.custom_scaler_base.ConstraintScalingScheme(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Schemes available for calculating constraint scaling factors.

  • harmonicMean (‘harmonic_mean’): sf = sum(1/abs(nominal value))

  • inverseSum (‘inverse_sum’): sf = 1 / sum(abs(nominal value))

  • inverseRSS (‘inverse_root_sum_squared’): sf = 1 / sqrt(sum(abs(nominal value)**2))

  • inverseMaximum (‘inverse_maximum’): sf = 1 / max(abs(nominal value)

  • inverseMinimum (‘inverse_minimum’): sf = 1 / min(abs(nominal value)

class idaes.core.scaling.custom_scaler_base.CustomScalerBase(**kwargs)[source]#

Base class for custom scaling routines.

zero_tolerance

Value at which a variable will be considered equal to zero for scaling.

max_variable_scaling_factor

Maximum value for variable scaling factors.

min_variable_scaling_factor

Minimum value for variable scaling factors.

max_constraint_scaling_factor

Maximum value for constraint scaling factors.

min_constraint_scaling_factor

Minimum value for constraint scaling factors.

overwrite

Whether to overwrite existing scaling factors.

call_submodel_scaler_method(submodel, method, submodel_scalers=None, overwrite=False)[source]#

Call scaling method for submodel.

Scaler for submodel is taken from submodel_scalers if present, otherwise the default scaler for the submodel is used.

Parameters:
  • submodel – submodel to be scaled

  • submodel_scalers (ComponentMap) – user provided ComponentMap of Scalers to use for submodels

  • method (str) – name of method to call from submodel (as string)

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

constraint_scaling_routine(model, overwrite=False, submodel_scalers=None)[source]#

Routine to apply scaling factors to constraints in model.

Derived classes must overload this method.

Parameters:
  • model – model to be scaled

  • overwrite (bool) – whether to overwrite existing scaling factors

  • submodel_scalers (ComponentMap) – ComponentMap of Scalers to use for sub-models

Returns:

None

get_default_scaling_factor(component)[source]#

Get scaling factor for component from dict of default values.

Parameters:

component – component to get default scaling factor for

Returns:

default scaling factor if it exists, else None

get_expression_nominal_values(expression)[source]#

Calculate nominal values for each additive term in a Pyomo expression.

The nominal value of any Var is defined as the inverse of its scaling factor (if assigned, else 1).

Parameters:

expression – Pyomo expression to collect nominal values for

Returns:

list of nominal values for each additive term

propagate_state_scaling(target_state, source_state, overwrite=False)[source]#

Propagate scaling of state variables from one StateBlock to another.

Indexing of target and source StateBlocks must match.

Parameters:
  • target_state – StateBlock to set scaling factors on

  • source_state – StateBlock to use as source for scaling factors

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_constraint_by_component(target_constraint, scaling_component, overwrite=False)[source]#

Set scaling factor for target_constraint equal to that of scaling_component.

Parameters:
  • target_constraint – constraint to set scaling factor for

  • scaling_component – component to use for scaling factor

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_constraint_by_default(constraint, overwrite=False)[source]#

Set scaling factor for constraint based on default scaling factor.

Parameters:
  • constraint – constraint to set scaling factor for

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_constraint_by_nominal_derivative_norm(constraint, norm=2, overwrite=False)[source]#

Scale constraint by norm of partial derivatives.

Calculates partial derivatives of constraint at nominal variable values, and then scaled the constraint by the user-selected norm of these derivatives. Given perfect variable scaling, this should provide a similar result to applying scaling based on the Jacobian norm, however this approach does not require an initial solution for the problem (relying on nominal values instead).

Parameters:
  • constraint – constraint to be scaled.

  • norm (int) – type of norm to use for scaling. Must be a positive integer.

  • overwrite (bool) – whether to overwrite existing scaling factors.

Returns:

None

scale_constraint_by_nominal_value(constraint, scheme=ConstraintScalingScheme.inverseMaximum, overwrite=False)[source]#

Set scaling factor for constraint based on the nominal value(s).

Terms with expected magnitudes of 0 will be ignored.

Parameters:
  • constraint – constraint to set scaling factor for

  • scheme (ConstraintScalingScheme) – ConstraintScalingScheme Enum indicating method to apply for determining constraint scaling.

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_model(model, first_stage_fill_in=None, second_stage_fill_in=None, submodel_scalers=None)[source]#

Default model scaling routine.

This method performs a four-step scaling routine:

  1. Scale variables using variable_scaling_routine

  2. Perform first-stage scaling factor fill in using user provided method(s), called in order declared

  3. Scale constraints using constraint_scaling_routine

  4. Perform second-stage scaling factor fill in using user provided method(s), called in order declared

Parameters:
  • model – model to be scaled

  • first_stage_fill_in (list) – list of methods to use for first-stage scaling factor fill in

  • second_stage_fill_in (list) – list of methods to use for second-stage scaling factor fill in

  • submodel_scalers (ComponentMap) – ComponentMap of Scalers to use for sub-models

Returns:

None

scale_variable_by_bounds(variable, overwrite=False)[source]#

Set scaling factor for variable based on bounds.

If variable has both upper and lower bounds, scaling factor will be based on the mean of the bounds. If variable has only one bound, scaling factor will be based on that bound. If variable has no bounds, scaling factor will not be set.

Parameters:
  • variable – variable to set scaling factor for

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_variable_by_component(target_variable, scaling_component, overwrite=False)[source]#

Set scaling factor for target_variable equal to that of scaling_component.

Parameters:
  • target_variable – variable to set scaling factor for

  • scaling_component – component to use for scaling factor

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_variable_by_default(variable, overwrite=False)[source]#

Set scaling factor for variable based on default scaling factor.

Parameters:
  • variable – variable to set scaling factor for

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

scale_variable_by_units(variable, overwrite=False)[source]#

Set scaling factor for variable based on units of measurement.

Units of measurement for variable are compared to those stored in self.unit_scaling_factors, and if a match is found the scaling factor set using the associated value.

Parameters:
  • variable – variable to set scaling factor for

  • overwrite (bool) – whether to overwrite existing scaling factors

Returns:

None

variable_scaling_routine(model, overwrite=False, submodel_scalers=None)[source]#

Routine to apply scaling factors to variables in model.

Derived classes must overload this method.

Parameters:
  • model – model to be scaled

  • overwrite (bool) – whether to overwrite existing scaling factors

  • submodel_scalers (ComponentMap) – ComponentMap of Scalers to use for sub-models

Returns:

None