From f0afdeaf6af671c71f0daa87ee85b680da68f38f Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Sun, 12 Mar 2023 22:07:16 -0700 Subject: [PATCH] update version to 0.5.0 (#826) --- .github/ISSUE_TEMPLATE.md | 2 +- .github/workflows/extra_sys.yml | 6 ++-- .github/workflows/gputest.yml | 6 ++-- .github/workflows/lint_and_docs.yml | 6 ++-- .github/workflows/profile.yml | 27 ---------------- .github/workflows/pytest.yml | 6 ++-- docs/requirements.txt | 4 +-- test/offline/test_discrete_bcq.py | 7 +++-- tianshou/__init__.py | 2 +- tianshou/env/venvs.py | 49 +++++++++++++++++++---------- 10 files changed, 52 insertions(+), 63 deletions(-) delete mode 100644 .github/workflows/profile.yml diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index c5c07bf3f..16f76f989 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -7,6 +7,6 @@ - [ ] I have searched through the [issue tracker](https://github.com/thu-ml/tianshou/issues) for duplicates - [ ] I have mentioned version numbers, operating system and environment, where applicable: ```python - import tianshou, gym, torch, numpy, sys + import tianshou, gymnasium as gym, torch, numpy, sys print(tianshou.__version__, gym.__version__, torch.__version__, numpy.__version__, sys.version, sys.platform) ``` diff --git a/.github/workflows/extra_sys.yml b/.github/workflows/extra_sys.yml index 50b8523e2..db945cbb3 100644 --- a/.github/workflows/extra_sys.yml +++ b/.github/workflows/extra_sys.yml @@ -12,12 +12,12 @@ jobs: python-version: [3.7, 3.8] steps: - name: Cancel previous run - uses: styfle/cancel-workflow-action@0.9.1 + uses: styfle/cancel-workflow-action@0.11.0 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Upgrade pip diff --git a/.github/workflows/gputest.yml b/.github/workflows/gputest.yml index 5461977bb..18ff68751 100644 --- a/.github/workflows/gputest.yml +++ b/.github/workflows/gputest.yml @@ -8,12 +8,12 @@ jobs: if: "!contains(github.event.head_commit.message, 'ci skip')" steps: - name: Cancel previous run - uses: styfle/cancel-workflow-action@0.9.1 + uses: styfle/cancel-workflow-action@0.11.0 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - name: Upgrade pip diff --git a/.github/workflows/lint_and_docs.yml b/.github/workflows/lint_and_docs.yml index f742ba347..336ae6880 100644 --- a/.github/workflows/lint_and_docs.yml +++ b/.github/workflows/lint_and_docs.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Cancel previous run - uses: styfle/cancel-workflow-action@0.9.1 + uses: styfle/cancel-workflow-action@0.11.0 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - name: Upgrade pip diff --git a/.github/workflows/profile.yml b/.github/workflows/profile.yml deleted file mode 100644 index f23538729..000000000 --- a/.github/workflows/profile.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Data Profile - -on: [push, pull_request] - -jobs: - profile: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'ci skip')" - steps: - - name: Cancel previous run - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ github.token }} - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Upgrade pip - run: | - python -m pip install --upgrade pip setuptools wheel - - name: Install dependencies - run: | - python -m pip install ".[dev]" --upgrade - - name: Test with pytest - run: | - pytest test/throughput --durations=0 -v --color=yes diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index ec638db00..c08d8ec28 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -11,12 +11,12 @@ jobs: python-version: [3.7, 3.8, 3.9] steps: - name: Cancel previous run - uses: styfle/cancel-workflow-action@0.9.1 + uses: styfle/cancel-workflow-action@0.11.0 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Upgrade pip diff --git a/docs/requirements.txt b/docs/requirements.txt index f0e834156..9d5ec37b0 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,10 +1,10 @@ gym numba numpy>=1.20 -sphinx<4 +sphinx sphinxcontrib-bibtex tensorboard torch tqdm -protobuf~=3.19.0 +protobuf pettingzoo diff --git a/test/offline/test_discrete_bcq.py b/test/offline/test_discrete_bcq.py index 1c9fcd591..98286c7bf 100644 --- a/test/offline/test_discrete_bcq.py +++ b/test/offline/test_discrete_bcq.py @@ -40,7 +40,7 @@ def get_args(): parser.add_argument("--hidden-sizes", type=int, nargs="*", default=[64, 64]) parser.add_argument("--test-num", type=int, default=100) parser.add_argument("--logdir", type=str, default="log") - parser.add_argument("--render", type=float, default=0.) + parser.add_argument("--render", type=float, default=0.0) parser.add_argument("--load-buffer-name", type=str, default=expert_file_name()) parser.add_argument( "--device", @@ -59,7 +59,7 @@ def test_discrete_bcq(args=get_args()): args.state_shape = env.observation_space.shape or env.observation_space.n args.action_shape = env.action_space.shape or env.action_space.n if args.reward_threshold is None: - default_reward_threshold = {"CartPole-v0": 190} + default_reward_threshold = {"CartPole-v0": 185} args.reward_threshold = default_reward_threshold.get( args.task, env.spec.reward_threshold ) @@ -123,7 +123,8 @@ def save_checkpoint_fn(epoch, env_step, gradient_step): { "model": policy.state_dict(), "optim": optim.state_dict(), - }, ckpt_path + }, + ckpt_path, ) return ckpt_path diff --git a/tianshou/__init__.py b/tianshou/__init__.py index 71f5e0a70..e039d6e42 100644 --- a/tianshou/__init__.py +++ b/tianshou/__init__.py @@ -1,6 +1,6 @@ from tianshou import data, env, exploration, policy, trainer, utils -__version__ = "0.4.11" +__version__ = "0.5.0" __all__ = [ "env", diff --git a/tianshou/env/venvs.py b/tianshou/env/venvs.py index a0fb0b538..cc39ba31b 100644 --- a/tianshou/env/venvs.py +++ b/tianshou/env/venvs.py @@ -5,7 +5,6 @@ import numpy as np import packaging -from tianshou.env.pettingzoo_env import PettingZooEnv from tianshou.env.utils import ENV_TYPE, gym_new_venv_step_type from tianshou.env.worker import ( DummyEnvWorker, @@ -14,8 +13,14 @@ SubprocEnvWorker, ) +try: + from tianshou.env.pettingzoo_env import PettingZooEnv +except ImportError: + PettingZooEnv = None # type: ignore + try: import gym as old_gym + has_old_gym = True except ImportError: has_old_gym = False @@ -152,11 +157,13 @@ def __init__( self.env_num = len(env_fns) self.wait_num = wait_num or len(env_fns) - assert 1 <= self.wait_num <= len(env_fns), \ - f"wait_num should be in [1, {len(env_fns)}], but got {wait_num}" + assert ( + 1 <= self.wait_num <= len(env_fns) + ), f"wait_num should be in [1, {len(env_fns)}], but got {wait_num}" self.timeout = timeout - assert self.timeout is None or self.timeout > 0, \ - f"timeout is {timeout}, it should be positive if provided!" + assert ( + self.timeout is None or self.timeout > 0 + ), f"timeout is {timeout}, it should be positive if provided!" self.is_async = self.wait_num != len(env_fns) or timeout is not None self.waiting_conn: List[EnvWorker] = [] # environments in self.ready_id is actually ready @@ -169,8 +176,9 @@ def __init__( self.is_closed = False def _assert_is_not_closed(self) -> None: - assert not self.is_closed, \ - f"Methods of {self.__class__.__name__} cannot be called after close." + assert ( + not self.is_closed + ), f"Methods of {self.__class__.__name__} cannot be called after close." def __len__(self) -> int: """Return len(self), which is the number of environments.""" @@ -245,10 +253,12 @@ def _wrap_id( def _assert_id(self, id: Union[List[int], np.ndarray]) -> None: for i in id: - assert i not in self.waiting_id, \ - f"Cannot interact with environment {i} which is stepping now." - assert i in self.ready_id, \ - f"Can only interact with ready environments {self.ready_id}." + assert ( + i not in self.waiting_id + ), f"Cannot interact with environment {i} which is stepping now." + assert ( + i in self.ready_id + ), f"Can only interact with ready environments {self.ready_id}." def reset( self, @@ -271,9 +281,10 @@ def reset( self.workers[i].send(None, **kwargs) ret_list = [self.workers[i].recv() for i in id] - assert isinstance(ret_list[0], (tuple, list)) and len( - ret_list[0] - ) == 2 and isinstance(ret_list[0][1], dict) + assert ( + isinstance(ret_list[0], (tuple, list)) and len(ret_list[0]) == 2 + and isinstance(ret_list[0][1], dict) + ) obs_list = [r[0] for r in ret_list] @@ -367,9 +378,13 @@ def step( obs_stack = np.stack(obs_list) except ValueError: # different len(obs) obs_stack = np.array(obs_list, dtype=object) - return obs_stack, np.stack(rew_list), np.stack(term_list), np.stack( - trunc_list - ), np.stack(info_list) + return ( + obs_stack, + np.stack(rew_list), + np.stack(term_list), + np.stack(trunc_list), + np.stack(info_list), + ) def seed( self,