idaes.core.util package¶

idaes.core.util.config module¶

This module contains utility functions useful for validating arguments to IDAES modeling classes. These functions are primarily designed to be used as the domain argument in ConfigBlocks.

idaes.core.util.config.is_physical_parameter_block(val)[source]

Domain validator for property package attributes

Parameters: val – value to be checked ConfigurationError if val is not an instance of PhysicalParameterBlock or useDefault
idaes.core.util.config.is_port(arg)[source]

Domain validator for ports

Parameters: arg – argument to be checked as a Port Port object or Exception
idaes.core.util.config.is_reaction_parameter_block(val)[source]

Domain validator for reaction package attributes

Parameters: val – value to be checked ConfigurationError if val is not an instance of ReactionParameterBlock
idaes.core.util.config.is_state_block(val)[source]

Domain validator for state block as an argument

Parameters: val – value to be checked ConfigurationError if val is not an instance of StateBlock or None
idaes.core.util.config.is_time_domain(arg)[source]

Domain validator for time domains

Parameters: arg – argument to be checked as a time domain (i.e. Set or ContinuousSet) – Set, ContinuousSet or Exception
idaes.core.util.config.is_transformation_method(arg)[source]

Domain validator for transformation methods

Parameters: arg – argument to be checked for membership in recognized strings Recognised string or Exception
idaes.core.util.config.is_transformation_scheme(arg)[source]

Domain validator for transformation scheme

Parameters: arg – argument to be checked for membership in recognized strings Recognised string or Exception
idaes.core.util.config.list_of_floats(arg)[source]

Domain validator for lists of floats

Parameters: arg – argument to be cast to list of floats and validated List of strings
idaes.core.util.config.list_of_strings(arg)[source]

Domain validator for lists of strings

Parameters: arg – argument to be cast to list of strings and validated List of strings

idaes.core.util.exceptions module¶

This module contains custom IDAES exceptions.

exception idaes.core.util.exceptions.BalanceTypeNotSupportedError[source]

IDAES exception to be used when a control volumedoes not support a given type of balance equation.

exception idaes.core.util.exceptions.BurntToast[source]

General exception for when something breaks badly in the core.

exception idaes.core.util.exceptions.ConfigurationError[source]

IDAES exception to be used when configuration arguments are incorrect or inconsistent.

exception idaes.core.util.exceptions.DynamicError[source]

IDAES exception for cases where settings associated with dynamic models are incorrect.

exception idaes.core.util.exceptions.PropertyNotSupportedError[source]

IDAES exception for cases when a models calls for a property which is not supported by the chosen property package.

Needs to inherit from AttributeError for Pyomo interactions.

exception idaes.core.util.exceptions.PropertyPackageError[source]

IDAES exception for generic errors arising from property packages.

Needs to inherit from AttributeError for Pyomo interactions.

idaes.core.util.expr_doc module¶

class idaes.core.util.expr_doc.Pyomo2SympyVisitor(object_map)[source]

This is based on the class of the same name in pyomo.core.base.symbolic, but it catches ExternalFunctions and does not decend into named expressions.

class idaes.core.util.expr_doc.PyomoSympyBimap[source]

This is based on the class of the same name in pyomo.core.base.symbolic, but it adds mapping latex symbols to the sympy symbols. This will get you pretty equations when using sympy’s LaTeX writer.

idaes.core.util.expr_doc.deduplicate_symbol(x, v, used)[source]

Check if x is a duplicated LaTeX symbol if so add incrementing Di subscript

Parameters: x – symbol string v – pyomo object used – dictionary of pyomo objects with symbols as keys Returns a unique symbol. If x was not in used keys, returns x, otherwise adds exponents to make it unique.
idaes.core.util.expr_doc.document_constraints(comp, doc=True, descend_into=True)[source]

Provides nicely formatted constraint documetntation in markdown format, assuming the $$latex math$$ and $latex math$ syntax is supported.

Parameters: comp – A Pyomo component to document in {_ConstraintData, _ExpressionData, _BlockData}. doc – True adds a documentation table for each constraint or expression. Due to the way symbols are semi-automatiaclly generated, the exact symbol definitions may be unique to each constraint or expression, if unique LaTeX symbols were not provided everywhere in a block. descend_into – If True, look in subblocks for constraints. A string in markdown format with equations in LaTeX form.
idaes.core.util.expr_doc.ipython_document_constraints(comp, doc=True, descend_into=True)[source]

See document_constraints, this just directly displays the markdown instead of returning a string.

