Dict-like Object Storage

class pyomo.core.kernel.dict_container.DictContainer(*args, **kwds)[source]

Bases: IHomogeneousContainer, MutableMapping

A partial implementation of the IHomogeneousContainer interface that provides dict-like storage functionality.

Complete implementations need to set the _ctype property at the class level and initialize the remaining ICategorizedObject attributes during object creation. If using __slots__, a slot named “_data” must be included.

Note that this implementation allows nested storage of other ICategorizedObjectContainer implementations that are defined with the same ctype.

__deepcopy__(memo)

Default implementation of __deepcopy__ based on __getstate__

This defines a default implementation of __deepcopy__ that leverages __getstate__() and __setstate__() to duplicate an object. Having a default __deepcopy__ implementation shortcuts significant logic in copy.deepcopy(), thereby speeding up deepcopy operations.

__eq__(other)[source]

Return self==value.

__getstate__()

Generic implementation of __getstate__

This implementation will collect the slots (in order) and then the __dict__ (if necessary) and place everything into a list. This standard format is significantly faster to generate and deepcopy (when compared to a dict), although it can be more fragile (changing the number of slots can cause a pickle to no longer be loadable)

Derived classes should not overload this method to provide special handling for fields (e.g., to resolve weak references). Instead, special field handlers should be declared via the __autoslot_mappers__ class attribute (see AutoSlots)

__hash__ = None
__init__(*args, **kwds)[source]
classmethod __init_subclass__(**kwds)

Automatically define __auto_slots__ on derived subclasses

This accomplishes the same thing as the AutoSlots metaclass without incurring the overhead / runtime penalty of using a metaclass.

__ne__(other)[source]

Return self!=value.

__setstate__(state)

Generic implementation of __setstate__

Restore the state generated by __getstate__()

Derived classes should not overload this method to provide special handling for fields (e.g., to restore weak references). Instead, special field handlers should be declared via the __autoslot_mappers__ class attribute (see AutoSlots)

__str__()

Convert this object to a string by first attempting to generate its fully qualified name. If the object does not have a name (because it does not have a parent, then a string containing the class name is returned.

classmethod __subclasshook__(C)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

activate(shallow=True)

Activate this container.

property active

The active status of this object.

child(key)[source]

Get the child object associated with a given storage key for this container.

Raises:

KeyError – if the argument is not a storage key for any children of this container

children()[source]

A generator over the children of this container.

clear() None.  Remove all items from D.
clone()

Returns a copy of this object with the parent pointer set to None.

A clone is almost equivalent to deepcopy except that any categorized objects encountered that are not descendents of this object will reference the same object on the clone.

components(active=True)

Generates an efficient traversal of all components stored under this container. Components are categorized objects that are either (1) not containers, or (2) are heterogeneous containers.

Parameters:

active (True/None) – Controls whether or not to filter the iteration to include only the active part of the storage tree. The default is True. Setting this keyword to None causes the active status of objects to be ignored.

Returns:

iterator of components in the storage tree

property ctype

The object’s category type.

deactivate(shallow=True)

Deactivate this container.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
getname(fully_qualified=False, name_buffer={}, convert=<class 'str'>, relative_to=None)

Dynamically generates a name for this object.

Parameters:
  • fully_qualified (bool) – Generate a full name by iterating through all anscestor containers. Default is False.

  • convert (function) – A function that converts a storage key into a string representation. Default is the built-in function str.

  • relative_to (object) – When generating a fully qualified name, generate the name relative to this block.

Returns:

If a parent exists, this method returns a string representing the name of the object in the context of its parent; otherwise (if no parent exists), this method returns None.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
property local_name

The object’s local name within the context of its parent. Alias for obj.getname(fully_qualified=False).

property name

The object’s fully qualified name. Alias for obj.getname(fully_qualified=True).

property parent

The object’s parent (possibly None).

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
property storage_key

The object’s storage key within its parent

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values