mirror of
https://github.com/wassname/ray.git
synced 2026-08-08 11:25:28 +08:00
Start working toward Python3 compatibility. (#117)
This commit is contained in:
committed by
Philipp Moritz
parent
3d083c8b58
commit
ddba1df802
+7
-3
@@ -1,3 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import ray
|
||||
import numpy as np
|
||||
@@ -130,7 +134,7 @@ class DistributedArrayTest(unittest.TestCase):
|
||||
|
||||
# test da.linalg.modified_lu
|
||||
def test_modified_lu(d1, d2):
|
||||
print "testing dist_modified_lu with d1 = " + str(d1) + ", d2 = " + str(d2)
|
||||
print("testing dist_modified_lu with d1 = " + str(d1) + ", d2 = " + str(d2))
|
||||
assert d1 >= d2
|
||||
k = min(d1, d2)
|
||||
m = ra.random.normal.remote([d1, d2])
|
||||
@@ -153,7 +157,7 @@ class DistributedArrayTest(unittest.TestCase):
|
||||
|
||||
# test dist_tsqr_hr
|
||||
def test_dist_tsqr_hr(d1, d2):
|
||||
print "testing dist_tsqr_hr with d1 = " + str(d1) + ", d2 = " + str(d2)
|
||||
print("testing dist_tsqr_hr with d1 = " + str(d1) + ", d2 = " + str(d2))
|
||||
a = da.random.normal.remote([d1, d2])
|
||||
y, t, y_top, r = da.linalg.tsqr_hr.remote(a)
|
||||
a_val = ray.get(da.assemble.remote(a))
|
||||
@@ -171,7 +175,7 @@ class DistributedArrayTest(unittest.TestCase):
|
||||
test_dist_tsqr_hr(d1, d2)
|
||||
|
||||
def test_dist_qr(d1, d2):
|
||||
print "testing qr with d1 = {}, and d2 = {}.".format(d1, d2)
|
||||
print("testing qr with d1 = {}, and d2 = {}.".format(d1, d2))
|
||||
a = da.random.normal.remote([d1, d2])
|
||||
K = min(d1, d2)
|
||||
q, r = da.linalg.qr.remote(a)
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import ray
|
||||
import time
|
||||
|
||||
import test_functions
|
||||
import ray.test.test_functions as test_functions
|
||||
|
||||
def wait_for_errors(error_type, num_errors, timeout=10):
|
||||
start_time = time.time()
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# This code reproduces a memory leak we had in the past
|
||||
|
||||
import os
|
||||
import numpy as np
|
||||
import ray
|
||||
|
||||
ray.init(start_ray_local=True, num_workers=1)
|
||||
|
||||
d = {"w": np.zeros(1000000)}
|
||||
|
||||
obj_capsule, contained_objectids = ray.libraylib.serialize_object(ray.worker.global_worker.handle, d)
|
||||
|
||||
while True:
|
||||
ray.libraylib.deserialize_object(ray.worker.global_worker.handle, obj_capsule)
|
||||
+25
-21
@@ -1,9 +1,13 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import ray
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
import test_functions
|
||||
import ray.test.test_functions as test_functions
|
||||
|
||||
class MicroBenchmarkTest(unittest.TestCase):
|
||||
|
||||
@@ -20,11 +24,11 @@ class MicroBenchmarkTest(unittest.TestCase):
|
||||
elapsed_times.append(end_time - start_time)
|
||||
elapsed_times = np.sort(elapsed_times)
|
||||
average_elapsed_time = sum(elapsed_times) / 1000
|
||||
print "Time required to submit an empty function call:"
|
||||
print " Average: {}".format(average_elapsed_time)
|
||||
print " 90th percentile: {}".format(elapsed_times[900])
|
||||
print " 99th percentile: {}".format(elapsed_times[990])
|
||||
print " worst: {}".format(elapsed_times[999])
|
||||
print("Time required to submit an empty function call:")
|
||||
print(" Average: {}".format(average_elapsed_time))
|
||||
print(" 90th percentile: {}".format(elapsed_times[900]))
|
||||
print(" 99th percentile: {}".format(elapsed_times[990]))
|
||||
print(" worst: {}".format(elapsed_times[999]))
|
||||
# average_elapsed_time should be about 0.00038
|
||||
|
||||
# measure the time required to submit a remote task to the scheduler (where the remote task returns one value)
|
||||
@@ -36,11 +40,11 @@ class MicroBenchmarkTest(unittest.TestCase):
|
||||
elapsed_times.append(end_time - start_time)
|
||||
elapsed_times = np.sort(elapsed_times)
|
||||
average_elapsed_time = sum(elapsed_times) / 1000
|
||||
print "Time required to submit a trivial function call:"
|
||||
print " Average: {}".format(average_elapsed_time)
|
||||
print " 90th percentile: {}".format(elapsed_times[900])
|
||||
print " 99th percentile: {}".format(elapsed_times[990])
|
||||
print " worst: {}".format(elapsed_times[999])
|
||||
print("Time required to submit a trivial function call:")
|
||||
print(" Average: {}".format(average_elapsed_time))
|
||||
print(" 90th percentile: {}".format(elapsed_times[900]))
|
||||
print(" 99th percentile: {}".format(elapsed_times[990]))
|
||||
print(" worst: {}".format(elapsed_times[999]))
|
||||
# average_elapsed_time should be about 0.001
|
||||
|
||||
# measure the time required to submit a remote task to the scheduler and get the result
|
||||
@@ -53,11 +57,11 @@ class MicroBenchmarkTest(unittest.TestCase):
|
||||
elapsed_times.append(end_time - start_time)
|
||||
elapsed_times = np.sort(elapsed_times)
|
||||
average_elapsed_time = sum(elapsed_times) / 1000
|
||||
print "Time required to submit a trivial function call and get the result:"
|
||||
print " Average: {}".format(average_elapsed_time)
|
||||
print " 90th percentile: {}".format(elapsed_times[900])
|
||||
print " 99th percentile: {}".format(elapsed_times[990])
|
||||
print " worst: {}".format(elapsed_times[999])
|
||||
print("Time required to submit a trivial function call and get the result:")
|
||||
print(" Average: {}".format(average_elapsed_time))
|
||||
print(" 90th percentile: {}".format(elapsed_times[900]))
|
||||
print(" 99th percentile: {}".format(elapsed_times[990]))
|
||||
print(" worst: {}".format(elapsed_times[999]))
|
||||
# average_elapsed_time should be about 0.0013
|
||||
|
||||
# measure the time required to do do a put
|
||||
@@ -69,11 +73,11 @@ class MicroBenchmarkTest(unittest.TestCase):
|
||||
elapsed_times.append(end_time - start_time)
|
||||
elapsed_times = np.sort(elapsed_times)
|
||||
average_elapsed_time = sum(elapsed_times) / 1000
|
||||
print "Time required to put an int:"
|
||||
print " Average: {}".format(average_elapsed_time)
|
||||
print " 90th percentile: {}".format(elapsed_times[900])
|
||||
print " 99th percentile: {}".format(elapsed_times[990])
|
||||
print " worst: {}".format(elapsed_times[999])
|
||||
print("Time required to put an int:")
|
||||
print(" Average: {}".format(average_elapsed_time))
|
||||
print(" 90th percentile: {}".format(elapsed_times[900]))
|
||||
print(" 99th percentile: {}".format(elapsed_times[990]))
|
||||
print(" worst: {}".format(elapsed_times[999]))
|
||||
# average_elapsed_time should be about 0.00087
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
@@ -8,7 +10,7 @@ import string
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
|
||||
import test_functions
|
||||
import ray.test.test_functions as test_functions
|
||||
import ray.array.remote as ra
|
||||
import ray.array.distributed as da
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import ray
|
||||
|
||||
import numpy as np
|
||||
|
||||
# Test simple functionality
|
||||
|
||||
@ray.remote(num_return_vals=2)
|
||||
def handle_int(a, b):
|
||||
return a + 1, b + 1
|
||||
|
||||
# Test timing
|
||||
|
||||
@ray.remote
|
||||
def empty_function():
|
||||
pass
|
||||
|
||||
@ray.remote
|
||||
def trivial_function():
|
||||
return 1
|
||||
|
||||
# Test keyword arguments
|
||||
|
||||
@ray.remote
|
||||
def keyword_fct1(a, b="hello"):
|
||||
return "{} {}".format(a, b)
|
||||
|
||||
@ray.remote
|
||||
def keyword_fct2(a="hello", b="world"):
|
||||
return "{} {}".format(a, b)
|
||||
|
||||
@ray.remote
|
||||
def keyword_fct3(a, b, c="hello", d="world"):
|
||||
return "{} {} {} {}".format(a, b, c, d)
|
||||
|
||||
# Test variable numbers of arguments
|
||||
|
||||
@ray.remote
|
||||
def varargs_fct1(*a):
|
||||
return " ".join(map(str, a))
|
||||
|
||||
@ray.remote
|
||||
def varargs_fct2(a, *b):
|
||||
return " ".join(map(str, b))
|
||||
|
||||
try:
|
||||
@ray.remote
|
||||
def kwargs_throw_exception(**c):
|
||||
return ()
|
||||
kwargs_exception_thrown = False
|
||||
except:
|
||||
kwargs_exception_thrown = True
|
||||
|
||||
try:
|
||||
@ray.remote
|
||||
def varargs_and_kwargs_throw_exception(a, b="hi", *c):
|
||||
return "{} {} {}".format(a, b, c)
|
||||
varargs_and_kwargs_exception_thrown = False
|
||||
except:
|
||||
varargs_and_kwargs_exception_thrown = True
|
||||
|
||||
# test throwing an exception
|
||||
|
||||
@ray.remote
|
||||
def throw_exception_fct1():
|
||||
raise Exception("Test function 1 intentionally failed.")
|
||||
|
||||
@ray.remote
|
||||
def throw_exception_fct2():
|
||||
raise Exception("Test function 2 intentionally failed.")
|
||||
|
||||
@ray.remote(num_return_vals=3)
|
||||
def throw_exception_fct3(x):
|
||||
raise Exception("Test function 3 intentionally failed.")
|
||||
|
||||
# test Python mode
|
||||
|
||||
@ray.remote
|
||||
def python_mode_f():
|
||||
return np.array([0, 0])
|
||||
|
||||
@ray.remote
|
||||
def python_mode_g(x):
|
||||
x[0] = 1
|
||||
return x
|
||||
|
||||
# test no return values
|
||||
|
||||
@ray.remote
|
||||
def no_op():
|
||||
pass
|
||||
|
||||
class TestClass(object):
|
||||
def __init__(self):
|
||||
self.a = 5
|
||||
|
||||
@ray.remote
|
||||
def test_unknown_type():
|
||||
return TestClass()
|
||||
Reference in New Issue
Block a user