idaes.core.util.expr_doc.sympify_expression(expr)[source]

Converts Pyomo expressions to sympy expressions. This is based on the function of the same name in pyomo.core.base.symbolic. The difference between this and the Pymomo is that this one checks if the expr argument is a named expression and expands it anyway. This allows named expressions to only be expanded if they are the top level object.

idaes.core.util.expr_doc.to_latex(expr)[source]

Return a sympy expression for the given Pyomo expression

Parameters: expr (Expression) – Pyomo expression keys: sympy_expr, a sympy expression; where, markdown string with documentation table; latex_expr, a LaTeX string representation of the expression. (dict)

idaes.core.util.initialization module¶

This module contains utility functions for initialization of IDAES models.

idaes.core.util.initialization.propagate_state(stream, direction='forward')[source]

This method propagates values between Ports along Arcs. Values can be propagated in either direction using the direction argument.

Parameters: stream – Arc object along which to propagate values direction – direction in which to propagate values. Default = ‘forward’ Valid value: ‘forward’, ‘backward’. None
idaes.core.util.initialization.solve_indexed_blocks(solver, blocks, **kwds)[source]

This method allows for solving of Indexed Block components as if they were a single Block. A temporary Block object is created which is populated with the contents of the objects in the blocks argument and then solved.

Parameters: solver – a Pyomo solver object to use when solving the Indexed Block blocks – an object which inherits from Block, or a list of Blocks kwds – a dict of argumnets to be passed to the solver A Pyomo solver results object

idaes.core.util.math module¶

This module contains utility functions for mathematical operators of use in equation oriented models.

idaes.core.util.math.smooth_abs(a, eps=0.0001)[source]

General function for creating an expression for a smooth minimum or maximum.

$|a| = sqrt(a^2 + eps^2)$
Parameters: a – term to get absolute value from (Pyomo component, float or int) eps – smoothing parameter (Param, float or int) (default=1e-4) An expression for the smoothed absolute value operation.
idaes.core.util.math.smooth_max(a, b, eps=0.0001)[source]

Smooth maximum operator, using smooth_abs operator.

$max(a, b) = 0.5*(a+b + |a-b|)$
Parameters: a – first term in max function b – second term in max function eps – smoothing parameter (Param or float, default = 1e-4) An expression for the smoothed maximum operation.
idaes.core.util.math.smooth_min(a, b, eps=0.0001)[source]

Smooth minimum operator, using smooth_abs operator.

$max(a, b) = 0.5*(a+b - |a-b|)$
Parameters: a – first term in min function b – second term in min function eps – smoothing parameter (Param or float, default = 1e-4) An expression for the smoothed minimum operation.
idaes.core.util.math.smooth_minmax(a, b, eps=0.0001, sense='max')[source]

General function for creating an expression for a smooth minimum or maximum. Uses the smooth_abs operator.

$minmax(a, b) = 0.5*(a+b +- |a-b|)$
Parameters: a – first term in mix or max function (Pyomo component, float or int) b – second term in min or max function (Pyomo component, float or int) eps – smoothing parameter (Param, float or int) (default=1e-4) sense – ‘mim’ or ‘max’ (default = ‘max’) An expression for the smoothed minimum or maximum operation.

idaes.core.util.misc module¶

This module contains miscellaneous utility functions for use in IDAES models.

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 A Pyomo Reference object with an added doc attribute
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 None
idaes.core.util.misc.copy_port_values(destination, source)[source]

Copy the variable values in the source port to the destination port. The ports must containt the same variables.

