<jupyter_start><jupyter_text>Colab setup<jupyter_code># After installing, restart the kernel

# install rlberry library
!git clone https://github.com/rlberry-py/rlberry.git
!cd rlberry && git pull && pip install -e .[full]
!pip install ffmpeg-python > /dev/null 2>&1

# packages required to show video
!pip install pyvirtualdisplay > /dev/null 2>&1
!apt-get install -y xvfb python-opengl ffmpeg > /dev/null 2>&1

# restart runtime
import os
os.kill(os.getpid(), 9)
# Create directory for saving videos
!mkdir videos > /dev/null 2>&1

# Initialize virtual display and import show_video function
import rlberry.colab_utils.display_setup
from rlberry.colab_utils.display_setup import show_video<jupyter_output><empty_output><jupyter_text>1. Importing modules and running unit tests---<jupyter_code>import rlberry
import rlberry.agents
import rlberry.stats
import rlberry.envs
import rlberry.exploration_tools
import rlberry.rendering
import rlberry.seeding 
import rlberry.spaces 
import rlberry.utils
import rlberry.wrappers
!python -m pytest rlberry/<jupyter_output><empty_output><jupyter_text>2. Interacting with GridWorld and saving video<jupyter_code>from rlberry.envs import GridWorld

env = GridWorld(nrows=12, ncols=15, walls=((5,5),(6, 6)))

# call enable_rendering if you want to record a video from the interactions
env.enable_rendering()
# get initial state
state = env.reset()
# run a random policy for 100 time steps
for tt in range(100):
  action = env.action_space.sample()  # a good RL algorithm must learn a better way to choose actions!
  next_state, reward, is_terminal, info = env.step(action)
  if is_terminal:
    break
  state = next_state
env.save_video("videos/env_example.mp4", framerate=10)

# show video
show_video()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09367945823927765, 'fraction_numerical': 0.01580135440180587, 'mean_word_length': 5.591078066914498, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '254942', 'license': 'MIT', 'n_tokens_mistral': 619, 'n_tokens_neox': 593, 'n_words': 174, 'path': 'colab_test/test_rlberry_setup.ipynb', 'repo_name': 'rlberry-py/tutorials', 'size': '1772'}