Skip to main content

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

Metadata

Release files for sorting-gym 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sorting-gym 0.0.9
File Size Uploaded
sorting-gym-0.0.9.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sorting-gym 0.0.9
File Interpreter ABI Platform
sorting_gym-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 34.4 kB

Release files / sorting-gym-0.0.9.tar.gz

Download URL sorting-gym-0.0.9.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a43655f2cf5f91dcfa945fde51f4918bf07d2bed889b829361bae07a04a8ef4c
BLAKE2b-256 checksum
How to use checksums
249d4e7afd0a58362ad1044fcd4e02e01f89fd6d50f4e6eaeec55febfe7e5f74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.7.4 Windows/10

Release files / sorting_gym-0.0.9-py3-none-any.whl

Download URL sorting_gym-0.0.9-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70b94f442a712572ec2cc312c73dd8ba239b6f10cb5186ece250fcdd9afd1f1c
BLAKE2b-256 checksum
How to use checksums
28f0ffa776ceed4add6eb8e2a57cd42f00e72b672bf04102d10959929f84cfc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.7.4 Windows/10

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page