Skip to content

Calling del_component on a ComponentData deletes the parent component #3435

Open
@emma58

Description

@emma58

Summary

Calling del_component on a ComponentData (at least for Constraint and Var) deletes the entire parent component.

Steps to reproduce the issue

This script:

from pyomo.environ import *

m = ConcreteModel()
m.x = Var(range(10))
@m.Constraint(range(10))
def c(m, i):
    return m.x[i] <= i

m.pprint()

print("Delete c[5]?")
m.del_component(m.c[5])

m.pprint()

print("Delete x[3]?")
m.del_component(m.x[3])

m.pprint()

Produces this output:

1 Var Declarations
    x : Size=10, Index={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
        Key : Lower : Value : Upper : Fixed : Stale : Domain
          0 :  None :  None :  None : False :  True :  Reals
          1 :  None :  None :  None : False :  True :  Reals
          2 :  None :  None :  None : False :  True :  Reals
          3 :  None :  None :  None : False :  True :  Reals
          4 :  None :  None :  None : False :  True :  Reals
          5 :  None :  None :  None : False :  True :  Reals
          6 :  None :  None :  None : False :  True :  Reals
          7 :  None :  None :  None : False :  True :  Reals
          8 :  None :  None :  None : False :  True :  Reals
          9 :  None :  None :  None : False :  True :  Reals

1 Constraint Declarations
    c : Size=10, Index={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, Active=True
        Key : Lower : Body : Upper : Active
          0 :  -Inf : x[0] :   0.0 :   True
          1 :  -Inf : x[1] :   1.0 :   True
          2 :  -Inf : x[2] :   2.0 :   True
          3 :  -Inf : x[3] :   3.0 :   True
          4 :  -Inf : x[4] :   4.0 :   True
          5 :  -Inf : x[5] :   5.0 :   True
          6 :  -Inf : x[6] :   6.0 :   True
          7 :  -Inf : x[7] :   7.0 :   True
          8 :  -Inf : x[8] :   8.0 :   True
          9 :  -Inf : x[9] :   9.0 :   True

2 Declarations: x c
Delete c[5]?
1 Var Declarations
    x : Size=10, Index={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
        Key : Lower : Value : Upper : Fixed : Stale : Domain
          0 :  None :  None :  None : False :  True :  Reals
          1 :  None :  None :  None : False :  True :  Reals
          2 :  None :  None :  None : False :  True :  Reals
          3 :  None :  None :  None : False :  True :  Reals
          4 :  None :  None :  None : False :  True :  Reals
          5 :  None :  None :  None : False :  True :  Reals
          6 :  None :  None :  None : False :  True :  Reals
          7 :  None :  None :  None : False :  True :  Reals
          8 :  None :  None :  None : False :  True :  Reals
          9 :  None :  None :  None : False :  True :  Reals

1 Declarations: x
Delete x[3]?
0 Declarations: 

Error Message

No error--we're turfing the entire IndexedComponent silently.

Information on your system

Pyomo version: main
Python version: 3.11
Operating system: linux
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable): NA

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