Ticket #4560 (new defect)

Opened 4 years ago

Last modified 4 years ago

Indexed Sets ignore "initialize" keywords

Reported by: gahacke Owned by: unassigned
Priority: blocker Milestone: Pyomo 4.x
Component: Pyomo Version:
Keywords: IndexedSet, default, initialize Cc:

Description

This is a problem for AbstractModels? where many of the indices are empty sets. The current behavior forces users to define every index in the data file, where sparse data should really be sufficient.

model file:

model.q = Set(initialize=[1,2,3])
model.S = Set(model.q, initialize=[])

data file:

# Exclude this first index because it is empty
# and the initialize=[] keyword should take care
# of it
# set S[1] := ;
set S[2] := a b;
set S[3] := a;

script file:

model.S[1] #-> KeyError

Attachments

set_bugs.dat Download (66 bytes) - added by gahacke 4 years ago.
set_bugs.py Download (179 bytes) - added by gahacke 4 years ago.

Change History

Changed 4 years ago by gahacke

Changed 4 years ago by gahacke

comment:1 follow-up: ↓ 2 Changed 4 years ago by jdsiiro

Are you sure that the behavior you want is correct? For example, I don't think that is the behavior we have/want in Params: if you provide external data, then the initialize keyword is (intentionally) ignored in that case as well. The correct way to provide fallback data for Params is with the default keyword. I think what you really want is to support a "default=" argument for indexed sets...?

comment:2 in reply to: ↑ 1 Changed 4 years ago by gahacke

Replying to jdsiiro:

Are you sure that the behavior you want is correct? For example, I don't think that is the behavior we have/want in Params: if you provide external data, then the initialize keyword is (intentionally) ignored in that case as well. The correct way to provide fallback data for Params is with the default keyword. I think what you really want is to support a "default=" argument for indexed sets...?

Perhaps "default" is more appropriate. Whatever you want to label it, if I have defined an object as being indexed by a set (and provided initialize and/or default data), then I would expect every index of the indexing set to be a valid key of the indexed object. This is the case for Params. I would have expected the behavior for Sets.

comment:3 Changed 4 years ago by jdsiiro

[10347] partially resolves this ticket, in that the provided example no longer raises a KeyError. However, that fix only works for implicitly providing empty subsets: if the original model had been:

model.q = Set(initialize=[1,2,3])
model.S = Set(model.q, initialize=['a','b','c','d'])

data file:

# Exclude this first index because we want it to fall back on the default 
# set S[1] := ;
set S[2] := a b;
set S[3] := a;

Then S[1] would still be empty and not get the value of {a, b, c, d}. Per the  discussion on the pyomo-developers list, I think the correct resolution here will be to add a default= keyword to the Set API.

comment:4 Changed 4 years ago by wehart

  • Milestone set to Pyomo 4.x
Note: See TracTickets for help on using tickets.