Description
Today I was helping someone debug a model where they were implicitly replacing components (and I immediately told them to stop doing that). What they were doing was similar to below:
m = ConcreteModel()
m.v = Var()
m.c = Constraint(expr=m.v==1)
m.v = Var()
Obviously, this is going to cause problems, however all that they were seeing was a warning about implicitly replacing a component. However, Constraint c
still refers to the original Var v
which no longer exists. The user was then wondering why their model was not behaving as expected.
My question is, would it be better to return an Exception
in cases like this rather than a printed warning that can be easily missed or ignored. Given that implicitly replacing a component is (almost?) always a bad idea, I don't think the extra overhead of checking for this would be an issue.