Scaling Utility Functions#

Utility functions for scaling.

Author: Andrew Lee

idaes.core.scaling.util.del_scaling_factor(component, delete_empty_suffix=False)[source]#

Delete scaling factor for component.

Parameters:
  • component – component to delete scaling factor for

  • delete_empty_suffix (bool) – (bool) whether to delete scaling Suffix if it is empty after deletion.

idaes.core.scaling.util.get_nominal_value(component)[source]#

Get the signed nominal value for a VarData or ParamData component.

For fixed Vars and Params, the current value of the component will be returned.

For unfixed Vars, the nominal value is determined using the assigned scaling factor and the sign determined based on the bounds and domain of the variable (defaulting to positive). If no scaling factor is set, then the current value will be used if set, otherwise the absolute nominal value will be equal to 1.

Parameters:

component – component to determine nominal value for

Returns:

signed float with nominal value

Raises:

TypeError if component is not instance of VarData or ParamData

idaes.core.scaling.util.get_scaling_factor(component)[source]#

Get scaling factor for component.

Parameters:

component – component to get scaling factor for

Returns:

float scaling factor

Raises:

TypeError if component is a Block

idaes.core.scaling.util.get_scaling_suffix(component)[source]#

Get scaling suffix for component.

If component is not a Block, gets scaling suffix from parent block. Creates a new suffix if one is not found.

Parameters:

component – component to get suffix for

Returns:

Pyomo scaling Suffix

Raises:

TypeError is component is an IndexedBlock

idaes.core.scaling.util.report_scaling_factors(blk, ctype=None, descend_into=False, stream=None)[source]#

Write the scaling factors for all components in a Block to a stream.

Parameters:
  • blk (Block) – Block to get scaling factors from.

  • ctype – None, Var or Constraint. Type of component to show scaling factors for (if None, shows both Vars and Constraints).

  • descend_into (bool) – whether to show scaling factors for components in sub-blocks.

  • stream – StringIO object to write results to. If not provided, writes to stdout.

Raises:
  • TypeError if blk is not a Pyomo Block.

  • ValueError is ctype is not None, Var or Constraint.

idaes.core.scaling.util.scaling_factors_from_dict(blk_or_suffix, json_dict, overwrite=False, verify_names=True)[source]#

Set scaling factors based on values in a serializable json dict.

This method expects components to be referenced by their local names.

Parameters:
  • blk_or_suffix – Pyomo Block or Suffix object to set scaling factors on

  • json_dict (dict) – dict of scaling factors to load into model

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

  • verify_names (bool) – (bool) whether to verify that all names in dict exist on block

Returns

None

Raises:

TypeError if blk_or_suffix is not an instance of Block or Suffix

Parameters:
idaes.core.scaling.util.scaling_factors_from_json_file(blk_or_suffix, filename, overwrite=False, verify_names=True)[source]#

Load scaling factors from json file.

Parameters:
  • blk_of_suffix – Block or Suffix to load scaling factors for

  • filename (str) – name of file to load as string

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

  • verify_names (bool) – (bool) whether to verify that all names in dict exist on block

Returns:

None

Raises:

TypeError if blk_or_suffix is not an instance of Block or Suffix

idaes.core.scaling.util.scaling_factors_to_dict(blk_or_suffix, descend_into=True)[source]#

Write scaling suffixes to a serializable json dict.

Component objects are replaced by their local names so they can be serialized.

Parameters:
  • blk_or_suffix – Pyomo Block or Suffix object to covert to dict

  • descend_into (bool) – for Blocks, whether to descend into any child blocks

Returns

dict containing scaling factors indexed by component names

Raises:

TypeError if blk_or_suffix is not an instance of Block or Suffix

Parameters:

descend_into (bool)

idaes.core.scaling.util.scaling_factors_to_json_file(blk_or_suffix, filename)[source]#

Serialize scaling factors to file in json format.

Parameters:
  • blk_of_suffix – Block or Suffix to save scaling factors for

  • filename (str) – name of file to write to as string

Returns:

None

Raises:

TypeError if blk_or_suffix is not an instance of Block or Suffix

idaes.core.scaling.util.set_scaling_factor(component, scaling_factor, overwrite=False)[source]#

Set scaling factor for component.

Scaling factors must be positive, non-zero floats.

Parameters:
  • component – component to set scaling factor for

  • scaling_factor (float) – scaling factor to assign

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

Returns:

None

Raises:

ValueError is scaling_factor is 0 or negative