cog-imperial / suspect

Special Structure Detection for Pyomo
https://cog-imperial.github.io/suspect/
Apache License 2.0
26 stars 4 forks source link

find component is more robust with components than strings #12

Closed michaelbynum closed 3 years ago

michaelbynum commented 3 years ago

consider

import pyomo.environ as pe
m = pe.ConcreteModel()
m.x = pe.Var(['1', '2'])

The following does not work:

m2 = m.clone()
m2.find_component(m.x['1'].getname(fully_qualified=True)) is m2.x['1']  # False

However, the following does

m2 = m.clone()
m2.find_component(m.x['1']) is m2.x['1']  # True

The reason the former does not work is that m.x['1'].getname(fully_qualified=True) returns "m.x[1]" instead of "m.x['1']".

fracek commented 3 years ago

Thank you, I didn't know this.