Skip to main content

OpenAI Gym Environments for Sorting

Project description

Sorting Gym

OpenAI Gym Environments for Sorting based on the 2020 paper Strong Generalization and Efficiency in Neural Programs by Yujia Li, Felix Gimeno, Pushmeet Kohli, Oriol Vinyals.

This repository includes implementations of the neural interface environments for sorting.

Install from pypi (recommended) with:

pip install sorting-gym

Importing the Python package sorting_gym will expose the following Gym environments:

  • SortTapeAlgorithmicEnv-v0 - Tape based environment based on Gym's algorithmic environment)
  • BasicNeuralSortInterfaceEnv-v0 - an interface where agents can implement simple algorithms such as bubble sort and insertion sort.
  • FunctionalNeuralSortInterfaceEnv-v0 - extends the BasicNeuralSortInterfaceEnv-v0 interface to include instructions for entering and exiting functions.

To define the parametric action space we introduce the DiscreteParametric(Space) type, allowing environments to describe disjoint output spaces, conditioned on a discrete parameter space. For example:

from gym.spaces import Discrete, Tuple, MultiBinary
from sorting_gym import DiscreteParametric
action_space = DiscreteParametric(2, ([Discrete(2), Tuple([Discrete(3), MultiBinary(3)])]))
action_space.sample()
(1, 2, array([0, 1, 0], dtype=int8))
action_space.sample()
(0, 1)

For agents that don't support a parametric action space, we provide two wrappers (BoxActionSpaceWrapper and MultiDiscreteActionSpaceWrapper) that flatten the DiscreteParametric action space down to a Box and a MultiDiscrete respectively.

In the sorting_gym.agents.scripted module we implement the scripted agents from the paper directly using the unwrapped environment.

RL Agents may want to consider supporting parametric/auto-regressive actions:

Goals:

  • Implement bubblesort/insertion sort environment.
  • Implement bubblesort/insertion sort agents as tests.
  • Implement function environment.
  • Implement quick sort scripted agent to test function environment.
  • Wrap the environment to expose a box action space.
  • Wrap the environment to expose a MultiDiscrete action space.
  • Include an example solution to train an agent via RL
  • Environment rendering (at least text based, optional dependency for rendering graphically with e.g. pygame)
  • Remove the tape environment from open ai gym (used to generate longer data as agent levels up)
  • Housekeeping - license and ci

Ideas to take it further:

  • Accelerate environment with cython (if required)
  • Open PR to gym for a discrete parametric space
  • Abstract out a Neural Controller Mixin/Environment Wrapper?
  • Consider a different/enhanced instruction set. Instead of always comparing every pointer and data element in the view (and neighbours), have explicit comparison instructions. Could extend to other math instructions, including accounting for variable cost of the instructions.
  • Instead of passing previous arguments, consider passing in the number of instructions executed in the current scope as a cheap program counter.

Run test with pytest

pytest

Building/Packaging

poetry update
poetry version patch
poetry lock
poetry build
poetry publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sorting-gym-0.0.9.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

sorting_gym-0.0.9-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file sorting-gym-0.0.9.tar.gz.

File metadata

  • Download URL: sorting-gym-0.0.9.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.7.4 Windows/10

File hashes

Hashes for sorting-gym-0.0.9.tar.gz
Algorithm Hash digest
SHA256 a43655f2cf5f91dcfa945fde51f4918bf07d2bed889b829361bae07a04a8ef4c
MD5 1274acd2df1d12863f21a3fed119f626
BLAKE2b-256 249d4e7afd0a58362ad1044fcd4e02e01f89fd6d50f4e6eaeec55febfe7e5f74

See more details on using hashes here.

File details

Details for the file sorting_gym-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: sorting_gym-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.7.4 Windows/10

File hashes

Hashes for sorting_gym-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 70b94f442a712572ec2cc312c73dd8ba239b6f10cb5186ece250fcdd9afd1f1c
MD5 c086c9d9cccae5089871cf3c93d1d700
BLAKE2b-256 28f0ffa776ceed4add6eb8e2a57cd42f00e72b672bf04102d10959929f84cfc4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page