diff --git a/acme/utils/loggers/__init__.py b/acme/utils/loggers/__init__.py index da162bb686..e0f5792bd1 100644 --- a/acme/utils/loggers/__init__.py +++ b/acme/utils/loggers/__init__.py @@ -21,6 +21,7 @@ from acme.utils.loggers.base import LoggingData from acme.utils.loggers.base import NoOpLogger from acme.utils.loggers.base import to_numpy +from acme.utils.loggers.constant import ConstantLogger from acme.utils.loggers.csv import CSVLogger from acme.utils.loggers.filters import NoneFilter from acme.utils.loggers.filters import TimeFilter diff --git a/acme/utils/loggers/constant.py b/acme/utils/loggers/constant.py new file mode 100644 index 0000000000..dafd98c752 --- /dev/null +++ b/acme/utils/loggers/constant.py @@ -0,0 +1,44 @@ +# Lint as: python3 +# Copyright 2018 DeepMind Technologies Limited. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Acme specific utils.""" +from acme.utils.loggers import base + + +class ConstantLogger(base.Logger): + """Logger for values that remain constant throughout the experiment. + + This logger is used to log additional values e.g. level_name or + hyperparameters that do not change in an experiment. Having these values + allows to group or facet plots when analysing data post-experiment. + """ + + def __init__(self, + constant_data: base.LoggingData, + to: base.Logger): + """Initialise the extra info logger. + + Args: + constant_data: Dictionary containing the constant info to be logged. + to: The logger to add these extra info to. + """ + self._constant_data = constant_data + self._to = to + + def write(self, data: base.LoggingData): + # Need to create a new mutable dictionary that will be updated with the data + # we will be writing. base.LoggingData is immutable and hence cannot be + # updated. + self._to.write({**self._constant_data, **data})