Scaling Profiler Utility#

class idaes.core.scaling.scaler_profiling.ScalingProfiler(build_model, user_scaling, perturb_state=None, scaling_methods=None, solver=None)[source]#

Class for running a set of constraint scaling methods on a model and reporting the effect on model condition number and solver behavior.

Users should call the profile_scaling_methods method to generate a dict of results or the report_scaling_profiles method for a stream-based output.

Users are expected to provide callback functions to 1) construct an initialized model that will be used for profiling, 2) apply user-defined variable scaling (used for the imperfect information case) and 3) perturb the model from the initialized state to test how well the model solves (optional).

Users may also provide a dict of scaling methods they wish to apply using the scaling_methods argument. If this is not provided, the tool will default to applying all the scaling methods defined by the AutoScaler and CustomScalerBase classes.

NOTE methods from the AutoScaler class are applied to Pyomo Blocks, whilst those from CustomScalerBase are applied to individual ConstraintDatas. The profiling tool assumes that methods will be applied to ConstraintDatas unless the block_based keyword argument is set to True for the scaling method.

Parameters:
  • build_model – callback to use to construct initialized model for testing

  • user_scaling – callback to use to apply user-defined scaling to initialized model

  • perturb_states – (optional) callback to use to perturb model state for re-solve tests

  • scaling_methods (dict) – (optional) dict of constraint scaling methods to profile. {“Name”: (method, kwargs)}

  • solver – (optional) Pyomo solver object to use for re-solve tests

profile_scaling_methods()[source]#

Generate results for all provided scaling methods.

For each scaling method, calculate the Jacobian condition number and re-solve the model with both user-provided variable scaling and perfect variable scaling (scaling by inverse magnitude). A base case with no scaling applied is also run for reference.

Parameters:

None

Returns:

dict with results for all scaling methods

report_scaling_profiles(stream=None)[source]#

Run scaling profile workflow nad report results to a stream.

Parameters:

stream – StringIO object to write result to (default=stdout)

Returns:

None

run_case(scaling_method, **kwargs)[source]#

Run case for a given scaling method with both perfect and imperfect scaling information.

Parameters:
  • scaling_method – constraint scaling method to be tested

  • kwargs – keyword argument to be passed to scaling method

Returns:

dict summarising results of scaling case

write_profile_report(results, stream=None)[source]#

Write a report on the comparison of scaling methods to a stream based on existing results dict.

Parameters:
  • results (dict) – dict containing results from a scaler profiling run

  • stream – StringIO object to write result to (default=stdout)

Returns:

None