piSTAR Lab Documentation

_images/ai-play_6.png

pistarlogo piSTAR Lab is an open source platform built to make AI experimentation accessible and fun.

Note

piSTAR Lab is in early development.

Who is piSTAR Lab for?

  • AI Enthusiasts and Students:
    • Have fun experimenting with state-of-the-art AI Agents. No coding required.

    • Gain a better intuition about reinforcement learning by creating your own agents.

  • Reinforcement Learning Researchers and Engineers:
    • Showcase your algorithms by creating extensions for other users to enjoy. No restrictive framework/library requirements.

    • Import your externally trained agents.

    • Use piSTAR Lab in your development workflow.

    • Try your algorithm on newly available environments with just a few clicks

  • Game and Environment Developers:
    • Create Extensions” which make your game playable by piSTAR Agents.

    • Train your own Agents for your game’s AI

Features

  • Intuitive UI

  • Extension System for adding new agents, environments or tasks types

  • No framework requirements. Use any framework available in python (other languages coming)

  • Real-time streaming of observations during training

  • Single and Multi player environment support

  • Experiment tracking

  • Python API, anything you can do in the UI, you can do in Python as well

  • Uses Ray Project (https://ray.io/) under the hood for distributed processing

Coming soon (unordered)

  • Simpler installation and better support for Windows and Mac

  • Easily share your trained agents with friends or publicly

  • Docker based agents and environments

  • Remote agents and environments

  • Data environments for agents with support for learning from offline data

  • API for Data Interfaces

  • Support for browser based games and environments so human can interact directly with their agents.

  • Support for other programming languages

  • Human control mode for testing environments via the UI

  • Better workspace integration with VSCode and Jupyter

  • Interactive Debugger

  • Testing and quality verification of extensions

Contributing

piSTAR Lab is Open Source and welcomes your contributions.

Overview

piSTAR Lab is modular Agent Development Environment that can run on your PC or in the cloud.

  • Manage your own library of Agents and Environments.

  • Run experiments with a click of a button.

  • Watch your agent learn in realtime.

Screenshots

_images/pistarlab_demo1.gif _images/recent_agents.png _images/envs.png _images/agent_training1.png _images/assign_multi_agent_envs.png _images/multi_agent_viewer.png _images/extension_man.png

Installation

NOTE: Tested on Ubuntu and Windows 10. If you run into issues, we recommend using Docker.

with Pip

  1. Install Anaconda or Miniconda

    Visit https://www.anaconda.com/products/individual for instructions

  2. Install additional dependencies (Ubuntu only)
    • XVFB to render without display (No MS Windows Support)

    • ffmpeg for video processing

    sudo apt-get install -y xvfb ffmpeg
    
  3. Create Conda Virtual Environment

    conda create -n pistarlab python=3.7
    conda activate pistarlab
    conda install pip
    
  4. Option 1 (Package only)

    pip install https://github.com/pistarlab/pistarlab/archive/refs/heads/main.zip#egg=pistarlab[all]
    
  5. Option 2 (Package + Source)

    git clone  --single-branch --depth=1 http://github.com/pistarlab/pistarlab/
    cd pistarlab
    pip install -e .[all]
    

with Docker

  1. Install Docker:

    Visit: https://docs.docker.com/engine/install/

  2. Clone Repo

    docker pull docker.pkg.github.com/pistarlab/pistarlab/image:latest
    

Usage

To launch piSTAR Lab, run:

pistarlab_launcher

Open your browser to http://localhost:7777

To launch the piSTAR Lab docker container, run:

mkdir pistarlab_docker ; docker run --rm -i -t -u `id -u` \
    --shm-size=2g \
    -p 7776:7776  \
    -p 7777:7777  \
    -p 7778:7778  \
    -p 8265:8265 \
    -v ${HOME}/pistarlab_docker:/home/ray/pistarlab pistarlab/pistarlab:latest  --launcher_host="0.0.0.0"

Open your browser to http://localhost:7777

Extensions

Extensions are the primary mechanism for adding new Agents, Environments, Tasks and Components.

Below are extensions available via piSTAR Lab and the repo (https://github.com/pistarlab/pistarlab-repo/). Future versions will allow user created extensions to be used and shared as well.

Development Notes

Creating a manifest

Manfiest files are used to speed up the installation of Extensions. They are especially useful for Environments where probing is required.

Example of creating a manifest

xvfb-run python pistarlab/extensions_tools.py --action=save_manifest --extension_path PATH_TO_EXTENSION/pistarlab-envs-gym-main

Advanced

Settings

Data and Configuration Path

By default pistarlab stores data and configuration in the $HOME/pistarlab/ directory. (eg: /home/$USER/pistarlab) This can be changed by using the PISTARLAB_ROOT environment variable

If you are using Docker, PISTARLAB_ROOT is under $HOME/pistarlab_docker/. This has been changed for Docker to avoid permission issues that Docker may instroduce.

Configuration is stored in the config.yaml file located at PISTARLAB_ROOT

Data is stored under PISTARLAB_ROOT/data

Debugging

Our current solution uses the remote_pdb python module to enable remote debuging over telnet.

To use debugging, do the following:

  1. Insert the following code snip where you want the debugger to started and wait for your input

from ..utils.remote_pdb import set_trace
set_trace() # you'll see the port number in the logs
  1. When the above code is executed, it will print the port number to connect to in the logs.

  2. use telnet to connect and use pdb as usual: for example `telnet 127.0.0.1 PORTNUM_HERE`

Cluster Mode

Warning

Experimental

Cluster mode is handled by Ray. For more information visit ray.io.

WIP, this documentation is incomplete and more testing needed.

Requirements * PostgreSQL to communicate over network (Temporary) * Python Version should be same on all nodes

with Docker

Switch to python env to 3.7.7

This is needed because the docker version of Ray uses 3.7.7 and multiple versions of python create problems when pickling.

conda install python=3.7.7

Docker Related Issue with using Ray

  • file permission issues when using docker. files copied using rsync get permissions

  • /tmp/ray_tmp_mount

without Docker

** Configuration **

Config file path: ~/pistarlab/cluster.yaml

TODO, see for details

Startup
  1. Starting cluster

    ray up -vvvv ~/pistarlab/cluster.yaml
    
  2. Launch piSTAR Lab on head node

    python pistarlab/launcher.py --ray_address="IP_ADDRESS:6379"
    
Install extensions on nodes
ray exec $HOME/pistarlab/cluster.yaml  "pip install --user -e /home/pistarlabuser/app/pistarlab/extensions/pistarlab-envs-gym-main"
Sync Data with Nodes

Before each task run

ray rsync-up -vvv ~/pistarlab/cluster.yaml

After each task (or as needed)

ray rsync-down -vvv ~/pistarlab/cluster.yaml /home/pistarlabuser/pistarlab/data/ $HOME/pistarlab/data/

Troubleshooting

Missing .so error when running tensorflow

ensure LD_LIBRARY_PATH is correct

My GPU is suddenly not avilable (Ubuntu)

If your GPU was working previously, but suddenly is not accessable the the system. The following script may help the script at `scripts/fix_gpu.sh` may help.

Testing GPU

Check if torch is detecting the GPU

python -c “import torch; print(torch.cuda.is_available());”

Running Atari Environment on Windows

If you get this error:

FileNotFoundError: Could not find module '..\atari_py\ale_interface\ale_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.------------

Reinstall Atari from here: https://github.com/Kojoley/atari-py/releases

Design

piSTAR Lab is build from on serveral excellent opensource technologies including:

  • Redis (redis.io) - in-memory data store

  • Ray (ray.io) - distributed processing framework to handle remote task execution

  • SQLite (sqlite.org)/ PostgreSQL (postgresql.org)

  • Vuejs (vuejs.org) - web development framework built on (nodejs)

  • Theia IDE (theia-ide.org) - web based IDE

Developer Notes

Setting up your environment

Tested on Ubuntu

  1. Install Anaconda or Miniconda

    Visit https://www.anaconda.com/products/individual for instructions

  2. Create Conda Virtual Environment

    conda create -n pistarlab python=3.7
    
  3. Install PIP

    conda install pip
    
  4. Clone Repo and install

    git clone https://github.com/pistarlab/pistarlab
    cd pistarlab
    pip install -e .[all]
    
  5. Install additional dependencies
    • XVFB to render without display (No MS Windows Support)

    • ffmpeg for video processing

    sudo apt-get install -y xvfb ffmpeg
    
  6. Install NPM/Nodejs for UI and Theia IDE

    bash ./install_node.sh
    
  7. Build Web IDE (optional)

    bash ./build_ide.sh
    

on Windows [Experimental]

Limitation: no headless mode for many environments so rendering may open a window

  1. Install Miniconda

  2. Install GitBash

  3. Follow Ubuntu Instructions

Troubleshooting

Building Theia IDE on Windows. * https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#building-on-windows

Install Scoop

See: https://github.com/lukesampson/scoop#installation

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# or shorter
iwr -useb get.scoop.sh | iex
# IF SCOOP doesn't get added to path
$env:Path += ";C:\Users\${USER}\scoop\shims"

Making changes to the UI

The UI is build using Vuejs cli and requires npm to run. Once setup, changes to the ui source code will be reflected immidiately in the browser.

Option 1: # Start pistarlab with enable_dev_ui argument. Eg: `pistarlab_launcher --enable_dev_ui`

Option 2: #. Run the UI using `npm run serve` #. By default, changes will be reflected at http://localhost:8080

Building for Readonly Viewing

pip install -e . -no-deps
pip install -r requirements-webreadonly.txt

Building for PiPy

  1. Build Redis Server Binary and copy to pistarlab/thirdparty_lib

    bash ./install_redis.sh_
    
  2. Build and deploy UI in pistarlab/uidist/ package directory

    bash ./build_ui.sh
    
  3. Run Tests with tox

    pip install tox
    tox
    
  4. Building wheel and source distribution and view files

    rm -rf build dist *.egg-info &&
    python setup.py bdist_wheel && python -m build --sdist --wheel && unzip -l dist/*.whl
    
  5. Uploading to PiPy

    pip install twine
    twine upload dist/*
    

Building the Documentation

  1. Install dependencies

    pip install -r docs/requirements.txt
    
  2. Rebuild API Docs

    From the project root, run:

    cd docs
    sphinx-apidoc -o source ../pistarlab
    
  3. Update the HTML

    cd docs
    make html
    

Building and Publishing a new Docker Image

Instructions on how to create a docker image from an Ubuntu environment

  1. Make changes to docker file

  2. Update requirements.txt

    
    

    conda create -n pistarlab377 python=3.7.7 conda activate pistarlab377 pip install -e . pip freeze > requirements.txt

  3. Run Docker Build

    
    

    ./build_docker

Roadmap

Warning

Under development

Planned Features

  • Composable Agents - agents built from reusable components

  • Public repositories for agents and component snapshots

  • Filter by observation/action space

  • Persistent environments

  • UI for easy hyper parameter exploration

  • Learning resource: videos, documentation, and tutorials

  • Missions which help users gain intuition about different aspects of reinforcement learning

  • Hosted competitions

pistarlab

pistarlab package

Subpackages
pistarlab.agents package
Submodules
pistarlab.agents.random module
Module contents
pistarlab.envs package
Submodules
pistarlab.envs.ma_test_envs module
Module contents
pistarlab.tasks package
Submodules
pistarlab.tasks.matask module
pistarlab.tasks.tune_default module
Module contents
pistarlab.thirdparty_lib package
Module contents
pistarlab.utils package
Submodules
pistarlab.utils.agent_helpers module
pistarlab.utils.env_helpers module
pistarlab.utils.gym_importer module
pistarlab.utils.logging module
pistarlab.utils.misc module
pistarlab.utils.param_helpers module
pistarlab.utils.pkghelpers module
pistarlab.utils.pyson module
pistarlab.utils.remote_pdb module
pistarlab.utils.serialize module
pistarlab.utils.snapshot_helpers module
pistarlab.utils.timer module
Module contents
pistarlab.wrappers package
Submodules
pistarlab.wrappers.default module
Module contents
Submodules
pistarlab.agent module
pistarlab.api_schema module
pistarlab.app_backend module
pistarlab.common module
pistarlab.component module
pistarlab.config module
pistarlab.core module
pistarlab.data_context module
pistarlab.databuffer module
pistarlab.dbinit module
pistarlab.dbmodels module
pistarlab.entity module
pistarlab.env_base module
pistarlab.execution_context module
pistarlab.filestore module
pistarlab.launcher module
pistarlab.meta module
pistarlab.extension_manager module
pistarlab.extension_tools module
pistarlab.remote_conn module
pistarlab.remote_env module
pistarlab.services module
pistarlab.session module
pistarlab.session_config module
pistarlab.session_env module
pistarlab.storage module
pistarlab.streamer module
pistarlab.task module
pistarlab.task_runner module
pistarlab.util_funcs module
Module contents