Parameters: (pyomo.Port) – Copy values from this port (pyomo.Port) – Copy values to this port None
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.svg_tag(tags, svg, outfile=None, idx=None, tag_map=None, show_tags=False)[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 Refernce. The refernce could be indexed. In yypical 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 String for SVG

idaes.core.util.model_serializer module¶

class idaes.core.util.model_serializer.Counter[source]

This is a counter object, which is an easy way to pass an interger pointer around between methods.

class idaes.core.util.model_serializer.StoreSpec(classes=((<class 'pyomo.core.base.param.Param'>, ('_mutable', )), (<class 'pyomo.core.base.var.Var'>, ()), (<class 'pyomo.core.base.component.Component'>, ('active', ))), data_classes=((<class 'pyomo.core.base.var._VarData'>, ('fixed', 'stale', 'value', 'lb', 'ub')), (<class 'pyomo.core.base.param._ParamData'>, ('value', )), (<class 'int'>, ('value', )), (<class 'float'>, ('value', )), (<class 'pyomo.core.base.component.ComponentData'>, ('active', ))), skip_classes=(<class 'pyomo.core.base.external.ExternalFunction'>, <class 'pyomo.core.base.sets.Set'>, <class 'pyomo.network.port.Port'>, <class 'pyomo.core.base.expression.Expression'>, <class 'pyomo.core.base.rangeset.RangeSet'>), ignore_missing=True, suffix=True, suffix_filter=None)[source]

A StoreSpec object tells the serializer functions what to read or write. The default settings will produce a StoreSpec configured to load/save the typical attributes required to load/save a model state.

classmethod bound()[source]

Returns a StoreSpec object to store variable bounds only.

get_class_attr_list(o)[source]

Look up what attributes to save/load for an Component object. :param o: Object to look up attribute list for.

Returns: A list of attributes and a filter function for object type
get_data_class_attr_list(o)[source]

Look up what attributes to save/load for an ComponentData object. :param o: Object to look up attribute list for.

Returns: A list of attributes and a filter function for object type
classmethod isfixed()[source]

Returns a StoreSpec object to store if variables are fixed.

set_read_callback(attr, cb=None)[source]

Set a callback to set an attribute, when reading from json or dict.

set_write_callback(attr, cb=None)[source]

Set a callback to get an attribute, when writing to json or dict.

classmethod value()[source]

Returns a StoreSpec object to store variable values only.

classmethod value_isfixed(only_fixed)[source]

Return a StoreSpec object to store variable values and if fixed.

Parameters: only_fixed – Only load fixed variable values
classmethod value_isfixed_isactive(only_fixed)[source]

Retur a StoreSpec object to store variable values, if variables are fixed and if components are active.

Parameters: only_fixed – Only load fixed variable values
idaes.core.util.model_serializer.component_data_from_dict(sd, o, wts)[source]

Component data to a dict.

idaes.core.util.model_serializer.component_data_to_dict(o, wts)[source]

Component data to a dict.

idaes.core.util.model_serializer.from_json(o, sd=None, fname=None, s=None, wts=None, gz=False)[source]

Load the state of a Pyomo component state from a dictionary, json file, or json string. Must only specify one of sd, fname, or s as a non-None value. This works by going through the model and loading the state of each sub-compoent of o. If the saved state contains extra information, it is ignored. If the save state doesn’t contain an enetry for a model component that is to be loaded an error will be raised, unless ignore_missing = True.

idaes.core.util.model_serializer.to_json(o, fname=None, human_read=False, wts=None, metadata={}, gz=False, return_dict=False, return_json_string=False)[source]

Save the state of a model to a Python dictionary, and optionally dump it to a json file. To load a model state, a model with the same structure must exist. The model itself cannot be recreated from this.

Parameters: o – The Pyomo component object to save. Usually a Pyomo model, but could also be a subcomponent of a model (usually a sub-block). fname – json file name to save model state, if None only create python dict gz – If fname is given and gv is True gzip the json file. The default is False. human_read – if True, add indents and spacing to make the json file more readable, if false cut out whitespace and make as compact as possilbe metadata – A dictionary of addtional metadata to add. wts – is What To Save, this is a StoreSpec object that specifies what object types and attributes to save. If None, the default is used which saves the state of the compelte model state. metadata – addtional metadata to save beyond the standard format_version, date, and time. return_dict – default is False if true returns a dictionary representation return_json_string – default is False returns a json string If return_dict is True returns a dictionary serialization of the Pyomo component. If return_dict is False and return_json_string is True returns a json string dump of the dict. If fname is given the dictionary is also written to a json file. If gz is True and fname is given, writes a gzipped json file.

idaes.core.util.model_statistics module¶

This module contains utility functions for reporting structural statistics of IDAES models.

idaes.core.util.model_statistics.activated_block_component_generator(block, ctype)[source]

Generator which returns all the components of a given ctype which exist in activated Blocks within a model.

Parameters: block – model to be studied ctype – type of Pyomo component to be returned by generator. A generator which returns all components of ctype which appear in activated Blocks in block
idaes.core.util.model_statistics.activated_blocks_set(block)[source]

Method to return a ComponentSet of all activated Block components in a model.

Parameters: block – model to be studied A ComponentSet including all activated Block components in block (including block itself)
idaes.core.util.model_statistics.activated_constraints_generator(block)[source]

Generator which returns all activated Constraint components in a model.

Parameters: block – model to be studied A generator which returns all activated Constraint components block
idaes.core.util.model_statistics.activated_constraints_set(block)[source]

Method to return a ComponentSet of all activated Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all activated Constraint components in block
idaes.core.util.model_statistics.activated_equalities_generator(block)[source]

Generator which returns all activated equality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all activated equality Constraint components block
idaes.core.util.model_statistics.activated_equalities_set(block)[source]

Method to return a ComponentSet of all activated equality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all activated equality Constraint components in block
idaes.core.util.model_statistics.activated_inequalities_generator(block)[source]

Generator which returns all activated inequality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all activated inequality Constraint components block
idaes.core.util.model_statistics.activated_inequalities_set(block)[source]

Method to return a ComponentSet of all activated inequality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all activated inequality Constraint components in block
idaes.core.util.model_statistics.activated_objectives_generator(block)[source]

Generator which returns all activated Objective components in a model.

Parameters: block – model to be studied A generator which returns all activated Objective components block
idaes.core.util.model_statistics.activated_objectives_set(block)[source]

Method to return a ComponentSet of all activated Objective components which appear in a model.

Parameters: block – model to be studied A ComponentSet including all activated Objective components which appear in block
idaes.core.util.model_statistics.active_variables_in_deactivated_blocks_set(block)[source]

Method to return a ComponentSet of any Var components which appear within an active Constraint but belong to a deacitvated Block in a model.

Parameters: block – model to be studied A ComponentSet including any Var components which belong to a deacitvated Block but appear in an activate Constraint in block
idaes.core.util.model_statistics.deactivated_blocks_set(block)[source]

Method to return a ComponentSet of all deactivated Block components in a model.

Parameters: block – model to be studied A ComponentSet including all deactivated Block components in block (including block itself)
idaes.core.util.model_statistics.deactivated_constraints_generator(block)[source]

Generator which returns all deactivated Constraint components in a model.

Parameters: block – model to be studied A generator which returns all deactivated Constraint components block
idaes.core.util.model_statistics.deactivated_constraints_set(block)[source]

Method to return a ComponentSet of all deactivated Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all deactivated Constraint components in block
idaes.core.util.model_statistics.deactivated_equalities_generator(block)[source]

Generator which returns all deactivated equality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all deactivated equality Constraint components block
idaes.core.util.model_statistics.deactivated_equalities_set(block)[source]

Method to return a ComponentSet of all deactivated equality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all deactivated equality Constraint components in block
idaes.core.util.model_statistics.deactivated_inequalities_generator(block)[source]

Generator which returns all deactivated inequality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all indeactivated equality Constraint components block
idaes.core.util.model_statistics.deactivated_inequalities_set(block)[source]

Method to return a ComponentSet of all deactivated inequality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all deactivated inequality Constraint components in block
idaes.core.util.model_statistics.deactivated_objectives_generator(block)[source]

Generator which returns all deactivated Objective components in a model.

Parameters: block – model to be studied A generator which returns all deactivated Objective components block
idaes.core.util.model_statistics.deactivated_objectives_set(block)[source]

Method to return a ComponentSet of all deactivated Objective components which appear in a model.

Parameters: block – model to be studied A ComponentSet including all deactivated Objective components which appear in block
idaes.core.util.model_statistics.degrees_of_freedom(block)[source]

Method to return the degrees of freedom of a model.

Parameters: block – model to be studied Number of degrees of freedom in block.
idaes.core.util.model_statistics.derivative_variables_set(block)[source]

Method to return a ComponentSet of all DerivativeVar components which appear in a model. Users should note that DerivativeVars are converted to ordinary Vars when a DAE transformation is applied. Thus, this method is useful for detecting any DerivativeVars which were do transformed.

Parameters: block – model to be studied A ComponentSet including all DerivativeVar components which appear in block
idaes.core.util.model_statistics.expressions_set(block)[source]

Method to return a ComponentSet of all Expression components which appear in a model.

Parameters: block – model to be studied A ComponentSet including all Expression components which appear in block
idaes.core.util.model_statistics.fixed_unused_variables_set(block)[source]

Method to return a ComponentSet of all fixed Var components which do not appear within any activated Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all fixed Var components which do not appear within any Constraints in block
idaes.core.util.model_statistics.fixed_variables_generator(block)[source]

Generator which returns all fixed Var components in a model.

Parameters: block – model to be studied A generator which returns all fixed Var components block
idaes.core.util.model_statistics.fixed_variables_in_activated_equalities_set(block)[source]

Method to return a ComponentSet of all fixed Var components which appear within an equality Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all fixed Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.fixed_variables_only_in_inequalities(block)[source]

Method to return a ComponentSet of all fixed Var components which appear only within activated inequality Constraints in a model.

Parameters: block – model to be studied A ComponentSet including all fixed Var components which appear only within activated inequality Constraints in block
idaes.core.util.model_statistics.fixed_variables_set(block)[source]

Method to return a ComponentSet of all fixed Var components in a model.

Parameters: block – model to be studied A ComponentSet including all fixed Var components in block
idaes.core.util.model_statistics.large_residuals_set(block, tol=1e-05)[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 A ComponentSet including all Constraint components with a residual greater than tol which appear in block
idaes.core.util.model_statistics.number_activated_blocks(block)[source]

Method to return the number of activated Block components in a model.

Parameters: block – model to be studied Number of activated Block components in block (including block itself)
idaes.core.util.model_statistics.number_activated_constraints(block)[source]

Method to return the number of activated Constraint components in a model.

Parameters: block – model to be studied Number of activated Constraint components in block
idaes.core.util.model_statistics.number_activated_equalities(block)[source]

Method to return the number of activated equality Constraint components in a model.

Parameters: block – model to be studied Number of activated equality Constraint components in block
idaes.core.util.model_statistics.number_activated_inequalities(block)[source]

Method to return the number of activated inequality Constraint components in a model.

Parameters: block – model to be studied Number of activated inequality Constraint components in block
idaes.core.util.model_statistics.number_activated_objectives(block)[source]

Method to return the number of activated Objective components which appear in a model.

Parameters: block – model to be studied Number of activated Objective components which appear in block
idaes.core.util.model_statistics.number_active_variables_in_deactivated_blocks(block)[source]

Method to return the number of Var components which appear within an active Constraint but belong to a deacitvated Block in a model.

Parameters: block – model to be studied Number of Var components which belong to a deacitvated Block but appear in an activate Constraint in block
idaes.core.util.model_statistics.number_deactivated_blocks(block)[source]

Method to return the number of deactivated Block components in a model.

Parameters: block – model to be studied Number of deactivated Block components in block (including block itself)
idaes.core.util.model_statistics.number_deactivated_constraints(block)[source]

Method to return the number of deactivated Constraint components in a model.

Parameters: block – model to be studied Number of deactivated Constraint components in block
idaes.core.util.model_statistics.number_deactivated_equalities(block)[source]

Method to return the number of deactivated equality Constraint components in a model.

Parameters: block – model to be studied Number of deactivated equality Constraint components in block
idaes.core.util.model_statistics.number_deactivated_inequalities(block)[source]

Method to return the number of deactivated inequality Constraint components in a model.

Parameters: block – model to be studied Number of deactivated inequality Constraint components in block
idaes.core.util.model_statistics.number_deactivated_objectives(block)[source]

Method to return the number of deactivated Objective components which appear in a model.

Parameters: block – model to be studied Number of deactivated Objective components which appear in block
idaes.core.util.model_statistics.number_derivative_variables(block)[source]

Method to return the number of DerivativeVar components which appear in a model. Users should note that DerivativeVars are converted to ordinary Vars when a DAE transformation is applied. Thus, this method is useful for detecting any DerivativeVars which were do transformed.

Parameters: block – model to be studied Number of DerivativeVar components which appear in block
idaes.core.util.model_statistics.number_expressions(block)[source]

Method to return the number of Expression components which appear in a model.

Parameters: block – model to be studied Number of Expression components which appear in block
idaes.core.util.model_statistics.number_fixed_unused_variables(block)[source]

Method to return the number of fixed Var components which do not appear within any activated Constraint in a model.

Parameters: block – model to be studied Number of fixed Var components which do not appear within any activated Constraints in block
idaes.core.util.model_statistics.number_fixed_variables(block)[source]

Method to return the number of fixed Var components in a model.

Parameters: block – model to be studied Number of fixed Var components in block
idaes.core.util.model_statistics.number_fixed_variables_in_activated_equalities(block)[source]

Method to return the number of fixed Var components which appear within activated equality Constraints in a model.

Parameters: block – model to be studied Number of fixed Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.number_fixed_variables_only_in_inequalities(block)[source]

Method to return the number of fixed Var components which only appear within activated inequality Constraints in a model.

Parameters: block – model to be studied Number of fixed Var components which only appear within activated inequality Constraints in block
idaes.core.util.model_statistics.number_large_residuals(block, tol=1e-05)[source]

Method to return the number 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 Number of Constraint components with a residual greater than tol which appear in block
idaes.core.util.model_statistics.number_total_blocks(block)[source]

Method to return the number of Block components in a model.

Parameters: block – model to be studied Number of Block components in block (including block itself)
idaes.core.util.model_statistics.number_total_constraints(block)[source]

Method to return the total number of Constraint components in a model.

Parameters: block – model to be studied Number of Constraint components in block
idaes.core.util.model_statistics.number_total_equalities(block)[source]

Method to return the total number of equality Constraint components in a model.

Parameters: block – model to be studied Number of equality Constraint components in block
idaes.core.util.model_statistics.number_total_inequalities(block)[source]

Method to return the total number of inequality Constraint components in a model.

Parameters: block – model to be studied Number of inequality Constraint components in block
idaes.core.util.model_statistics.number_total_objectives(block)[source]

Method to return the number of Objective components which appear in a model

Parameters: block – model to be studied Number of Objective components which appear in block
idaes.core.util.model_statistics.number_unfixed_variables(block)[source]

Method to return the number of unfixed Var components in a model.

Parameters: block – model to be studied Number of unfixed Var components in block
idaes.core.util.model_statistics.number_unfixed_variables_in_activated_equalities(block)[source]

Method to return the number of unfixed Var components which appear within activated equality Constraints in a model.

Parameters: block – model to be studied Number of unfixed Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.number_unused_variables(block)[source]

Method to return the number of Var components which do not appear within any activated Constraint in a model.

Parameters: block – model to be studied Number of Var components which do not appear within any activagted Constraints in block
idaes.core.util.model_statistics.number_variables(block)[source]

Method to return the number of Var components in a model.

Parameters: block – model to be studied Number of Var components in block
idaes.core.util.model_statistics.number_variables_in_activated_constraints(block)[source]

Method to return the number of Var components that appear within active Constraints in a model.

Parameters: block – model to be studied Number of Var components which appear within active Constraints in block
idaes.core.util.model_statistics.number_variables_in_activated_equalities(block)[source]

Method to return the number of Var components which appear within activated equality Constraints in a model.

Parameters: block – model to be studied Number of Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.number_variables_in_activated_inequalities(block)[source]

Method to return the number of Var components which appear within activated inequality Constraints in a model.

Parameters: block – model to be studied Number of Var components which appear within activated inequality Constraints in block
idaes.core.util.model_statistics.number_variables_only_in_inequalities(block)[source]

Method to return the number of Var components which appear only within activated inequality Constraints in a model.

Parameters: block – model to be studied Number of Var components which appear only within activated inequality Constraints in block
idaes.core.util.model_statistics.report_statistics(block, ostream=None)[source]

Method to print a report of the model statistics for a Pyomo Block

Parameters: block – the Block object to report statistics from ostream – output stream for printing (defaults to sys.stdout) Printed output of the model statistics
idaes.core.util.model_statistics.total_blocks_set(block)[source]

Method to return a ComponentSet of all Block components in a model.

Parameters: block – model to be studied A ComponentSet including all Block components in block (including block itself)
idaes.core.util.model_statistics.total_constraints_set(block)[source]

Method to return a ComponentSet of all Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all Constraint components in block
idaes.core.util.model_statistics.total_equalities_generator(block)[source]

Generator which returns all equality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all equality Constraint components block
idaes.core.util.model_statistics.total_equalities_set(block)[source]

Method to return a ComponentSet of all equality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all equality Constraint components in block
idaes.core.util.model_statistics.total_inequalities_generator(block)[source]

Generator which returns all inequality Constraint components in a model.

Parameters: block – model to be studied A generator which returns all inequality Constraint components block
idaes.core.util.model_statistics.total_inequalities_set(block)[source]

Method to return a ComponentSet of all inequality Constraint components in a model.

Parameters: block – model to be studied A ComponentSet including all inequality Constraint components in block
idaes.core.util.model_statistics.total_objectives_generator(block)[source]

Generator which returns all Objective components in a model.

Parameters: block – model to be studied A generator which returns all Objective components block
idaes.core.util.model_statistics.total_objectives_set(block)[source]

Method to return a ComponentSet of all Objective components which appear in a model.

Parameters: block – model to be studied A ComponentSet including all Objective components which appear in block
idaes.core.util.model_statistics.unfixed_variables_generator(block)[source]

Generator which returns all unfixed Var components in a model.

Parameters: block – model to be studied A generator which returns all unfixed Var components block
idaes.core.util.model_statistics.unfixed_variables_in_activated_equalities_set(block)[source]

Method to return a ComponentSet of all unfixed Var components which appear within an activated equality Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all unfixed Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.unfixed_variables_set(block)[source]

Method to return a ComponentSet of all unfixed Var components in a model.

Parameters: block – model to be studied A ComponentSet including all unfixed Var components in block
idaes.core.util.model_statistics.unused_variables_set(block)[source]

Method to return a ComponentSet of all Var components which do not appear within any activated Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all Var components which do not appear within any Constraints in block
idaes.core.util.model_statistics.variables_in_activated_constraints_set(block)[source]

Method to return a ComponentSet of all Var components which appear within a Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all Var components which appear within activated Constraints in block
idaes.core.util.model_statistics.variables_in_activated_equalities_set(block)[source]

Method to return a ComponentSet of all Var components which appear within an equality Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all Var components which appear within activated equality Constraints in block
idaes.core.util.model_statistics.variables_in_activated_inequalities_set(block)[source]

Method to return a ComponentSet of all Var components which appear within an inequality Constraint in a model.

Parameters: block – model to be studied A ComponentSet including all Var components which appear within activated inequality Constraints in block
idaes.core.util.model_statistics.variables_only_in_inequalities(block)[source]

Method to return a ComponentSet of all Var components which appear only within inequality Constraints in a model.

Parameters: block – model to be studied A ComponentSet including all Var components which appear only within inequality Constraints in block
idaes.core.util.model_statistics.variables_set(block)[source]

Method to return a ComponentSet of all Var components in a model.

Parameters: block – model to be studied A ComponentSet including all Var components in block

idaes.core.util.plot module¶

Convenience plotting functions for time-dependent variables.

idaes.core.util.plot.plot_dynamic(time, y, ylabel, xlabel='time (s)', title=None, legend=None)[source]

Plot time dependent variables with pyplot.

Parameters: time (ContinuousSet or list-like) – Time index set y (list-like of list-likes of Var, Expression, Reference, or float) – List of quantities to plot (multiple quantities can be plotted). Each quantity in the list should be indexed only by time. If you want to plot something that is not indexed only by time, you can create a Pyomo Reference with the correct indexing. ylabel (str) – Y-axis label, required xlabel (str) – X-axis label, default = ‘time (s)’ title (str or None) – Plot title, default = None legend (list-like of str or None) – Legend string for each y, default = None None
idaes.core.util.plot.stitch_dynamic(*args)[source]

Combine time-indexed Pyomo component values from different models into one combined time set. This allows you to use multiple models to simulate sections of the time domain, and plot them all together.

Parameters: arguments () (Positional) – Multiple Pyomo components indexed by time, or time sets (list) with the time indexed Pyomo compoent values concatonated for plotting

idaes.core.util.tables module¶

idaes.core.util.tables.create_stream_table_dataframe(streams, true_state=False, time_point=0, orient='columns')[source]

Method to create a stream table in the form of a pandas dataframe. Method takes a dict with name keys and stream values. Use an OrderedDict to list the streams in a specific order, otherwise the dataframe can be sorted later.

Parameters: streams – dict with name keys and stream values. Names will be used as display names for stream table, and streams may be Arcs, Ports or StateBlocks. true_state – indicated whether the stream table should contain the display variables define in the StateBlock (False, default) or the state variables (True). time_point – point in the time domain at which to generate stream table (default = 0) orient – orientation of stream table. Accepted values are ‘columns’ (default) where streams are displayed as columns, or ‘index’ where stream are displayed as rows. A pandas DataFrame containing the stream table data.
idaes.core.util.tables.generate_table(blocks, attributes, heading=None)[source]

Create a Pandas DataFrame that contains a list of user-defined attributes from a set of Blocks.

Parameters: blocks (dict) – A dictionary with name keys and BlockData objects for values. Any name can be associated with a block. Use an OrderedDict to show the blocks in a specific order, otherwise the dataframe can be sorted later. attributes (list or tuple of strings) – Attributes to report from a Block, can be a Var, Param, or Expression. If an attribute doesn’t exist or doesn’t have a valid value, it will be treated as missing data. heading (list or tuple of srings) – A list of strings that will be used as column headings. If None the attribute names will be used. A Pandas dataframe containing a data table (DataFrame)
idaes.core.util.tables.stream_table_dataframe_to_string(stream_table, **kwargs)[source]

Method to print a stream table from a dataframe. Method takes any argument understood by DataFrame.to_string

idaes.core.util.testing module¶

This module contains utility functions for use in testing IDAES models.

class idaes.core.util.testing.PhysicalParameterTestBlock(*args, **kwargs)
Parameters: rule (function) – A rule function or None. Default rule calls build(). concrete (bool) – If True, make this a toplevel model. Default - False. ctype (str) – Pyomo ctype of the block. Default - “Block” default (dict) – Default ProcessBlockData config Keys default_arguments Default arguments to use with Property Package initialize (dict) – ProcessBlockData config for individual elements. Keys are BlockData indexes and values are dictionaries described under the “default” argument above. idx_map (function) – Function to take the index of a BlockData element and return the index in the initialize dict from which to read arguments. This can be provided to overide the default behavior of matching the BlockData index exactly to the index in initialize. (PhysicalParameterTestBlock) New instance
class idaes.core.util.testing.RBlockBase(*args, **kwargs)[source]
initialize(outlvl=0, optarg=None, solver=None)[source]

This is a default initialization routine for ReactionBlocks to ensure that a routine is present. All ReactionBlockData classes should overload this method with one suited to the particular reaction package

Parameters: None – None
class idaes.core.util.testing.ReactionBlock(*args, **kwargs)
Parameters: rule (function) – A rule function or None. Default rule calls build(). concrete (bool) – If True, make this a toplevel model. Default - False. ctype (str) – Pyomo ctype of the block. Default - “Block” default (dict) – Default ProcessBlockData config Keys initialize (dict) – ProcessBlockData config for individual elements. Keys are BlockData indexes and values are dictionaries described under the “default” argument above. idx_map (function) – Function to take the index of a BlockData element and return the index in the initialize dict from which to read arguments. This can be provided to overide the default behavior of matching the BlockData index exactly to the index in initialize. (ReactionBlock) New instance
class idaes.core.util.testing.ReactionBlockData(component)[source]
build()[source]

General build method for PropertyBlockDatas. Inheriting models should call super().build.

Parameters: None – None
get_reaction_rate_basis()[source]

Method which returns an Enum indicating the basis of the reaction rate term.

class idaes.core.util.testing.ReactionParameterTestBlock(*args, **kwargs)
Parameters: rule (function) – A rule function or None. Default rule calls build(). concrete (bool) – If True, make this a toplevel model. Default - False. ctype (str) – Pyomo ctype of the block. Default - “Block” default (dict) – Default ProcessBlockData config Keys property_package Reference to associated PropertyPackageParameter object default_arguments Default arguments to use with Property Package initialize (dict) – ProcessBlockData config for individual elements. Keys are BlockData indexes and values are dictionaries described under the “default” argument above. idx_map (function) – Function to take the index of a BlockData element and return the index in the initialize dict from which to read arguments. This can be provided to overide the default behavior of matching the BlockData index exactly to the index in initialize. (ReactionParameterTestBlock) New instance
class idaes.core.util.testing.SBlockBase(*args, **kwargs)[source]
initialize(outlvl=0, optarg=None, solver=None, hold_state=False, **state_args)[source]

This is a default initialization routine for StateBlocks to ensure that a routine is present. All StateBlockData classes should overload this method with one suited to the particular property package

Parameters: None – None
class idaes.core.util.testing.StateTestBlockData(component)[source]
build()[source]

General build method for StateBlockDatas.

Parameters: None – None
define_state_vars()[source]

Method that returns a dictionary of state variables used in property package. Implement a placeholder method which returns an Exception to force users to overload this.

get_energy_density_terms(p)[source]

Method which returns a valid expression for enthalpy density to use in the energy balances.

get_enthalpy_flow_terms(p)[source]

Method which returns a valid expression for enthalpy flow to use in the energy balances.

get_material_density_terms(p, j)[source]

Method which returns a valid expression for material density to use in the material balances .

get_material_flow_basis()[source]

Method which returns an Enum indicating the basis of the material flow term.

get_material_flow_terms(p, j)[source]

Method which returns a valid expression for material flow to use in the material balances.

class idaes.core.util.testing.TestStateBlock(*args, **kwargs)
Parameters: rule (function) – A rule function or None. Default rule calls build(). concrete (bool) – If True, make this a toplevel model. Default - False. ctype (str) – Pyomo ctype of the block. Default - “Block” default (dict) – Default ProcessBlockData config Keys initialize (dict) – ProcessBlockData config for individual elements. Keys are BlockData indexes and values are dictionaries described under the “default” argument above. idx_map (function) – Function to take the index of a BlockData element and return the index in the initialize dict from which to read arguments. This can be provided to overide the default behavior of matching the BlockData index exactly to the index in initialize. (TestStateBlock) New instance
idaes.core.util.testing.get_default_solver()[source]

Tries to set-up the default solver for testing, and returns None if not available