Skip to content

Commit

Permalink
Fix StdoutLogger and update requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
m-wojnar committed Jul 14, 2023
1 parent bc9f812 commit eafcf79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
36 changes: 10 additions & 26 deletions reinforced_lib/logs/stdout_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ def finish(self) -> None:
"""

if len(self._values) > 0:
for name in self._names:
if name in self._values:
print(f'{name}: {self._values[name]}', end='\t')

print()
print('\t'.join(f'{name}: {value}' for name, value in self._values.items()))

def log_scalar(self, source: Source, value: Scalar) -> None:
"""
Expand All @@ -55,7 +51,8 @@ def log_scalar(self, source: Source, value: Scalar) -> None:
Scalar to log.
"""

self._print(source, value)
self._values[self.source_to_name(source)] = value
self._print()

def log_array(self, source: Source, value: Array) -> None:
"""
Expand Down Expand Up @@ -100,27 +97,14 @@ def log_other(self, source: Source, value: Any) -> None:
Value of any type to log.
"""

self._print(source, json.dumps(value))
self._values[self.source_to_name(source)] = json.dumps(value)
self._print()

def _print(self, source: Source, value: Any) -> None:
def _print(self) -> None:
"""
Prints a new row to the standard output if there is any value update.
Parameters
----------
source : Source
Source of the logged value.
value : any
Value of any type to log.
Prints a new row to the standard output if all values has already been filled.
"""

if not (name := self.source_to_name(source)) in self._values:
self._values[name] = value
return

for name in self._names:
if name in self._values:
print(f'{name}: {self._values[name]}', end='\t')

self._values = {}
print()
if len(self._values) == len(self._names):
print('\t'.join(f'{name}: {self._values[name]}' for name in self._names))
self._values = {}
4 changes: 2 additions & 2 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
joblib~=1.2.0
joblib~=1.3.1
# ns3-ai==1.0.2
pygame~=2.3.0
pygame~=2.5.0
seaborn~=0.12.2
sphinx~=5.1.1
sphinx-rtd-theme~=1.0.0
16 changes: 8 additions & 8 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
chex~=0.1.5
cloudpickle~=2.2.0
chex~=0.1.81
cloudpickle~=2.2.1
dm-haiku~=0.0.9
gymnasium~=0.27.1
jax~=0.4.6
jaxlib~=0.4.6
gymnasium~=0.28.1
jax~=0.4.13
jaxlib~=0.4.13
lz4~=4.3.2
matplotlib~=3.7.1
optax~=0.1.4
tensorboardX~=2.6
matplotlib~=3.7.2
optax~=0.1.5
tensorboardX~=2.6.1

0 comments on commit eafcf79

Please sign in to comment.