#machine-learning #ai #rl #openai #neuro-evolution

open_ai

Api-bindings to use the OpenAI directly inside of rust

2 releases

0.1.1 Aug 27, 2017
0.1.0 Aug 27, 2017

#8 in Simulation

Download history 1/week @ 2018-08-15 2/week @ 2018-08-22 5/week @ 2018-09-05 1/week @ 2018-09-12 2/week @ 2018-09-26 7/week @ 2018-10-03 9/week @ 2018-10-17 3/week @ 2018-10-24 15/week @ 2018-11-07

12 downloads per month

Apache-2.0

7KB
51 lines

OpenAI in rust

This crate allows you to create an environment in OpenAI where to train your agents.

Setup

To use this crate you will need to have a few things already installed on your machine including python 3 as well as OpenAI gym and the environments you need. You can find out how to install OpenAI in the README of their repository.

Once you've installed all of the dependencies you'll need to start a display server on port zero like this:

xvfb-run -s "-screen 0 1080x1920x24" bash
export DISPLAY=:0

Now that you've executed this command you can run your program and a window should pop up and you'll see your agent training in the environment that you have chosen.

Code example

Cargo.toml

[dependencies]
open_ai = "0.1.1"
rand = "0.3"

main.rs

extern crate open_ai;
extern crate rand;

use rand::Rng;
use open_ai::{ Python, Env, PyDict };

fn main() {
    let gil = Python::acquire_gil();

    // Create your environment
    let env = Env::make(gil.python(), "LunarLander-v2");

    let mut observation = env.reset();
    loop {
        env.render();

        // Here goes your agent
        let action: i32 = rand::thread_rng().gen_range(0,4);

        let result = env.step(action);
        observation = result.0;

        if result.2 {
            observation = env.reset();
        }
    }
}

Dependencies

~1MB
~23K SLoC