Git Product home page Git Product logo

cartpole-py's Introduction

cartpole-py

A simple Python example that creates a training simulator for Bonsai. It simulates a cartpole balancing environment. The SimulatorSession interface is implemented to demonstrate using bonsai-common, a Python framework for interfacing with the Bonsai platform.

Prerequisites

Simulators need two environment variables set to be able to attach to the platform.

The first is SIM_ACCESS_KEY. You can create one from the Account Settings page. You have one chance to copy the key once it has been created. Make sure you don't enter the ID.

The second is SIM_WORKSPACE. You can find this in the URL after /workspaces/ once you are logged in to the platform.

There is also an optional SIM_API_HOST key, but if it is not set it will default to https://api.bons.ai.

If you're launching your simulator from the command line, make sure that you have these two environment variables set. If you like, you could use the following example Bash script:

export SIM_WORKSPACE=<your-workspace-id>
export SIM_ACCESS_KEY=<your-access-key>

You will need to install support libraries prior to running. Our demos depend on bonsai-common. This library will need to be installed from source.

pip3 install git+https://github.com/microsoft/bonsai-common

Running from your local Python environment

python3 cartpole.py

When you run this, the simulator registers with your Bonsai workspace. This adds an unmanaged entry to the list of simulators in your workspace portal that can be used to train brains while executing the simulation in your local Python environment.

Building Demo Dockerfile

docker build -t <IMAGE_NAME> -f Dockerfile ../../

Run Dockerfile local

docker run --rm -it -e SIM_ACCESS_KEY="<ACCESS_KEY>" -e SIM_API_HOST="<TARGET>" -e SIM_WORKSPACE="<WORKSPACE>" <IMAGE_NAME>

This adds an unmanaged entry to the list of simulators in your workspace portal that can be used to train brains while executing the simulation in your container.

How to push to ACR

az login # (Is not necessary if you are already up to date or logged in recently)
az acr login --subscription <SUBSCRIPTION_ID> --name <ACR_REGISTRY_NAME>
docker tag <IMAGE_NAME> <ACR_REGISTRY_NAME>.azurecr.io/bonsai/<IMAGE_NAME>
docker push <ACR_REGSITRY_NAME>.azurecr.io/bonsai/<IMAGE_NAME>

Example run Dockerfile

docker build -t cartpole -f Dockerfile ../../
docker run --rm -it -e SIM_ACCESS_KEY="111" -e SIM_API_HOST="https://api.bons.ai" -e SIM_WORKSPACE="123"

Example push to ACR(Assuming you logged in)

docker build -t cartpole -f Dockerfile ../../
docker tag cartpole bonsaisimpreprod.azurecr.io/bonsai/cartpole
docker push bonsaisimpreprod.azurecr.io/bonsai/cartpole

Once your image is registered in the ACR you can switch the web and click Add Simulator from the left hand navigation. Enter the URL to the image there and give it a name. Use this name in your Inkling to refer to the simulator.

Microsoft Open Source Code of Conduct

This repository is subject to the Microsoft Open Source Code of Conduct.

cartpole-py's People

Contributors

forresttrepte avatar mikest avatar nmann4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cartpole-py's Issues

Cartpoleviz

Hi
Could I please have access to /Cartpoleviz/? Or a refence on how to roll our own?

Kind Regards,
Elliot Wood

Docker file refers to Samples parent folder

The instructions for building a docker container do not work and the reason is in the docker file which refers to a path of a parent folder named Samples. The folder is not part of the repo and users without Docker knowledge would not be able to follow and complete the tutorial.

Environment variables not used

As of the the instructions the user has to create environment variables to be used later by bonsai-common. However there are few issues:

  • please specify whether the variable has to be for the user or for the system
  • even after setting the environment variables and verifying that they can be accessed, it appears that the config.py in microsoft_bonsai_api (dependency) is trying to parse empty argv string and replaces the defaults from the environment variables. As a result the docker run cannot connect to the service. (so it seems the env. variables are not necessary at all)
  • I ended up with something like (there is similar line in the markdown)

docker run --rm -it -e SIM_ACCESS_KEY="Y2U2...โ€œ -e SIM_API_HOST="https://api.bons.ai" -e SIM_WORKSPACE="b6ab...." cartpole:latest

  • _sessions_operations file refers {workplaceName} variable - something which I thought is the problem for some time and was trying to solve by passing workplacename. However it seems to be using workplaceID despite of the variable name. Please change the variable name
  • (in the markdown this is referred only when creating the environment variables)
    Cheers :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.