Skip to content

Commit

Permalink
update version to 0.5.0 (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinkle23897 authored Mar 13, 2023
1 parent 73600ed commit f0afdea
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
6 changes: 3 additions & 3 deletions .github/workflows/extra_sys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/gputest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint_and_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/profile.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
gym
numba
numpy>=1.20
sphinx<4
sphinx
sphinxcontrib-bibtex
tensorboard
torch
tqdm
protobuf~=3.19.0
protobuf
pettingzoo
7 changes: 4 additions & 3 deletions test/offline/test_discrete_bcq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tianshou/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tianshou import data, env, exploration, policy, trainer, utils

__version__ = "0.4.11"
__version__ = "0.5.0"

__all__ = [
"env",
Expand Down
49 changes: 32 additions & 17 deletions tianshou/env/venvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
Expand All @@ -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]

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f0afdea

Please sign in to comment.