Перейти к файлу
Chris Kahrs 725244a938
Merge pull request #17 from microsoft/gym-dssat-agriculture-sample
merge dssat agriculture sample to main
2022-11-07 08:20:57 -05:00
bonsai_gym override gym_simulate to fix up reward/observation 2022-10-28 16:30:30 -07:00
ci CI: fix pipeline using latest ubuntu (#13) 2022-08-25 15:36:49 +02:00
samples install prerequisites for pillow library (dependency of this version of gym?) 2022-10-31 16:48:26 -07:00
.gitignore ignore .vscode folder 2022-10-28 16:36:41 -07:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2020-08-24 21:04:59 -07:00
LICENSE Updating LICENSE to template content 2020-08-24 21:05:01 -07:00
README.md UPDATE: readme with proper links to official docs and description about reward and terminal 2020-12-14 15:32:24 -08:00
SECURITY.md Initial SECURITY.md commit 2020-08-24 21:05:04 -07:00
setup.cfg Release 2020.08.27 2020-08-27 21:39:09 -07:00
setup.py revert gym>=0.18.0 2022-10-28 16:39:38 -07:00

README.md

Bonsai Gym

A python library for integrating Bonsai brains with Open AI Gym environments.

Bonsai Gym

A python library for integrating Bonsai BRAIN with Open AI Gym environments.

Installation

One of the requirements bonsai-common is not located on pypi and must be installed from the github repo

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

Install the latest bonsai-gym from github.

NOTE - The bonsai-gym located on pypi is an older release that we no longer support. We have no plans to publish this to pypi

$ pip install git+https://github.com/microsoft/bonsai-gym

Usage

Once installed, import bonsai_gym in order to access base class GymSimulator3, which implements all of the environment-independent Bonsai SDK integrations necessary to train a Bonsai BRAIN to play an OpenAI Gym simulator.

See CartPole sample

    import gym

    from bonsai_gym import GymSimulator3

    class CartPole(GymSimulator3):
        # Environment name, from openai-gym
        environment_name = "CartPole-v0"

        # Simulator name from Inkling
        simulator_name = "CartpoleSimulator"

        # convert openai gym observation to our state type
        def gym_to_state(self, observation):
            state = {
                "position": observation[0],
                "velocity": observation[1],
                "angle": observation[2],
                "rotation": observation[3],
            }
            return state

        # convert our action type into openai gym action
        def action_to_gym(self, action):
            return action["command"]


    if __name__ == "__main__":
        # create a brain, openai-gym environment, and simulator
        config = BonsaiClientConfig(argv=sys.argv)
        sim = CartPole(config)
        sim.run_gym()

Running Simulator

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 script:

export SIM_WORKSPACE=<your-workspace-id>
export SIM_ACCESS_KEY=<your-access-key>
python3 my_sim.py

Rewards and Terminals

The GymSimulator3 class automatically appends the gym reward and gym terminal to the state extracted from the environment with the keys named _gym_reward and _gym_terminal respectively. You can use these rewards and terminals in your Inkling definition using Inkling functions. See the example Inklings in the samples directory to see a standard implementation.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.