Created
November 1, 2020 15:22
-
-
Save benblack769/1ca446b054a6ff4245da32c5f09d1666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pettingzoo.tests.all_modules import all_environments | |
from pettingzoo.tests.seed_test import calc_hash | |
import time | |
import random | |
import numpy as np | |
import supersuit | |
import gym | |
import random | |
import json | |
import sys | |
def gen_actions(): | |
all_actions = {} | |
for name, module in all_environments.items(): | |
env = module.env() | |
actions = {agent: [np.array(space.sample()).tolist() for i in range(50)] for agent, space in env.action_spaces.items()} | |
all_actions[name] = actions | |
return all_actions | |
def gen_hashes(all_actions): | |
out_hashes = {} | |
random.seed(32) | |
np.random.seed(43) | |
for name, module in (all_environments.items()): | |
# if "sisl" not in name: | |
# continue | |
print(name) | |
env = module.env() | |
base_seed = 42 | |
env.seed(base_seed) | |
out_hashes[name] = calc_hash(env, all_actions[name]) | |
return out_hashes | |
def write_json(name, jdata): | |
out = json.dumps(jdata, indent=2,sort_keys=True) | |
open(name, 'w').write(out) | |
def read_json(name): | |
return json.loads(open(name).read()) | |
if __name__ == "__main__": | |
cmd = sys.argv[1] | |
if cmd == "write": | |
actions = gen_actions() | |
hashes = gen_hashes(actions) | |
write_json("out_hashes.json", hashes) | |
write_json("actions.json", actions) | |
elif cmd == "read": | |
actions = read_json("actions.json") | |
# hashes = read_json("out_hashes.json") | |
out_hashes = gen_hashes(actions) | |
write_json("new_out_hashes.json", out_hashes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment