Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
from gym import envs, spaces, logger
|
2016-06-17 13:23:49 -07:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
2016-10-21 19:00:36 -07:00
|
|
|
import argparse
|
2016-06-17 13:23:49 -07:00
|
|
|
|
2017-05-13 20:40:33 -07:00
|
|
|
from gym.envs.tests.spec_list import should_skip_env_spec_for_tests
|
2016-06-17 13:23:49 -07:00
|
|
|
from gym.envs.tests.test_envs_semantics import generate_rollout_hash, hash_object
|
|
|
|
|
|
|
|
DATA_DIR = os.path.join(os.path.dirname(__file__), os.pardir, 'gym', 'envs', 'tests')
|
|
|
|
ROLLOUT_STEPS = 100
|
|
|
|
episodes = ROLLOUT_STEPS
|
|
|
|
steps = ROLLOUT_STEPS
|
|
|
|
|
2016-10-21 19:00:36 -07:00
|
|
|
ROLLOUT_FILE = os.path.join(DATA_DIR, 'rollout.json')
|
2016-06-17 13:23:49 -07:00
|
|
|
|
2016-10-21 19:00:36 -07:00
|
|
|
if not os.path.isfile(ROLLOUT_FILE):
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
logger.info("No rollout file found. Writing empty json file to {}".format(ROLLOUT_FILE))
|
|
|
|
with open(ROLLOUT_FILE, "w") as outfile:
|
|
|
|
json.dump({}, outfile, indent=2)
|
2016-06-17 13:23:49 -07:00
|
|
|
|
2016-10-21 19:00:36 -07:00
|
|
|
def update_rollout_dict(spec, rollout_dict):
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
"""
|
|
|
|
Takes as input the environment spec for which the rollout is to be generated,
|
|
|
|
and the existing dictionary of rollouts. Returns True iff the dictionary was
|
|
|
|
modified.
|
|
|
|
"""
|
|
|
|
# Skip platform-dependent
|
|
|
|
if should_skip_env_spec_for_tests(spec):
|
|
|
|
logger.info("Skipping tests for {}".format(spec.id))
|
|
|
|
return False
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
# Skip environments that are nondeterministic
|
|
|
|
if spec.nondeterministic:
|
|
|
|
logger.info("Skipping tests for nondeterministic env {}".format(spec.id))
|
|
|
|
return False
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
logger.info("Generating rollout for {}".format(spec.id))
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
try:
|
|
|
|
observations_hash, actions_hash, rewards_hash, dones_hash = generate_rollout_hash(spec)
|
|
|
|
except:
|
|
|
|
# If running the env generates an exception, don't write to the rollout file
|
|
|
|
logger.warn("Exception {} thrown while generating rollout for {}. Rollout not added.".format(sys.exc_info()[0], spec.id))
|
|
|
|
return False
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
rollout = {}
|
|
|
|
rollout['observations'] = observations_hash
|
|
|
|
rollout['actions'] = actions_hash
|
|
|
|
rollout['rewards'] = rewards_hash
|
|
|
|
rollout['dones'] = dones_hash
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
existing = rollout_dict.get(spec.id)
|
|
|
|
if existing:
|
|
|
|
differs = False
|
|
|
|
for key, new_hash in rollout.items():
|
|
|
|
differs = differs or existing[key] != new_hash
|
|
|
|
if not differs:
|
|
|
|
logger.debug("Hashes match with existing for {}".format(spec.id))
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
logger.warn("Got new hash for {}. Overwriting.".format(spec.id))
|
2016-06-17 13:23:49 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
rollout_dict[spec.id] = rollout
|
|
|
|
return True
|
2016-06-17 13:23:49 -07:00
|
|
|
|
2016-10-21 19:00:36 -07:00
|
|
|
def add_new_rollouts(spec_ids, overwrite):
|
2019-07-12 13:59:33 -04:00
|
|
|
environments = [spec for spec in envs.registry.all() if spec.entry_point is not None]
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
if spec_ids:
|
|
|
|
environments = [spec for spec in environments if spec.id in spec_ids]
|
|
|
|
assert len(environments) == len(spec_ids), "Some specs not found"
|
|
|
|
with open(ROLLOUT_FILE) as data_file:
|
|
|
|
rollout_dict = json.load(data_file)
|
|
|
|
modified = False
|
|
|
|
for spec in environments:
|
|
|
|
if not overwrite and spec.id in rollout_dict:
|
|
|
|
logger.debug("Rollout already exists for {}. Skipping.".format(spec.id))
|
|
|
|
else:
|
|
|
|
modified = update_rollout_dict(spec, rollout_dict) or modified
|
2016-10-21 19:00:36 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
if modified:
|
|
|
|
logger.info("Writing new rollout file to {}".format(ROLLOUT_FILE))
|
|
|
|
with open(ROLLOUT_FILE, "w") as outfile:
|
|
|
|
json.dump(rollout_dict, outfile, indent=2, sort_keys=True)
|
|
|
|
else:
|
|
|
|
logger.info("No modifications needed.")
|
2016-10-21 19:00:36 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-f', '--force', action='store_true', help='Overwrite '+
|
|
|
|
'existing rollouts if hashes differ.')
|
|
|
|
parser.add_argument('-v', '--verbose', action='store_true')
|
|
|
|
parser.add_argument('specs', nargs='*', help='ids of env specs to check (default: all)')
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.verbose:
|
|
|
|
logger.set_level(logger.INFO)
|
|
|
|
add_new_rollouts(args.specs, args.force)
|