Model Diagnostic Functions

The IDAES toolset contains a number of utility functions which can be useful for identifying modeling issues and debugging solver issues.

Degeneracy Hunter

class idaes.core.util.model_diagnostics.DegeneracyHunter(block_or_jac, solver=None)[source]

Degeneracy Hunter is a collection of utility functions to assist in mathematical modeling in Pyomo.

check_rank_equality_constraints(tol=1e-06, dense=False)[source]

Method to check the rank of the Jacobian of the equality constraints

Parameters
  • tol – Tolerance for smallest singular value (default=1E-6)

  • dense – If True, use a dense svd to perform singular value analysis, which tends to be slower but more reliable than svds

Returns

Number of singular values less than tolerance (-1 means error)

check_residuals(tol=1e-05, print_level=1, sort=True)[source]

Method to return a ComponentSet of all Constraint components with a residual greater than a given threshold which appear in a model.

Parameters
  • block – model to be studied

  • tol – residual threshold for inclusion in ComponentSet

  • print_level

    controls to extend of output to the screen:

    • 0 - nothing printed

    • 1 - only name of constraint printed

    • 2 - each constraint is pretty printed

    • 3 - pretty print each constraint, then print value for included variable

  • sort – sort residuals in descending order for printing

Returns

A ComponentSet including all Constraint components with a residual greater than tol which appear in block

check_variable_bounds(tol=1e-05, relative=False, skip_lb=False, skip_ub=False, verbose=True)[source]

Return a ComponentSet of all variables within a tolerance of their bounds.

Parameters
  • block – model to be studied

  • tol – residual threshold for inclusion in ComponentSet (default = 1e-5)

  • relative – Boolean, use relative tolerance (default = False)

  • skip_lb – Boolean to skip lower bound (default = False)

  • skip_ub – Boolean to skip upper bound (default = False)

  • verbose – Boolean to toggle on printing to screen (default = True)

Returns

A ComponentSet including all Constraint components with a residual greater than tol which appear in block

find_candidate_equations(verbose=True, tee=False)[source]

Solve MILP to find a degenerate set and candidate equations

Parameters
  • verbose – Print information to the screen (default=True)

  • tee – Print solver output to screen (default=True)

Returns

either None or dictionary of candidate equations

Return type

ds

find_irreducible_degenerate_sets(verbose=True, tee=False)[source]

Compute irreducible degenerate sets

Parameters
  • verbose – Print information to the screen (default=True)

  • tee – Print solver output to screen (default=True)

Returns

list of irreducible degenerate sets

Return type

irreducible_degenerate_sets

static print_variable_bounds(v)[source]

Print variable, bounds, and value

Parameters

v – variable

Returns

None

svd_analysis(n_sv=None, dense=False)[source]

Perform SVD analysis of the constraint Jacobian

Parameters
  • n_sv – number of smallest singular values to compute

  • dense – If True, use a dense svd to perform singular value analysis, which tends to be slower but more reliable than svds

Returns

None

Actions:

Stores SVD results in object

underdetermined_variables_and_constraints(n_calc=1, tol=0.1, dense=False)[source]

Determines constraints and variables associated with the smallest singular values by having large components in the left and right singular vectors, respectively, associated with those singular values.

Parameters
  • n_calc – The singular value, as ordered from least to greatest starting from 1, to calculate associated constraints and variables

  • tol – Size below which to ignore constraints and variables in the singular vector

  • dense – If True, use a dense svd to perform singular value analysis, which tends to be slower but more reliable than svds

Returns

None

Available Methods

This module contains a collection of tools for diagnosing modeling issues.

idaes.core.util.model_diagnostics.get_valid_range_of_component(component)[source]

Return the valid range for a component as specified in the model metadata.

Parameters

component – Pyomo component to get valid range for

Returns

valid range for component if found. This will either be a 2-tuple (low, high) or None.

Raises

AttributeError if metadata object not found

idaes.core.util.model_diagnostics.ipopt_solve_halt_on_error(model, options=None)[source]

Run IPOPT to solve model with debugging output enabled.

This function calls IPOPT to solve the model provided with settings to halt on AMPL evaluation errors and report these with symbolic names.

Parameters
  • model – Pyomo model to be solved.

  • options – solver options to be passed to IPOPT

Returns

Pyomo solver results dict

idaes.core.util.model_diagnostics.list_components_with_values_outside_valid_range(component, descend_into=True)[source]

Return a list of component objects with values outside the valid range specified in the model metadata.

This function will iterate over component data objects in Blocks and indexed components.

Parameters
  • component – Pyomo component to search for component outside of range on. This can be a Block, Var or Param.

  • descend_into – (optional) Whether to descend into components on child Blocks (default=True)

Returns

list of component objects found with values outside the valid range.

idaes.core.util.model_diagnostics.set_bounds_from_valid_range(component, descend_into=True)[source]

Set bounds on Pyomo components based on valid range recorded in model metadata. WARNING - this function will overwrite any bounds already set on the component/model.

This function will iterate over component data objects in Blocks and indexed components.

Parameters
  • component – Pyomo component to set bounds on. This can be a Block, Var or Param.

  • descend_into – (optional) Whether to descend into components on child Blocks (default=True)

Returns

None