Skip to content

Rethinking Pyomo component string representations #525

Open
@whart222

Description

@whart222

Yesterday, I discussed a preliminary extension of VarList to include per-variable labels. This would allow me to label variables as I add them to the list.

This conversation raised some concerns that the users would not be able to associate labels with the location of the variable in a model. I noted that this extension really isn't logically different from Pyomo capabilities that already exist, where we can assign variables on a model with an arbitrary name. For example:

from pyomo.environ import *

m = ConcreteModel()
setattr(m, 'some wierd.name', Var())
setattr(m, ' ', Var())

m.pprint()

Which produces output like:

2 Var Declarations
      : Size=1, Index=None
        Key  : Lower : Value : Upper : Fixed : Stale : Domain
        None :  None :  None :  None : False :  True :  Reals
    some wierd.name : Size=1, Index=None
        Key  : Lower : Value : Upper : Fixed : Stale : Domain
        None :  None :  None :  None : False :  True :  Reals

2 Declarations: some wierd.name  

Note that the setattr() method is being used in a manner that makes it impossible to identify the original variable component. In fact, I didn't even know that I could use a space as an attribute name until I tried this. But more generally, we can add arbitrary symbols in attribute names.

I think this is generally bad, but I'd like to assess everyone's thoughts on this. Should we change setattr() semantics? Should we require that string representations provide exact correspondence to the location of components in models? If not, then what names are reasonable and appropriate? Or are any allowable?

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