Skip to content

Commit

Permalink
Add constant info logger.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 327014404
Change-Id: I84884cc9019064d2bb2be8556d4c794d78e14f34
  • Loading branch information
Acme Contributor authored and Copybara-Service committed Aug 17, 2020
1 parent 1b1d160 commit 7eeeb24
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions acme/utils/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions acme/utils/loggers/constant.py
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 7eeeb24

Please sign in to comment.