这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ v_s
v_s_
obs
obs_next

dtype
18 changes: 11 additions & 7 deletions examples/inverse/irl_gail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import datetime
import os
import pprint
from typing import SupportsFloat
from typing import SupportsFloat, cast

import d4rl
import gymnasium as gym
Expand All @@ -16,6 +16,7 @@
from torch.utils.tensorboard import SummaryWriter

from tianshou.data import Batch, Collector, ReplayBuffer, VectorReplayBuffer
from tianshou.data.types import RolloutBatchProtocol
from tianshou.env import SubprocVectorEnv, VectorEnvNormObs
from tianshou.policy import GAILPolicy
from tianshou.policy.base import BasePolicy
Expand Down Expand Up @@ -185,12 +186,15 @@ def dist(loc_scale: tuple[torch.Tensor, torch.Tensor]) -> Distribution:

for i in range(dataset_size):
expert_buffer.add(
Batch(
obs=dataset["observations"][i],
act=dataset["actions"][i],
rew=dataset["rewards"][i],
done=dataset["terminals"][i],
obs_next=dataset["next_observations"][i],
cast(
RolloutBatchProtocol,
Batch(
obs=dataset["observations"][i],
act=dataset["actions"][i],
rew=dataset["rewards"][i],
done=dataset["terminals"][i],
obs_next=dataset["next_observations"][i],
),
),
)
print("dataset loaded")
Expand Down
6 changes: 4 additions & 2 deletions test/base/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ def step(self, action: np.ndarray | int): # type: ignore[no-untyped-def] # cf.
if self.index == self.size:
self.terminated = True
return self._get_state(), self._get_reward(), self.terminated, False, {}

info_dict = {"key": 1, "env": self}
if action == 0:
self.index = max(self.index - 1, 0)
return (
self._get_state(),
self._get_reward(),
self.terminated,
False,
{"key": 1, "env": self} if self.dict_state else {},
info_dict,
)
if action == 1:
self.index += 1
Expand All @@ -164,7 +166,7 @@ def step(self, action: np.ndarray | int): # type: ignore[no-untyped-def] # cf.
self._get_reward(),
self.terminated,
False,
{"key": 1, "env": self},
info_dict,
)
return None

Expand Down
Loading