Skip to content

Can't clone model with Set initialized from Python 3 dict_keys #1510

Open
@emma58

Description

@emma58

In Python 3 (not 2 because in 2 keys() returns a list),

m = ConcreteModel()
some_dict = {1:2, 3:5, 5:8}
m.some_set = Set(initialize=some_dict.keys())
new = m.clone()

produces

ERROR: Unable to clone Pyomo component attribute. Component 'some_set'
    contains an uncopyable field '_init_values' (<class
    'pyomo.core.base.set.TuplizeValuesInitializer'>)

The original exception is swallowed, but it's a TypeError: can't pickle dict_keys objects. It seems like at some point it is Set's job to convert some_dict.keys() to a list or something friendlier?

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