mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-07-30 20:18:15 +00:00
Revert all changes for python 2
+ Add makefile and pytype
This commit is contained in:
parent
8152b34aaa
commit
37f9f13684
10 changed files with 31 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -12,6 +12,7 @@ __pycache__/
|
|||
_build/
|
||||
*.npz
|
||||
*.pth
|
||||
.pytype/
|
||||
|
||||
# Setuptools distribution and build folders.
|
||||
/dist/
|
||||
|
|
|
|||
13
Makefile
Normal file
13
Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
SHELL=/bin/bash
|
||||
|
||||
pytest:
|
||||
./scripts/run_tests.sh
|
||||
|
||||
pytype:
|
||||
pytype
|
||||
|
||||
doc:
|
||||
cd docs && make html
|
||||
|
||||
spelling:
|
||||
cd docs && make spelling
|
||||
|
|
@ -15,3 +15,6 @@ filterwarnings =
|
|||
# Gym warnings
|
||||
ignore:Parameters to load are deprecated.:DeprecationWarning
|
||||
ignore:the imp module is deprecated in favour of importlib:PendingDeprecationWarning
|
||||
|
||||
[pytype]
|
||||
inputs = torchy_baselines
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -18,6 +18,7 @@ setup(name='torchy_baselines',
|
|||
'pytest-cov',
|
||||
'pytest-env',
|
||||
'pytest-xdist',
|
||||
'pytype',
|
||||
],
|
||||
'docs': [
|
||||
'sphinx',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections import deque
|
||||
import os
|
||||
import io
|
||||
import zipfile
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import deque
|
||||
|
||||
import gym
|
||||
import torch as th
|
||||
|
|
@ -18,7 +18,7 @@ from torchy_baselines.common.evaluation import evaluate_policy
|
|||
from torchy_baselines.common.save_util import data_to_json, json_to_data
|
||||
|
||||
|
||||
class BaseRLModel(object):
|
||||
class BaseRLModel(ABC):
|
||||
"""
|
||||
The base RL model
|
||||
|
||||
|
|
@ -43,8 +43,6 @@ class BaseRLModel(object):
|
|||
:param sde_sample_freq: (int) Sample a new noise matrix every n steps when using SDE
|
||||
Default: -1 (only sample at the beginning of the rollout)
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, policy, env, policy_base, policy_kwargs=None,
|
||||
verbose=0, device='auto', support_multi_env=False,
|
||||
create_eval_env=False, monitor_wrapper=True, seed=None,
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ def getkvs():
|
|||
return Logger.CURRENT.name2val
|
||||
|
||||
|
||||
def log(*args, **kwargs):
|
||||
def log(*args, level=INFO):
|
||||
"""
|
||||
Write the sequence of args, with no separators,
|
||||
to the console and output files (if you've configured an output file).
|
||||
|
|
@ -283,7 +283,6 @@ def log(*args, **kwargs):
|
|||
:param args: (list) log the arguments
|
||||
:param level: (int) the logging level (can be DEBUG=10, INFO=20, WARN=30, ERROR=40, DISABLED=50)
|
||||
"""
|
||||
level = kwargs.get('level', INFO)
|
||||
Logger.CURRENT.log(*args, level=level)
|
||||
|
||||
|
||||
|
|
@ -424,7 +423,7 @@ class Logger(object):
|
|||
self.name2val.clear()
|
||||
self.name2cnt.clear()
|
||||
|
||||
def log(self, *args, **kwargs):
|
||||
def log(self, *args, level=INFO):
|
||||
"""
|
||||
Write the sequence of args, with no separators,
|
||||
to the console and output files (if you've configured an output file).
|
||||
|
|
@ -435,7 +434,6 @@ class Logger(object):
|
|||
:param args: (list) log the arguments
|
||||
:param level: (int) the logging level (can be DEBUG=10, INFO=20, WARN=30, ERROR=40, DISABLED=50)
|
||||
"""
|
||||
level = kwargs.get('level', INFO)
|
||||
if self.level <= level:
|
||||
self._do_log(args)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
import inspect
|
||||
import pickle
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import cloudpickle
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class NotSteppingError(Exception):
|
|||
Exception.__init__(self, msg)
|
||||
|
||||
|
||||
class VecEnv(object):
|
||||
class VecEnv(ABC):
|
||||
"""
|
||||
An abstract asynchronous, vectorized environment.
|
||||
|
||||
|
|
@ -39,8 +39,6 @@ class VecEnv(object):
|
|||
'render.modes': ['human', 'rgb_array']
|
||||
}
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, num_envs, observation_space, action_space):
|
||||
self.num_envs = num_envs
|
||||
self.observation_space = observation_space
|
||||
|
|
@ -112,7 +110,7 @@ class VecEnv(object):
|
|||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def env_method(self, method_name, *method_args, **method_kwargs):
|
||||
def env_method(self, method_name, *method_args, indices=None, **method_kwargs):
|
||||
"""
|
||||
Call instance methods of vectorized environments.
|
||||
|
||||
|
|
@ -222,8 +220,8 @@ class VecEnvWrapper(VecEnv):
|
|||
def set_attr(self, attr_name, value, indices=None):
|
||||
return self.venv.set_attr(attr_name, value, indices)
|
||||
|
||||
def env_method(self, method_name, *method_args, **method_kwargs):
|
||||
return self.venv.env_method(method_name, *method_args, **method_kwargs)
|
||||
def env_method(self, method_name, *method_args, indices=None, **method_kwargs):
|
||||
return self.venv.env_method(method_name, *method_args, indices=indices, **method_kwargs)
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""Find attribute from wrapped venv(s) if this wrapper does not have it.
|
||||
|
|
|
|||
|
|
@ -99,11 +99,8 @@ class DummyVecEnv(VecEnv):
|
|||
for env_i in target_envs:
|
||||
setattr(env_i, attr_name, value)
|
||||
|
||||
def env_method(self, method_name, *method_args, **method_kwargs):
|
||||
def env_method(self, method_name, *method_args, indices=None, **method_kwargs):
|
||||
"""Call instance methods of vectorized environments."""
|
||||
indices = method_kwargs.get('indices')
|
||||
if 'indices' in method_kwargs:
|
||||
del method_kwargs['indices']
|
||||
target_envs = self._get_target_envs(indices)
|
||||
return [getattr(env_i, method_name)(*method_args, **method_kwargs) for env_i in target_envs]
|
||||
|
||||
|
|
|
|||
|
|
@ -153,8 +153,7 @@ class SubprocVecEnv(VecEnv):
|
|||
for pipe in self.remotes:
|
||||
# gather images from subprocesses
|
||||
# `mode` will be taken into account later
|
||||
kwargs.update({'mode': 'rgb_array'})
|
||||
pipe.send(('render', (args, kwargs)))
|
||||
pipe.send(('render', (args, {'mode': 'rgb_array', **kwargs})))
|
||||
imgs = [pipe.recv() for pipe in self.remotes]
|
||||
# Create a big image by tiling images from subprocesses
|
||||
bigimg = tile_images(imgs)
|
||||
|
|
@ -199,11 +198,8 @@ class SubprocVecEnv(VecEnv):
|
|||
assert len(seed) == len(indices)
|
||||
return [self.env_method('seed', seed[i], indices=i) for i in indices]
|
||||
|
||||
def env_method(self, method_name, *method_args, **method_kwargs):
|
||||
def env_method(self, method_name, *method_args, indices=None, **method_kwargs):
|
||||
"""Call instance methods of vectorized environments."""
|
||||
indices = method_kwargs.get('indices')
|
||||
if 'indices' in method_kwargs:
|
||||
del method_kwargs['indices']
|
||||
target_remotes = self._get_target_remotes(indices)
|
||||
for remote in target_remotes:
|
||||
remote.send(('env_method', (method_name, method_args, method_kwargs)))
|
||||
|
|
|
|||
0
torchy_baselines/py.typed
Normal file
0
torchy_baselines/py.typed
Normal file
Loading…
Reference in a new issue