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


Api-bindings to use the OpenAI directly inside of rust

2 releases

0.1.1 Aug 27, 2017
0.1.0 Aug 27, 2017

#12 in Simulation

12 downloads per month


51 lines

OpenAI in rust

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


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


open_ai = "0.1.1"
rand = "0.3"


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 {

        // 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();


~24K SLoC