Collections of model/component attributes (symenergy.core.collections)¶
All constraints, parameters, and variables can be conventiently accessed through the corresponding collections. These are
All constraints, parameters, and variables of the model and component objects can be conveniently accessed through their respective collections. The model class aggregates all
-
class
symenergy.core.collections.
AttributeCollection
(name)[source]¶ Iterable collection of parameters/variables/constraints of components/model
-
append
(el)[source]¶ Append an element (parameter, constraint, or variable) to the collection. This checks for consistency, i.e. an error is thrown if anything but a
symenergy.core.Parameter
is appended to asymenergy.core.ParameterCollection
.Parameters: el (appropriate SymEnergy class) – Parameter, Constraint, or Variable
-
tolist
(return_attribute='', squeeze=True, unique=True, **kwargs)[source]¶ Return list of elements filtered by single element attribute.
kwargs must be dict of type {element attribute: attribute value}.
Example
>>> `m.constraints.tolist(is_equality_constraint=True)` returns all equality constraints of model `m` >>> `m.constraints.tolist('col', is_equality_constraint=True)` returns the column names of all equality constraints of model `m`
Parameters:
-
to_dict
(dict_struct={('name', ): ''}, squeeze=True, **kwargs)[source]¶ Convert collection to arbitrarily nested dictionary.
Returns a dictionary defined by the dict_struct parameter. This parameter is an arbitrarly nested dictionary with keys corresponding to (tuples of) element attribute names: {(‘attr1’, ‘attr2’): {‘attr3’: {(‘attr4’, ‘attr5’): ‘attr6’}}} returns the values of ‘attr6’ for all combinations of the other attributes.
Example
>>> `dict_struct={('base_name', 'comp_name'): {'slot': ''}}`
If dict_struct is a string (name of element attribute), to_dict acts as a wrapper of
symenergy.core.collections.AttributeCollection.tolist()
Parameters: dict_struct (dict or str) – nested dictionary of strings specifying element attributes
-
-
class
symenergy.core.collections.
ParameterCollection
(name)[source]¶ Collection of type
symenergy.core.parameter.Parameter