def __init__(self, config=None, env=None, logger_creator=None): """Initialize an RLLib agent. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ config = config or {} # Agents allow env ids to be passed directly to the constructor. self._env_id = env or config.get("env") Trainable.__init__(self, config, logger_creator)
def __init__(self, config=None, env=None, logger_creator=None): """Initialize an RLLib trainer. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ config = config or {} if tf and config.get("eager"): tf.enable_eager_execution() logger.info("Executing eagerly, with eager_tracing={}".format( "True" if config.get("eager_tracing") else "False")) if tf and not tf.executing_eagerly(): logger.info("Tip: set 'eager': true or the --eager flag to enable " "TensorFlow eager execution") # Vars to synchronize to workers on each train call self.global_vars = {"timestep": 0} # Trainers allow env ids to be passed directly to the constructor. self._env_id = self._register_if_needed(env or config.get("env")) # Create a default logger creator if no logger_creator is specified if logger_creator is None: timestr = datetime.today().strftime("%Y-%m-%d_%H-%M-%S") logdir_prefix = "{}_{}_{}".format(self._name, self._env_id, timestr) def default_logger_creator(config): """Creates a Unified logger with a default logdir prefix containing the agent name and the env id """ if not os.path.exists(DEFAULT_RESULTS_DIR): os.makedirs(DEFAULT_RESULTS_DIR) logdir = tempfile.mkdtemp( prefix=logdir_prefix, dir=DEFAULT_RESULTS_DIR) return UnifiedLogger(config, logdir, loggers=None) logger_creator = default_logger_creator Trainable.__init__(self, config, logger_creator)
def __init__( self, config={}, env=None, registry=get_registry(), logger_creator=None): """Initialize an RLLib agent. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. registry (obj): Object registry for user-defined envs, models, etc. If unspecified, the default registry will be used. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ # Agents allow env ids to be passed directly to the constructor. self._env_id = env or config.get("env") Trainable.__init__(self, config, registry, logger_creator)
def __init__( self, config=None, env=None, registry=None, logger_creator=None): """Initialize an RLLib agent. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. registry (obj): Object registry for user-defined envs, models, etc. If unspecified, the default registry will be used. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ config = config or {} # Agents allow env ids to be passed directly to the constructor. self._env_id = env or config.get("env") Trainable.__init__(self, config, registry, logger_creator)
def __init__(self, config=None, env=None, logger_creator=None): """Initialize an RLLib agent. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ config = config or {} Agent._validate_config(config) # Vars to synchronize to evaluators on each train call self.global_vars = {"timestep": 0} # Agents allow env ids to be passed directly to the constructor. self._env_id = env or config.get("env") # Create a default logger creator if no logger_creator is specified if logger_creator is None: timestr = datetime.today().strftime("%Y-%m-%d_%H-%M-%S") logdir_prefix = "{}_{}_{}".format(self._agent_name, self._env_id, timestr) def default_logger_creator(config): """Creates a Unified logger with a default logdir prefix containing the agent name and the env id """ if not os.path.exists(DEFAULT_RESULTS_DIR): os.makedirs(DEFAULT_RESULTS_DIR) logdir = tempfile.mkdtemp(prefix=logdir_prefix, dir=DEFAULT_RESULTS_DIR) return UnifiedLogger(config, logdir, None) logger_creator = default_logger_creator Trainable.__init__(self, config, logger_creator)
def __init__(self, config=None, env=None, logger_creator=None): """Initialize an RLLib agent. Args: config (dict): Algorithm-specific configuration data. env (str): Name of the environment to use. Note that this can also be specified as the `env` key in config. logger_creator (func): Function that creates a ray.tune.Logger object. If unspecified, a default logger is created. """ config = config or {} # Vars to synchronize to evaluators on each train call self.global_vars = {"timestep": 0} # Agents allow env ids to be passed directly to the constructor. self._env_id = self._register_if_needed(env or config.get("env")) # Create a default logger creator if no logger_creator is specified if logger_creator is None: timestr = datetime.today().strftime("%Y-%m-%d_%H-%M-%S") logdir_prefix = "{}_{}_{}".format(self._agent_name, self._env_id, timestr) def default_logger_creator(config): """Creates a Unified logger with a default logdir prefix containing the agent name and the env id """ if not os.path.exists(DEFAULT_RESULTS_DIR): os.makedirs(DEFAULT_RESULTS_DIR) logdir = tempfile.mkdtemp( prefix=logdir_prefix, dir=DEFAULT_RESULTS_DIR) return UnifiedLogger(config, logdir, None) logger_creator = default_logger_creator Trainable.__init__(self, config, logger_creator)