add yapf style and apply yapf to format all Python files

This recreates pull request #2192
This commit is contained in:
Erwin Coumans
2019-04-27 07:31:15 -07:00
parent c591735042
commit ef9570c315
347 changed files with 70304 additions and 22752 deletions

View File

@@ -1,28 +1,32 @@
import re
from gym import error
import glob
# checkpoints/KerasDDPG-InvertedPendulum-v0-20170701190920_actor.h5
# checkpoints/KerasDDPG-InvertedPendulum-v0-20170701190920_actor.h5
weight_save_re = re.compile(r'^(?:\w+\/)+?(\w+-v\d+)-(\w+-v\d+)-(\d+)(?:_\w+)?\.(\w+)$')
def get_fields(weight_save_name):
match = weight_save_re.search(weight_save_name)
if not match:
raise error.Error('Attempted to read a malformed weight save: {}. (Currently all weight saves must be of the form {}.)'.format(id,weight_save_re.pattern))
return match.group(1), match.group(2), int(match.group(3))
match = weight_save_re.search(weight_save_name)
if not match:
raise error.Error(
'Attempted to read a malformed weight save: {}. (Currently all weight saves must be of the form {}.)'
.format(id, weight_save_re.pattern))
return match.group(1), match.group(2), int(match.group(3))
def get_latest_save(file_folder, agent_name, env_name, version_number):
"""
"""
Returns the properties of the latest weight save. The information can be used to generate the loading path
:return:
"""
path = "%s%s"% (file_folder, "*.h5")
file_list = glob.glob(path)
latest_file_properties = []
file_properties = []
for f in file_list:
file_properties = get_fields(f)
if file_properties[0] == agent_name and file_properties[1] == env_name and (latest_file_properties == [] or file_properties[2] > latest_file_properties[2]):
latest_file_properties = file_properties
path = "%s%s" % (file_folder, "*.h5")
file_list = glob.glob(path)
latest_file_properties = []
file_properties = []
for f in file_list:
file_properties = get_fields(f)
if file_properties[0] == agent_name and file_properties[1] == env_name and (
latest_file_properties == [] or file_properties[2] > latest_file_properties[2]):
latest_file_properties = file_properties
return latest_file_properties
return latest_file_properties