|
import pickle |
|
import datasets |
|
import numpy as np |
|
|
|
_DESCRIPTION = """The dataset consists of tuples of (observations, actions, rewards, dones) sampled by agents |
|
interacting with the CityLearn 2022 Phase 1 environment""" |
|
|
|
_BASE_URL = "https://huggingface.co/datasets/TobiTob/CityLearn/resolve/main" |
|
_URLS = { |
|
"s_test": f"{_BASE_URL}/s_test.pkl", |
|
"s_test2": f"{_BASE_URL}/s_test2.pkl", |
|
"s_test3": f"{_BASE_URL}/s_test3.pkl", |
|
"s_test4": f"{_BASE_URL}/s_test4.pkl", |
|
"s_test5": f"{_BASE_URL}/s_test5.pkl", |
|
"s_test6": f"{_BASE_URL}/s_test6.pkl", |
|
"s_test7": f"{_BASE_URL}/s_test7.pkl", |
|
"s_8759x5": f"{_BASE_URL}/s_8759x5.pkl", |
|
"halfcheetah-medium-replay-v2": f"{_BASE_URL}/test.pkl", |
|
} |
|
|
|
|
|
class DecisionTransformerCityLearnDataset(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="s_test", |
|
description="Test Data size 10x8", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test2", |
|
description="Test Data size 10x16", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test3", |
|
description="Test Data size 100x16", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test4", |
|
description="Test Data size 10x1000", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test5", |
|
description="Test Data size 260x168 (week)", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test6", |
|
description="Test Data size 60x730 (month)", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_test7", |
|
description="Test Data size 5x3000", |
|
), |
|
datasets.BuilderConfig( |
|
name="s_8759x5", |
|
description="Data sampled from an expert policy in CityLearn environment", |
|
), |
|
datasets.BuilderConfig( |
|
name="halfcheetah-medium-replay-v2", |
|
description="Test Data", |
|
), |
|
] |
|
|
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"observations": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), |
|
"actions": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), |
|
"rewards": datasets.Sequence(datasets.Value("float32")), |
|
"dones": datasets.Sequence(datasets.Value("bool")), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = _URLS[self.config.name] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir, |
|
"split": "train", |
|
}, |
|
) |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
with open(filepath, "rb") as f: |
|
trajectories = pickle.load(f) |
|
|
|
for idx, traj in enumerate(trajectories): |
|
yield idx, { |
|
"observations": traj["observations"], |
|
"actions": traj["actions"], |
|
"rewards": np.expand_dims(traj["rewards"], axis=1), |
|
"dones": np.expand_dims(traj.get("dones", traj.get("terminals")), axis=1), |
|
} |
|
|