From f861124b9a0cd7dcd0964e55c89c845dea329cb7 Mon Sep 17 00:00:00 2001 From: Wapaul1 Date: Wed, 17 May 2017 20:42:17 -0700 Subject: [PATCH] Added python2 support and check for outdated tf (#562) Improve the Evolutionary Strategies example. --- examples/evolution_strategies/policies.py | 2 +- examples/evolution_strategies/tabular_logger.py | 8 +++++--- examples/evolution_strategies/tf_util.py | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/evolution_strategies/policies.py b/examples/evolution_strategies/policies.py index 96f676e58..8f9a2ded2 100644 --- a/examples/evolution_strategies/policies.py +++ b/examples/evolution_strategies/policies.py @@ -76,7 +76,7 @@ class Policy: # === Rollouts/training === - def rollout(self, env, *, render=False, timestep_limit=None, save_obs=False, + def rollout(self, env, render=False, timestep_limit=None, save_obs=False, random_stream=None): """Do a rollout. diff --git a/examples/evolution_strategies/tabular_logger.py b/examples/evolution_strategies/tabular_logger.py index d92adf164..633dbbdf0 100644 --- a/examples/evolution_strategies/tabular_logger.py +++ b/examples/evolution_strategies/tabular_logger.py @@ -79,12 +79,13 @@ def dump_tabular(): _Logger.CURRENT.dump_tabular() -def log(*args, level=INFO): +def log(*args, **kwargs): """Write the sequence of args, with no separators. This is written to the console and output files (if you've configured an output file). """ + level = kwargs['level'] if 'level' in kwargs else INFO _Logger.CURRENT.log(*args, level=level) @@ -177,7 +178,8 @@ class _Logger(object): self.tbwriter.write_values(self.name2val) self.name2val.clear() - def log(self, *args, level=INFO): + def log(self, *args, **kwargs): + level = kwargs['level'] if 'level' in kwargs else INFO if self.level <= level: self._do_log(*args) @@ -198,7 +200,7 @@ class _Logger(object): # Misc def _do_log(self, *args): - self._write_text(*args, '\n') + self._write_text(*args + ('\n',)) for f in self.text_outputs: try: f.flush() diff --git a/examples/evolution_strategies/tf_util.py b/examples/evolution_strategies/tf_util.py index 0ef934bb2..1143d4bcb 100644 --- a/examples/evolution_strategies/tf_util.py +++ b/examples/evolution_strategies/tf_util.py @@ -10,6 +10,11 @@ import tensorflow as tf import functools import os +# Tensorflow must be at least version 1.0.0 for the example to work. +if int(tf.__version__.split(".")[0]) < 1: + raise Exception("Your Tensorflow version is less than 1.0.0. Please update " + "Tensorflow to the latest version.") + # ================================================================ # Import all names into common namespace # ================================================================