CustomScalerBase Class#
- class idaes.core.scaling.custom_scaler_base.ConstraintScalingScheme(value)[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.
- max_expression_scaling_hint
Maximum value for expression scaling hints.
- min_expression_scaling_hint
Minimum value for constraint scaling hints.
- 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 (VarData | ConstraintData | ExpressionData) – component to get default scaling factor for
- Returns:
default scaling factor if it exists, else None
- get_expression_nominal_value(expression)[source]#
Calculate nominal value for a Pyomo expression.
The nominal value of any Var is defined as the inverse of its scaling factor (if assigned, else 1).
- Parameters:
expression (ConstraintData | ExpressionData) – Pyomo expression to obtain nominal value for
- Returns:
float of nominal value
- 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 (ConstraintData | ExpressionData) – Pyomo expression to collect nominal values for
- Returns:
list of nominal values for each additive term
- get_sum_terms_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 (ConstraintData | ExpressionData) – 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.
If both source and target state are indexed, the index sets must match. If the source state block is indexed, the target state block must also be indexed.
- 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 (ConstraintData) – constraint to set scaling factor for
scaling_component (VarData | ConstraintData | ExpressionData) – 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 (ConstraintData) – 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 (ConstraintData) – 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 (ConstraintData) – 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:
Scale variables using variable_scaling_routine
Perform first-stage scaling factor fill in using user provided method(s), called in order declared
Scale constraints using constraint_scaling_routine
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.
- 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 (VarData) – variable to set scaling factor for
scaling_component (VarData | ConstraintData | ExpressionData) – 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 or scaling hint for named expression based on default scaling factor.
- Parameters:
variable (VarData | ExpressionData) – variable/expression to set scaling factor for
overwrite (bool) – whether to overwrite existing scaling factors
- Returns:
None
- scale_variable_by_definition_constraint(variable, constraint, overwrite=False)[source]#
Set scaling factor for variable via a constraint that defines it. We expect a constraint of the form variable == prod(v ** nu for v, nu in zip(other_variables, variable_exponents), and set a scaling factor for a variable based on the nominal value of the righthand side.
This method may return a result even if the constraint does not have this expected form, but the resulting scaling factor may not be suitable.
- Parameters:
variable – variable to set scaling factor for
constraint – constraint defining this variable
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