microsoft / cartpole-py

A cart and pole simulator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A cart and pole simulator.

License:MIT License


Languages

Language:Python 89.8%Language:Dockerfile 10.2%