def log(self): """Get a nested dictionary of the current values for logged quantities. The nested dictionary consist of one level for each element of a namespace. The logged value and flag for the namespace ``('example', 'namespace')`` would be accessible in the returned dictionary via ``logger.log()['example']['namespace']``. Returns: dict: A nested dictionary of the current logged quantities. The end values are (value, flag) pairs which hold the value along with its associated `hoomd.logging.TypeFlags` flag represented as a string (to get the `hoomd.logging.TypeFlags` enum value use ``TypeFlags[flag]``. """ return dict_map(self._dict, lambda x: x())
def _get_state_dict(cls, data, namespace, **kwargs): """Get the state dictionary from the accepted outputs of from_state. Deals with GSD files, namespace dicts (the output of hoomd loggers), and state dictionaries. """ # Filenames if isinstance(data, str): if data.endswith('gsd'): state, kwargs = cls._state_from_gsd(data, namespace, **kwargs) # Dictionaries and like objects elif isinstance(data, NamespaceDict): state = deepcopy(data[namespace]) elif isinstance(data, Mapping): try: # try to grab the namespace state = deepcopy(NamespaceDict(data)[namespace]) except KeyError: # if namespace can't be found assume that dictionary is the # state dictionary (This assumes that values are of the form # (value, flag) try: state = dict_map(data, lambda x: x[0]) except TypeError: # if the map fails, we then assume that the dictionary is # one without the flag information on the data. This could # be the case if a logger backend stores the data and that # returned data is fed in. state = deepcopy(data) # Data is of an unusable type else: raise ValueError("Object {} cannot be used to get state." "".format(data)) return (state, kwargs)
def _get_state(self): """Hook to allow subclasses to overwrite state property.""" state = self._typeparam_states() state['__params__'] = dict(self._param_dict) return dict_filter(dict_map(state, _convert_values_to_log_form), lambda x: x is not RequiredArg)