Skip to content

Inconsistencies in getting component data #1821

Open
@clyman23

Description

@clyman23

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 deprecated
    • pe.value(set_name) will fail with TypeError: 'OrderedSimpleSet' object is not callable
  • Indexed Param param_name indexed by set set_name
    • Simply call param_name[set_value] where set_value is some value in set_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 and param_name[set_value].data() will both fail with AttributeError (understandably, since the return of param_name[set_value] is just the value of the param at that index)
    • Calling param_name.value and param_name.data() both return AttributeError
  • Simple Param param_name
    • Call pe.value(param_name) or param_name.value
    • param_name.data() raises AttributeError
    • Can also call pe.value(param_name[None]) or param_name[None].value
  • Indexed Var var_name indexed by set set_name
    • Need to call pe.value(var_name[set_value]) or var_name[set_value].value
    • Unlike an indexed param, cannot just call var_name[set_value]
    • Using .data() returns AttributeError
  • Simple Var var_name
    • Same things as Indexed Var when using set_value=None
    • Can also just call var_name.value or pe.value(var_name)
    • Using .data() returns AttributeError

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions