mirror of
https://github.com/wassname/ray.git
synced 2026-07-15 11:25:40 +08:00
Fixing Lint after flake upgrade (#1162)
* Fixing Lint after flake upgrade * more lint fixes
This commit is contained in:
committed by
Robert Nishihara
parent
6da7761d5d
commit
797f4fcbf3
@@ -32,19 +32,19 @@ def sigmoid(x):
|
||||
return 1.0 / (1.0 + np.exp(-x))
|
||||
|
||||
|
||||
def preprocess(I):
|
||||
def preprocess(img):
|
||||
"""Preprocess 210x160x3 uint8 frame into 6400 (80x80) 1D float vector."""
|
||||
# Crop the image.
|
||||
I = I[35:195]
|
||||
img = img[35:195]
|
||||
# Downsample by factor of 2.
|
||||
I = I[::2, ::2, 0]
|
||||
img = img[::2, ::2, 0]
|
||||
# Erase background (background type 1).
|
||||
I[I == 144] = 0
|
||||
img[img == 144] = 0
|
||||
# Erase background (background type 2).
|
||||
I[I == 109] = 0
|
||||
img[img == 109] = 0
|
||||
# Set everything else (paddles, ball) to 1.
|
||||
I[I != 0] = 1
|
||||
return I.astype(np.float).ravel()
|
||||
img[img != 0] = 1
|
||||
return img.astype(np.float).ravel()
|
||||
|
||||
|
||||
def discount_rewards(r):
|
||||
|
||||
@@ -46,8 +46,8 @@ SIMPLE_OBJECTS = (BASE_SIMPLE_OBJECTS +
|
||||
|
||||
# Create some complex objects that cannot be serialized by value in tasks.
|
||||
|
||||
l = []
|
||||
l.append(l)
|
||||
lst = []
|
||||
lst.append(lst)
|
||||
|
||||
|
||||
class Foo(object):
|
||||
@@ -55,7 +55,7 @@ class Foo(object):
|
||||
pass
|
||||
|
||||
|
||||
BASE_COMPLEX_OBJECTS = [999 * "h", 999 * u"h", l, Foo(),
|
||||
BASE_COMPLEX_OBJECTS = [999 * "h", 999 * u"h", lst, Foo(),
|
||||
10 * [10 * [10 * [1]]]]
|
||||
|
||||
LIST_COMPLEX_OBJECTS = [[obj] for obj in BASE_COMPLEX_OBJECTS]
|
||||
|
||||
@@ -33,7 +33,7 @@ def check_serializable(cls):
|
||||
.format(cls))
|
||||
try:
|
||||
obj = cls.__new__(cls)
|
||||
except:
|
||||
except Exception:
|
||||
raise RayNotDictionarySerializable("The class {} has overridden "
|
||||
"'__new__', so Ray may not be able "
|
||||
"to serialize it efficiently."
|
||||
|
||||
@@ -66,18 +66,15 @@ def address(ip_address, port):
|
||||
|
||||
|
||||
def get_ip_address(address):
|
||||
try:
|
||||
ip_address = address.split(":")[0]
|
||||
except:
|
||||
raise Exception("Unable to parse IP address from address "
|
||||
"{}".format(address))
|
||||
assert type(address) == str, "Address must be a string"
|
||||
ip_address = address.split(":")[0]
|
||||
return ip_address
|
||||
|
||||
|
||||
def get_port(address):
|
||||
try:
|
||||
port = int(address.split(":")[1])
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception("Unable to parse port from address {}".format(address))
|
||||
return port
|
||||
|
||||
@@ -505,7 +502,7 @@ def start_ui(redis_address, stdout_file=None, stderr_file=None, cleanup=True):
|
||||
ui_process = subprocess.Popen(command, env=new_env,
|
||||
cwd=new_notebook_directory,
|
||||
stdout=stdout_file, stderr=stderr_file)
|
||||
except:
|
||||
except Exception:
|
||||
print("Failed to start the UI, you may need to run "
|
||||
"'pip install jupyter'.")
|
||||
else:
|
||||
|
||||
@@ -60,7 +60,7 @@ try:
|
||||
def kwargs_throw_exception(**c):
|
||||
return ()
|
||||
kwargs_exception_thrown = False
|
||||
except:
|
||||
except Exception:
|
||||
kwargs_exception_thrown = True
|
||||
|
||||
try:
|
||||
@@ -68,7 +68,7 @@ try:
|
||||
def varargs_and_kwargs_throw_exception(a, b="hi", *c):
|
||||
return "{} {} {}".format(a, b, c)
|
||||
varargs_and_kwargs_exception_thrown = False
|
||||
except:
|
||||
except Exception:
|
||||
varargs_and_kwargs_exception_thrown = True
|
||||
|
||||
# test throwing an exception
|
||||
|
||||
@@ -98,7 +98,7 @@ class Trial(object):
|
||||
self.agent.stop.remote()
|
||||
self.agent.__ray_terminate__.remote(
|
||||
self.agent._ray_actor_id.id())
|
||||
except:
|
||||
except Exception:
|
||||
print("Error stopping agent:", traceback.format_exc())
|
||||
self.status = Trial.ERROR
|
||||
finally:
|
||||
@@ -198,7 +198,7 @@ class Trial(object):
|
||||
else:
|
||||
try:
|
||||
ray.get(self.agent.restore.remote(path))
|
||||
except:
|
||||
except Exception:
|
||||
print("Error restoring agent:", traceback.format_exc())
|
||||
self.status = Trial.ERROR
|
||||
|
||||
|
||||
@@ -114,14 +114,14 @@ class TrialRunner(object):
|
||||
try:
|
||||
trial.start()
|
||||
self._running[trial.train_remote()] = trial
|
||||
except:
|
||||
except Exception:
|
||||
print("Error starting agent, retrying:", traceback.format_exc())
|
||||
time.sleep(2)
|
||||
trial.stop(error=True)
|
||||
try:
|
||||
trial.start()
|
||||
self._running[trial.train_remote()] = trial
|
||||
except:
|
||||
except Exception:
|
||||
print("Error starting agent, abort:", traceback.format_exc())
|
||||
trial.stop(error=True)
|
||||
# note that we don't return the resources, since they may
|
||||
@@ -143,7 +143,7 @@ class TrialRunner(object):
|
||||
if trial.should_checkpoint():
|
||||
trial.checkpoint()
|
||||
self._running[trial.train_remote()] = trial
|
||||
except:
|
||||
except Exception:
|
||||
print("Error processing event:", traceback.format_exc())
|
||||
if trial.status == Trial.RUNNING:
|
||||
self._stop_trial(trial, error=True)
|
||||
|
||||
@@ -1495,7 +1495,7 @@ def fetch_and_register_remote_function(key, worker=global_worker):
|
||||
|
||||
try:
|
||||
function = pickle.loads(serialized_function)
|
||||
except:
|
||||
except Exception:
|
||||
# If an exception was thrown when the remote function was imported, we
|
||||
# record the traceback and notify the scheduler of the failure.
|
||||
traceback_str = format_error_message(traceback.format_exc())
|
||||
@@ -1527,7 +1527,7 @@ def fetch_and_execute_function_to_run(key, worker=global_worker):
|
||||
function = pickle.loads(serialized_function)
|
||||
# Run the function.
|
||||
function({"counter": counter, "worker": worker})
|
||||
except:
|
||||
except Exception:
|
||||
# If an exception was thrown when the function was run, we record the
|
||||
# traceback and notify the scheduler of the failure.
|
||||
traceback_str = traceback.format_exc()
|
||||
|
||||
@@ -224,13 +224,13 @@ class DockerRunner(object):
|
||||
|
||||
try:
|
||||
self._stop_node(self.head_container_id)
|
||||
except:
|
||||
except Exception:
|
||||
success = False
|
||||
|
||||
for container_id in self.worker_container_ids:
|
||||
try:
|
||||
self._stop_node(container_id)
|
||||
except:
|
||||
except Exception:
|
||||
success = False
|
||||
|
||||
return success
|
||||
|
||||
+6
-6
@@ -213,8 +213,8 @@ class SerializationTest(unittest.TestCase):
|
||||
pass
|
||||
|
||||
# Make a list that contains itself.
|
||||
l = []
|
||||
l.append(l)
|
||||
lst = []
|
||||
lst.append(lst)
|
||||
# Make an object that contains itself as a field.
|
||||
a1 = ClassA()
|
||||
a1.field = a1
|
||||
@@ -227,7 +227,7 @@ class SerializationTest(unittest.TestCase):
|
||||
d1 = {}
|
||||
d1["key"] = d1
|
||||
# Create a list of recursive objects.
|
||||
recursive_objects = [l, a1, a2, a3, d1]
|
||||
recursive_objects = [lst, a1, a2, a3, d1]
|
||||
|
||||
# Check that exceptions are thrown when we serialize the recursive
|
||||
# objects.
|
||||
@@ -639,15 +639,15 @@ class APITest(unittest.TestCase):
|
||||
return x + 1
|
||||
|
||||
@ray.remote
|
||||
def l(x):
|
||||
def k2(x):
|
||||
return ray.get(k.remote(x))
|
||||
|
||||
@ray.remote
|
||||
def m(x):
|
||||
return ray.get(l.remote(x))
|
||||
return ray.get(k2.remote(x))
|
||||
|
||||
self.assertEqual(ray.get(k.remote(1)), 2)
|
||||
self.assertEqual(ray.get(l.remote(1)), 2)
|
||||
self.assertEqual(ray.get(k2.remote(1)), 2)
|
||||
self.assertEqual(ray.get(m.remote(1)), 2)
|
||||
|
||||
def testGetMultiple(self):
|
||||
|
||||
@@ -108,8 +108,8 @@ class TaskTests(unittest.TestCase):
|
||||
return 1
|
||||
|
||||
n = 10 ** 4 # TODO(pcm): replace by 10 ** 5 once this is faster.
|
||||
l = ray.get([f.remote() for _ in range(n)])
|
||||
self.assertEqual(l, n * [1])
|
||||
lst = ray.get([f.remote() for _ in range(n)])
|
||||
self.assertEqual(lst, n * [1])
|
||||
|
||||
self.assertTrue(ray.services.all_processes_alive())
|
||||
ray.worker.cleanup()
|
||||
|
||||
Reference in New Issue
Block a user