Skip to main content

SimpleOptions

This Python package aims to provide a simple framework for implementing and using options in Hierarchical Reinforcement Learning (HRL) projects.

Key classes:

  • BaseOption: An abstract class representing an option with an initiation set, option policy, and termination condition.
  • BaseEnvironment: An abstract base class representing an agent's environment. The environment specification is based on the OpenAI Gym Env specifciation, but does not implement it directly. It supports both primitive actions and options, as well as functionality for constructing State-Transition Graphs (STGs) out-of-the-box using NetworkX.
  • OptionAgent: A class representing an HRL agent, which can interact with its environment and has access to a number of options. It includes implementations of Macro-Q Learning and Intra-Option learning, with many customisable features.

This code was written with tabular, graph-based HRL methods in mind. It's less of a plug-and-play repository, and is intended to be used to as a basic framework for developing your own BaseOption and Environment implementations.

How to Install

The easiest way to install this package is to simply run pip install simpleoptions.

Alternatively, you can install from source. Simply download this repository and, in the root directory, run the command pip install .

How to Use This Code

Below, you will find a step-by-step guide introducing the intended workflow for using this code.

Step 1: Implement an Environment

The first step to using this framework involves defining an environment for your agents to interact with. This can be done by subclassing the BaseEnvironment abstract class and filling in the abstract methods. If you have previously worked with OpenAI Gym/Farama Gymnasium, much of this will be familiar to you, although there are a few additional methods on top of the usual step and reset that you'll need to implement.

Step 2: Define Your Options

You must now define/discover options for your agent to use when interacting with its environment. How you go about this is up to you. An ever-growing number of option discovery methods can be found in the hierarchical reinforcement learning literature. We include some option discovery method implementations in the implementations directory.

To define a new type of option, you need to subclass BaseOption and implement the following methods:

  • initiation - a method that takes a state as its input, and returns whether the option can be invoked in that state.
  • termination - a method that takes a state as its input, and returns the probability that the option terminates in that state.
  • policy - a method that takes a state as its input, and returns the action (either a primitive action or another option) that this option would select in this state.

This minimal framework gives you a lot of flexibility in defining your options. For example, your policy method could make use of a simple dictionary mapping states to actions, it could be based on some learned action-value function, or any other function of the state.

As an example, consider an example option that takes an agent to a sub-goal state from any of the nearest 50 states. initiation would return True for the nearest 50 states to the subgoal, and False otherwise. termination would return 0.0 for states in the initiation set, and 1.0 otherwise. policy woudl return the primitive action that takes the agent one step along the shortest path to the subgoal state.

Finally, we also include a PrimitiveOption that can be used to represent the primitive actions made available by a given environment.

Step 5: Giving Options to an Agent and Running It in an Environment

This package also includes an OptionsAgent, an implementation of an agent that learns using the Macro-Q Learning and Intra-Option Learning algorithms.

Once you have defined an environment an a set of options, you can instatiate an OptionsAgent agent and use its run_agent method to train it.

Example Environments

A number of reinforcement learning environments implemented using our BaseEnvironment interfaces can be found here.

Metadata

Release files for simpleoptions 0.11.0

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

Source distribution (sdist)

Source distribution for simpleoptions 0.11.0
File Size Uploaded
simpleoptions-0.11.0.tar.gz 28.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simpleoptions 0.11.0
File Interpreter ABI Platform
simpleoptions-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.2 kB

Release files / simpleoptions-0.11.0.tar.gz

Download URL simpleoptions-0.11.0.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6aa3e64dde0910548d11078dc83194ae5a8fa7cd12d5d37f2d2e9b271a70d3bc
BLAKE2b-256 checksum
How to use checksums
85fafc2b9bd45e898219ca8bcc79014001c36f7e876d7e29209e62acb1070445
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / simpleoptions-0.11.0-py3-none-any.whl

Download URL simpleoptions-0.11.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc4eb418a714d811e8d0d9820dc3e9117cd98a8c0d47fe1c62953a28c7115e02
BLAKE2b-256 checksum
How to use checksums
8a3c4f65e8090dd3f4c35b8f6437e7d8c0174a7308d70dc0c09c7ae4091d4dc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.9.1

2 release files

0.8.3

2 release files

0.6.2

1 release file

0.6.1

1 release file

0.3.1

1 release file

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