Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
15 changes: 9 additions & 6 deletions tutorials/sphinx-tutorials/torchrl_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
# Envs
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

from torchrl.envs.libs.gym import GymEnv, GymWrapper
from torchrl.envs.libs.gym import GymEnv, GymWrapper, set_gym_backend

gym_env = gym.make("Pendulum-v1")
env = GymWrapper(gym_env)
Expand Down Expand Up @@ -434,9 +434,16 @@

from torchrl.envs import ParallelEnv


def make_env():
# You can control whether to use gym or gymnasium for your env
with set_gym_backend("gym"):
return GymEnv("Pendulum-v1", frame_skip=3, from_pixels=True, pixels_only=False)


base_env = ParallelEnv(
4,
lambda: GymEnv("Pendulum-v1", frame_skip=3, from_pixels=True, pixels_only=False),
make_env,
mp_start_method="fork", # This will break on Windows machines! Remove and decorate with if __name__ == "__main__"
)
env = TransformedEnv(
Expand Down Expand Up @@ -656,10 +663,6 @@ def exec_sequence(params, data):
td_module(td)
print("mode:", td["action"])

with set_exploration_type(ExplorationType.MODE):
td_module(td)
print("mean:", td["action"])

###############################################################################
# Using Environments and Modules
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Loading