Dataset Usage#

Here we provide examples of how to access the data in the dataset for your own use.

reconstructed_environment = gym.make(
    deserialise_spec_stack(json.loads(dataset.environment_stack))
)

Complete Working Example#

Environment Setup#

To run the full code below, you will need to install the dependencies shown below. It is recommended to use a newly-created virtual environment to avoid dependency conflicts.

numpy
cython
#minari
git+https://github.com/WillDudley/Gymnasium.git@spec_stack#egg=gymnasium[box2d]

Then you need to pip install -e . from the root of the repository.

Full Code#

# pyright: basic, reportGeneralTypeIssues=false

import json

import gymnasium as gym
from gymnasium.utils.serialize_spec_stack import deserialise_spec_stack

import minari

dataset = minari.download_dataset("LunarLander_v2_remote-test-dataset")

print("*" * 60, " Dataset Structure")
print(f"Dataset attributes: {dataset.__dir__()}\n")
print(f"Episode attributes: {dataset.episodes[0].__dir__()}\n")
print(f"Transition attributes: {dataset.episodes[0].transitions[0].__dir__()}\n")

print("*" * 60, " Examples")
print(f"Shape of observations: {dataset.observations.shape}\n")
print(f"Return of third episode: {dataset.episodes[2].compute_return()}\n")
print(f"21st action of fifth episode: {dataset.episodes[4].transitions[20].action}\n")

reconstructed_environment = gym.make(
    deserialise_spec_stack(json.loads(dataset.environment_stack))
)