Lint Python files with Yapf (#1872)

This commit is contained in:
Philipp Moritz
2018-04-11 10:11:35 -07:00
committed by Robert Nishihara
parent a3ddde398c
commit 74162d1492
97 changed files with 3927 additions and 3139 deletions
@@ -6,19 +6,17 @@ import numpy as np
import ray
if __name__ == "__main__":
ray.init(num_workers=0)
A = np.ones(2 ** 31 + 1, dtype="int8")
A = np.ones(2**31 + 1, dtype="int8")
a = ray.put(A)
assert np.sum(ray.get(a)) == np.sum(A)
del A
del a
print("Successfully put A.")
B = {"hello": np.zeros(2 ** 30 + 1),
"world": np.ones(2 ** 30 + 1)}
B = {"hello": np.zeros(2**30 + 1), "world": np.ones(2**30 + 1)}
b = ray.put(B)
assert np.sum(ray.get(b)["hello"]) == np.sum(B["hello"])
assert np.sum(ray.get(b)["world"]) == np.sum(B["world"])
@@ -26,7 +24,7 @@ if __name__ == "__main__":
del b
print("Successfully put B.")
C = [np.ones(2 ** 30 + 1), 42.0 * np.ones(2 ** 30 + 1)]
C = [np.ones(2**30 + 1), 42.0 * np.ones(2**30 + 1)]
c = ray.put(C)
assert np.sum(ray.get(c)[0]) == np.sum(C[0])
assert np.sum(ray.get(c)[1]) == np.sum(C[1])
@@ -6,8 +6,7 @@ import os
import time
import ray
from ray.test.test_utils import (_wait_for_nodes_to_join,
_broadcast_event,
from ray.test.test_utils import (_wait_for_nodes_to_join, _broadcast_event,
_wait_for_event)
# This test should be run with 5 nodes, which have 0, 0, 5, 6, and 50 GPUs for
@@ -6,10 +6,8 @@ import os
import time
import ray
from ray.test.test_utils import (_wait_for_nodes_to_join,
_broadcast_event,
_wait_for_event,
wait_for_pid_to_exit)
from ray.test.test_utils import (_wait_for_nodes_to_join, _broadcast_event,
_wait_for_event, wait_for_pid_to_exit)
# This test should be run with 5 nodes, which have 0, 1, 2, 3, and 4 GPUs for a
# total of 10 GPUs. It should be run with 7 drivers. Drivers 2 through 6 must
@@ -28,9 +26,10 @@ def remote_function_event_name(driver_index, task_index):
@ray.remote
def long_running_task(driver_index, task_index, redis_address):
_broadcast_event(remote_function_event_name(driver_index, task_index),
redis_address,
data=(ray.services.get_node_ip_address(), os.getpid()))
_broadcast_event(
remote_function_event_name(driver_index, task_index),
redis_address,
data=(ray.services.get_node_ip_address(), os.getpid()))
# Loop forever.
while True:
time.sleep(100)
@@ -42,10 +41,10 @@ num_long_running_tasks_per_driver = 2
@ray.remote
class Actor0(object):
def __init__(self, driver_index, actor_index, redis_address):
_broadcast_event(actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(),
os.getpid()))
_broadcast_event(
actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(), os.getpid()))
assert len(ray.get_gpu_ids()) == 0
def check_ids(self):
@@ -60,10 +59,10 @@ class Actor0(object):
@ray.remote(num_gpus=1)
class Actor1(object):
def __init__(self, driver_index, actor_index, redis_address):
_broadcast_event(actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(),
os.getpid()))
_broadcast_event(
actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(), os.getpid()))
assert len(ray.get_gpu_ids()) == 1
def check_ids(self):
@@ -78,10 +77,10 @@ class Actor1(object):
@ray.remote(num_gpus=2)
class Actor2(object):
def __init__(self, driver_index, actor_index, redis_address):
_broadcast_event(actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(),
os.getpid()))
_broadcast_event(
actor_event_name(driver_index, actor_index),
redis_address,
data=(ray.services.get_node_ip_address(), os.getpid()))
assert len(ray.get_gpu_ids()) == 2
def check_ids(self):
@@ -110,11 +109,13 @@ def driver_0(redis_address, driver_index):
long_running_task.remote(driver_index, i, redis_address)
# Create some actors that require one GPU.
actors_one_gpu = [Actor1.remote(driver_index, i, redis_address)
for i in range(5)]
actors_one_gpu = [
Actor1.remote(driver_index, i, redis_address) for i in range(5)
]
# Create some actors that don't require any GPUs.
actors_no_gpus = [Actor0.remote(driver_index, 5 + i, redis_address)
for i in range(5)]
actors_no_gpus = [
Actor0.remote(driver_index, 5 + i, redis_address) for i in range(5)
]
for _ in range(1000):
ray.get([actor.check_ids.remote() for actor in actors_one_gpu])
@@ -145,14 +146,17 @@ def driver_1(redis_address, driver_index):
long_running_task.remote(driver_index, i, redis_address)
# Create an actor that requires two GPUs.
actors_two_gpus = [Actor2.remote(driver_index, i, redis_address)
for i in range(1)]
actors_two_gpus = [
Actor2.remote(driver_index, i, redis_address) for i in range(1)
]
# Create some actors that require one GPU.
actors_one_gpu = [Actor1.remote(driver_index, 1 + i, redis_address)
for i in range(3)]
actors_one_gpu = [
Actor1.remote(driver_index, 1 + i, redis_address) for i in range(3)
]
# Create some actors that don't require any GPUs.
actors_no_gpus = [Actor0.remote(driver_index, 1 + 3 + i, redis_address)
for i in range(5)]
actors_no_gpus = [
Actor0.remote(driver_index, 1 + 3 + i, redis_address) for i in range(5)
]
for _ in range(1000):
ray.get([actor.check_ids.remote() for actor in actors_two_gpus])
@@ -179,8 +183,9 @@ def cleanup_driver(redis_address, driver_index):
# We go ahead and create some actors that don't require any GPUs. We
# don't need to wait for the other drivers to finish. We call methods
# on these actors later to make sure they haven't been killed.
actors_no_gpus = [Actor0.remote(driver_index, i, redis_address)
for i in range(10)]
actors_no_gpus = [
Actor0.remote(driver_index, i, redis_address) for i in range(10)
]
_wait_for_event("DRIVER_0_DONE", redis_address)
_wait_for_event("DRIVER_1_DONE", redis_address)
@@ -206,13 +211,13 @@ def cleanup_driver(redis_address, driver_index):
# Create some actors that require two GPUs.
actors_two_gpus = []
for i in range(3):
actors_two_gpus.append(try_to_create_actor(Actor2, driver_index,
10 + i))
actors_two_gpus.append(
try_to_create_actor(Actor2, driver_index, 10 + i))
# Create some actors that require one GPU.
actors_one_gpu = []
for i in range(4):
actors_one_gpu.append(try_to_create_actor(Actor1, driver_index,
10 + 3 + i))
actors_one_gpu.append(
try_to_create_actor(Actor1, driver_index, 10 + 3 + i))
removed_workers = 0
@@ -233,14 +238,14 @@ def cleanup_driver(redis_address, driver_index):
# Make sure that the PIDs for the actors from driver 0 and driver 1 have
# been killed.
for i in range(10):
node_ip_address, pid = _wait_for_event(actor_event_name(0, i),
redis_address)
node_ip_address, pid = _wait_for_event(
actor_event_name(0, i), redis_address)
if node_ip_address == ray.services.get_node_ip_address():
wait_for_pid_to_exit(pid)
removed_workers += 1
for i in range(9):
node_ip_address, pid = _wait_for_event(actor_event_name(1, i),
redis_address)
node_ip_address, pid = _wait_for_event(
actor_event_name(1, i), redis_address)
if node_ip_address == ray.services.get_node_ip_address():
wait_for_pid_to_exit(pid)
removed_workers += 1
@@ -25,8 +25,9 @@ if __name__ == "__main__":
for i in range(num_attempts):
ip_addresses = ray.get([f.remote() for i in range(1000)])
distinct_addresses = set(ip_addresses)
counts = [ip_addresses.count(address) for address
in distinct_addresses]
counts = [
ip_addresses.count(address) for address in distinct_addresses
]
print("Counts are {}".format(counts))
if len(counts) == 5:
break