MCPcopy
hub / github.com/google-deepmind/acme / get_counts

Method get_counts

acme/utils/counting.py:79–108  ·  view source on GitHub ↗

Return all counts tracked by this counter.

(self)

Source from the content-addressed store, hash-verified

77 return self.get_counts()
78
79 def get_counts(self) -> Dict[str, Number]:
80 """Return all counts tracked by this counter."""
81 now = time.time()
82 # TODO(b/144421838): use futures instead of blocking.
83 if self._parent and (now - self._last_sync_time) > self._time_delta:
84 with self._lock:
85 counts = _prefix_keys(self._counts, self._prefix)
86 # Reset the local counts, as they will be merged into the parent and the
87 # cache.
88 self._counts = {}
89 self._cache = self._parent.increment(**counts)
90 self._last_sync_time = now
91
92 # Potentially prefix the keys in the counts dictionary.
93 counts = _prefix_keys(self._counts, self._prefix)
94
95 # If there's no prefix make a copy of the dictionary so we don't modify the
96 # internal self._counts.
97 if not self._prefix:
98 counts = dict(counts)
99
100 # Combine local counts with any parent counts.
101 for key, value in self._cache.items():
102 counts[key] = counts.get(key, 0) + value
103
104 if self._prefix and self._return_only_prefixed:
105 counts = dict([(key[len(self._prefix) + 1:], value)
106 for key, value in counts.items()
107 if key.startswith(f'{self._prefix}_')])
108 return counts
109
110 def save(self) -> Mapping[str, Mapping[str, Number]]:
111 return {'counts': self._counts, 'cache': self._cache}

Callers 6

test_counter_cachingMethod · 0.95
incrementMethod · 0.95
test_full_learnerMethod · 0.95
runMethod · 0.80

Calls 3

_prefix_keysFunction · 0.85
incrementMethod · 0.80
itemsMethod · 0.80

Tested by 4

test_counter_cachingMethod · 0.76
test_full_learnerMethod · 0.76