Description
There are currently a number of ways to retrieve component data from a solved pyomo model (Concrete Model) using the latest released version of pyomo (v5.7.3). This was noticed when upgrading from 5.6.x to 5.7.x with the introduction of the .data()
method for some pyomo components.
There are many ways to retrieve the values of component data that vary based on the component type. The following is my current understanding of how to retrieve information for each component type:
- Set
set_name
- Need to call
set_name.data()
set_name.value
has been deprecatedpe.value(set_name)
will fail withTypeError: 'OrderedSimpleSet' object is not callable
- Need to call
- Indexed Param
param_name
indexed by setset_name
- Simply call
param_name[set_value]
where set_value is some value inset_name
to get the param value at that index - Can also call
pe.value(param_name[set_value])
and get same result param_name[set_value].value
andparam_name[set_value].data()
will both fail withAttributeError
(understandably, since the return ofparam_name[set_value]
is just the value of the param at that index)- Calling
param_name.value
andparam_name.data()
both returnAttributeError
- Simply call
- Simple Param
param_name
- Call
pe.value(param_name)
orparam_name.value
param_name.data()
raisesAttributeError
- Can also call
pe.value(param_name[None])
orparam_name[None].value
- Call
- Indexed Var
var_name
indexed by setset_name
- Need to call
pe.value(var_name[set_value])
orvar_name[set_value].value
- Unlike an indexed param, cannot just call
var_name[set_value]
- Using
.data()
returnsAttributeError
- Need to call
- Simple Var
var_name
- Same things as Indexed Var when using
set_value=None
- Can also just call
var_name.value
orpe.value(var_name)
- Using
.data()
returnsAttributeError
- Same things as Indexed Var when using
All of this can make it very confusing for developers to extract solved model component values; the developer is required to use different methods to extract values if the component is a set, a param, or a var.
I would propose expanding the functionality of pe.value()
method to be able to extract values of all component types. This would streamline the process and make deployment of large pyomo projects much simpler.