• Docs >
  • framework.frame_state_objects
Shortcuts

framework.frame_state_objects

class ignite_framework.framework.frame_state_objects.MetaStateObject[source]

Class factory for constructing modular state objects from modular_name string which defines the MRO.

__module__ = 'ignite_framework.framework.frame_state_objects'
static __new__(typ, name, bases, namespace, modular_name=None, initial_value='')[source]

Create and return a new object. See help(type) for accurate signature.

class ignite_framework.framework.frame_state_objects.FrameStateObject(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]

FrameStateObject is a descriptor which is instantiated (referred to instance) as a class attribute of the owner’s class. The attribute name of the VariableState instance is set as attribute name to itself for self-referencing in the owner’s cl ass & instance ___dict__’s. The`values which are unique for each owner instance are/must be stored in the instance __dict__.

Overloading: StateObject`s handle overloads up to 3 suffix words (3 for `__getattr__, 2 for __setattr__, each separated by ‘_’ from the rest. Overloads are used to:

  • _every/once-setter: creates new FrameOnce?EveryEventCounter with the set-value as num_events
  • ‘_every/once_<int>`-setter/(getter): creates FrameOnce/EveryEventCounter and sets state variable
  • ‘every/once_<int>_ref`-getter: as above but returns a StateObjectsReference of it
  • _callbacks-getter: return the StateObject’s callback list of functions
  • _ref: return a StateObjectsReference of the state variable

Once a once/every-overload was called an new state variable with the overloaded name is created, so when calling the next time this call refers to a regular existing (state variable) attribute.

Using state objects in functions: There are 3 possibilities how to refer to a state variable inside a function, basically these options should cover all existing (?) options: 1. assign the state variable value to a function argument when called func(arg1=state.variable_name) 2. assign the state variable reference including full functionality to the argument func( arg_ref=state.variable_name_ref) 3. using global state variable inside the function without assignment n.variable

Feature development: StateObject currently cannot be inherited as the instantiation mechanise (???also lookup???) is based on self.__class__.__dict__[] = …

Parameters:
  • initial_value

    Any type permitted by the current subclass of FrameStateObject. with special values:

    • initial_value=’’: default initial_value is set
    • initial_value=’do_not_set’: initial value will not be set anywhere, e.g. required for StateComponents
  • instance_attr__get__
  • instance_attr__set__
__delete__(instance)[source]

Deleting the state variable resets its value to the initial_value, e.g. delete a model output to free memory.

A state variable cannot be deleted, but for example to free memory it is common to write e.g.

del state.trainer.output
Parameters:instance

Returns:

__dict__ = mappingproxy({'__module__': 'ignite_framework.framework.frame_state_objects', '__doc__': "\n `FrameStateObject` is a descriptor which is instantiated (referred to `instance`) as a class\n attribute of the `owner`'s class. The attribute name of the `VariableState` instance is set as\n attribute `name` to itself for self-referencing in the owner's cl ass & instance ___dict__'s.\n The`values which are unique for each owner instance are/must be stored in the instance __dict__.\n\n Overloading:\n `StateObject`s handle overloads up to 3 suffix words (3 for `__getattr__`, 2 for `__setattr__`,\n each separated by '_' from the rest. Overloads are used to:\n\n * `_every/once`-setter: creates new `FrameOnce?EveryEventCounter` with the set-value as `num_events`\n * '_every/once_<int>`-setter/(getter): creates `FrameOnce/EveryEventCounter` and sets state variable\n * 'every/once_<int>_ref`-getter: as above but returns a `StateObjectsReference` of it\n * `_callbacks`-getter: return the `StateObject`'s callback list of functions\n * `_ref`: return a `StateObjectsReference` of the state variable\n\n Once a `once/every`-overload was called an new state variable with the overloaded name is created, so\n when calling the next time this call refers to a regular existing (state variable) attribute.\n\n Using `state objects` in functions:\n There are 3 possibilities how to refer to a state variable inside a function, basically these options\n should cover all existing (?) options:\n 1. assign the state variable value to a function argument when called `func(arg1=state.variable_name)`\n 2. assign the state variable reference including full functionality to the argument `func(\n arg_ref=state.variable_name_ref)`\n 3. using global state variable inside the function without assignment `n.variable`\n\n Feature development:\n `StateObject` currently cannot be inherited as the instantiation mechanise (???also lookup???) is based on\n `self.__class__.__dict__[] = ...`\n\n Args:\n initial_value: Any type permitted by the current subclass of `FrameStateObject`. with special values:\n\n * `initial_value=''`: default `initial_value` is set\n * `initial_value='do_not_set'`: initial value will not be set anywhere, e.g. required for `StateComponents`\n instance_attr__get__:\n instance_attr__set__:\n ", '_initial_value': None, 'event_mode': True, '__init__': <function FrameStateObject.__init__>, '__set_name__': <function FrameStateObject.__set_name__>, '__get__': <function FrameStateObject.__get__>, '__delete__': <function FrameStateObject.__delete__>, '_default_instance_attr__get__': <function FrameStateObject._default_instance_attr__get__>, '_default_instance_attr__set__': <function FrameStateObject._default_instance_attr__set__>, '_raise_signature_error': <function FrameStateObject._raise_signature_error>, '__dict__': <attribute '__dict__' of 'FrameStateObject' objects>, '__weakref__': <attribute '__weakref__' of 'FrameStateObject' objects>})
__get__(instance, owner)[source]
Parameters:
  • instance – The instance is the instance of the transition class owner. instance is holding the value and callbacks of the descriptor in its instance.__dict__.
  • owner – The owner is the class of instance. StateObject is assigned to as attribute. ‘owner is the CLASS of the transition instance that is calling the descriptor.
Returns:

  • no suffix: returns the value of the StateObject
  • _callbacks: returns the list of callback functions which are called when StateObject is set
  • _ref: returns the StateObjectsReference of the StateObject
  • _every/once_<int>: returns the value (initial value if gotten for the first time) of the
    <int>th

Return type:

Depending on if & which overload suffix is used different returns are given

__init__(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'ignite_framework.framework.frame_state_objects'
__set_name__(owner, name)[source]
__weakref__

list of weak references to the object (if defined)

_default_instance_attr__get__(instance, owner)[source]
_default_instance_attr__set__(instance, value)[source]
_initial_value = None
_raise_signature_error(func, get_or_set)[source]
Parameters:
  • func – function to get or set the instance descriptor value
  • get_or_setget or set indicating the __get__ or __set__ character of func

Returns:

event_mode = True