Skip to main content

Wrapper for creating vectorized gymnasium environments.

Project description

Ninetails

A wrapper for creating vectorized gymnasium environments.

Installation

pip3 install ninetails

Usage

import gymnasium as gym
import numpy as np

from ninetails import SubProcessVectorGymnasiumEnv


def main() -> None:
    """main.

    Returns:
        None:
    """
    # define your environment using a function that returns the environment here
    env_fns = [lambda i=i: gym.make("MountainCarContinuous-v0") for i in range(1)]

    # create a vectorized environment
    # `strict` is useful here for debugging
    vec_env = SubProcessVectorGymnasiumEnv(env_fns=env_fns, strict=True)

    # define our initial termination and trunction arrays
    terminations, truncations = np.array([False]), np.array([False])

    # reset follows the same signature as a Gymnasium environment
    observations, infos = vec_env.reset(seed=42)

    for step_count in range(5000):
        # sample an action, this is an np.ndarray of [num_envs, *env.action_space.shape]
        actions = vec_env.sample_actions()

        # similarly, the step function follows the same signature as a Gymnasium environment with the following shapes
        # observations: np.ndarray of shape [num_envs, *env.observation_space.shape]
        # rewards: np.ndarray of shape [num_envs, 1]
        # terminations: np.ndarray of shape [num_envs, 1]
        # truncations: np.ndarray of shape [num_envs, 1]
        # infos: tuple[dict[str, Any]]
        observations, rewards, terminations, truncations, infos = vec_env.step(actions)

        # to reset underlying environments
        done_ids = set(np.where(terminations).tolist() + np.where(truncations).tolist())
        for id in done_ids:
            # warning, you'll have to handle starting observations yourself here
            reset_obs, reset_info = vec_env.reset(id)


if __name__ == "__main__":
    main()

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

ninetails-0.0.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

ninetails-0.0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file ninetails-0.0.3.tar.gz.

File metadata

  • Download URL: ninetails-0.0.3.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ninetails-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6ce39bd8013fe79674fba173c4ce30de60b3adc12c726c06b98ae664c43629b2
MD5 d5cfd52e05f6f3b7efbbdc3990a2f97e
BLAKE2b-256 f7618f2dcf9b2a0ff75bc194e930b4e140fcbd35e50ad081efe31172e83c5c2c

See more details on using hashes here.

File details

Details for the file ninetails-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: ninetails-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ninetails-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e7c40e573afd091b9489486147e7db57946bb194fc668d6b12c49c0ac31013f9
MD5 f7c3bfc56da5426fcb93e974bd42a612
BLAKE2b-256 9619ec87f3a4622900699209d931ed2d08dc473c09457655b596cfa173338d9d

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