Miscellaneous Utility Methods

get_solver

The get_solver method is primarily intended for use when a solver object is required in a general model. The get_solver method takes two optional arguments which allow the user to specify a specific solver and/or solver options if required, or to use the default solver specified in the IDAES Configuration if no arguments are provided.

idaes.core.util.misc.get_solver(solver=None, options=None)[source]

General method for getting a solver object which defaults to the standard IDAES solver (defined in the IDAES configuration).

Parameters
  • solver – string name for desired solver. Default=None, use default solver

  • options – dict of solver options to use, overwrites any settings provided by IDAES configuration. Default = None, use default solver options.

Returns

A Pyomo solver object

Variable-Like Expressions

There are a number of cases within IDAES where a modeler may wish to use an Expression in place of a Var to reduce the complexity of their model. A common example of this is in the ideal Separator unit where the outlet Ports use Expressions for the state variable in order to reduce the number of variables (and thus constraints) in the model.

In these cases, it is possible that a user might mistake the Expression for a Var and attempt to use methods such as fix() on it. In order to provide the user with a useful error message informing them that this will not work, IDAES has created a derived VarLikeExpression component for these situations. This component derives directly from Pyomo’s Expression component and implements common methods associated with Vars which will return an error message informing the user that the component is an Expression, and a suggestion on how to proceed.

class idaes.core.util.misc.VarLikeExpression(*args, **kwds)[source]

A shared var-like expression container, which may be defined over a index.

Constructor Arguments:

initialize: A Pyomo expression or dictionary of expressions used to initialize this object.

expr: A synonym for initialize.

rule: A rule function used to initialize this object.

class idaes.core.util.misc.SimpleVarLikeExpression(*args, **kwds)[source]
add(index, expr)[source]

Add an expression with a given index.

class idaes.core.util.misc.IndexedVarLikeExpression(*args, **kwds)[source]
add(index, expr)[source]

Add an expression with a given index.

class idaes.core.util.misc._GeneralVarLikeExpressionData(expr=None, component=None)[source]

An object derived from _GeneralExpressionData which implements methods for common APIs on Vars.

Constructor Arguments:

expr: The Pyomo expression stored in this expression.

component: The Expression object that owns this data.

Public Class Attributes:

expr: The expression owned by this data.

Private class attributes:

_component: The expression component.

property value

DEPRECATED.

Deprecated since version 4.3.11323: The .value property getter on _GeneralExpressionDataImpl is deprecated. Use the .expr property getter instead

Other Utility Methods

This library also contains a number of other utility methods that do not fall under another category.

idaes.core.util.misc.add_object_reference(self, local_name, remote_object)[source]

Method to create a reference in the local model to a remote Pyomo object. This method should only be used where Pyomo Reference objects are not suitable (such as for referencing scalar Pyomo objects where the None index is undesirable).

Parameters
  • local_name – name to use for local reference (str)

  • remote_object – object to make a reference to

Returns

None

idaes.core.util.misc.copy_port_values(destination=None, source=None, arc=None, direction='forward')[source]

Moved to idaes.core.util.initialization.propagate_state. Leaving redirection function here for deprecation warning.

idaes.core.util.misc.extract_data(data_dict)[source]

General method that returns a rule to extract data from a python dictionary. This method allows the param block to have a database for a parameter but extract a subset of this data to initialize a Pyomo param object.

idaes.core.util.misc.set_param_from_config(b, param, config=None, index=None)[source]

Utility method to set parameter value from a config block. This allows for converting units if required. This method directly sets the value of the parameter.

Parameters
  • defined (b - block on which parameter and config block are) –

  • arg (param - name of parameter as str. Used to find param and config) –

  • object (units - units of param) –

  • - (index) – unset, assumes b.config.

  • - – property may have multiple parameters associated with it.

Returns

None

idaes.core.util.misc.TagReference(s, description='')[source]

Create a Pyomo reference with an added description string attribute to describe the reference. The intended use for these references is to create a time-indexed reference to variables in a model corresponding to plant measurment tags.

Parameters
  • s – Pyomo time slice of a variable or expression

  • description (str) – A description the measurment

Returns

A Pyomo Reference object with an added doc attribute

idaes.core.util.misc.svg_tag(tags, svg, outfile=None, idx=None, tag_map=None, show_tags=False, byte_encoding='utf-8', tag_format=None, tag_format_default='{:.4e}')[source]

Replace text in a SVG with tag values for the model. This works by looking for text elements in the SVG with IDs that match the tags or are in tag_map.

Parameters
  • tags – A dictionary where the key is the tag and the value is a Pyomo Reference. The reference could be indexed. In typical IDAES applications the references would be indexed by time.

  • svg – a file pointer or a string continaing svg contents

  • outfile – a file name to save the results, if None don’t save

  • idx – if None not indexed, otherwise an index in the indexing set of the reference

  • tag_map – dictionary with svg id keys and tag values, to map svg ids to tags

  • show_tags – Put tag labels of the diagram instead of numbers

  • byte_encoding – If svg is given as a byte-array, use this encoding to convert it to a string.

  • tag_format – A dictionary of formatting strings. If the formatting string is a callable, it should be a function that takes the value to display and returns a formatting string.

  • tag_format_default – The default formatting if not explicitly by tag_format. If the formatting string is a callable, it should be a function that takes the value to display and returns a formatting string.

Returns

SVG String