mirror of
https://github.com/wassname/ray.git
synced 2026-08-13 12:30:18 +08:00
Python 3 compatibility. (#121)
* Make common module Python 3 compatible. * Make plasma module Python 3 compatible. * Make photon module Python 3 compatible. * Make numbuf module Python 3 compatible. * Remaining changes for Python 3 compatibility. * Test Python 3 in Travis. * Fixes.
This commit is contained in:
@@ -7,6 +7,10 @@ import ray
|
||||
import numpy as np
|
||||
import time
|
||||
from numpy.testing import assert_equal, assert_almost_equal
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
from importlib import reload
|
||||
|
||||
import ray.array.remote as ra
|
||||
import ray.array.distributed as da
|
||||
|
||||
+22
-18
@@ -4,8 +4,12 @@ from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import ray
|
||||
import sys
|
||||
import time
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
from importlib import reload
|
||||
|
||||
import ray.test.test_functions as test_functions
|
||||
|
||||
def wait_for_errors(error_type, num_errors, timeout=10):
|
||||
@@ -23,9 +27,9 @@ class FailureTest(unittest.TestCase):
|
||||
ray.init(start_ray_local=True, num_workers=1, driver_mode=ray.SILENT_MODE)
|
||||
|
||||
test_functions.test_unknown_type.remote()
|
||||
wait_for_errors("TaskError", 1)
|
||||
wait_for_errors(b"TaskError", 1)
|
||||
error_info = ray.error_info()
|
||||
self.assertEqual(len(error_info["TaskError"]), 1)
|
||||
self.assertEqual(len(error_info[b"TaskError"]), 1)
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
@@ -57,17 +61,17 @@ class TaskStatusTest(unittest.TestCase):
|
||||
|
||||
test_functions.throw_exception_fct1.remote()
|
||||
test_functions.throw_exception_fct1.remote()
|
||||
wait_for_errors("TaskError", 2)
|
||||
wait_for_errors(b"TaskError", 2)
|
||||
result = ray.error_info()
|
||||
self.assertEqual(len(result["TaskError"]), 2)
|
||||
for task in result["TaskError"]:
|
||||
self.assertTrue("Test function 1 intentionally failed." in task.get("message"))
|
||||
self.assertEqual(len(result[b"TaskError"]), 2)
|
||||
for task in result[b"TaskError"]:
|
||||
self.assertTrue(b"Test function 1 intentionally failed." in task.get(b"message"))
|
||||
|
||||
x = test_functions.throw_exception_fct2.remote()
|
||||
try:
|
||||
ray.get(x)
|
||||
except Exception as e:
|
||||
self.assertTrue("Test function 2 intentionally failed."in str(e))
|
||||
self.assertTrue("Test function 2 intentionally failed." in str(e))
|
||||
else:
|
||||
self.assertTrue(False) # ray.get should throw an exception
|
||||
|
||||
@@ -76,7 +80,7 @@ class TaskStatusTest(unittest.TestCase):
|
||||
try:
|
||||
ray.get(ref)
|
||||
except Exception as e:
|
||||
self.assertTrue("Test function 3 intentionally failed."in str(e))
|
||||
self.assertTrue("Test function 3 intentionally failed." in str(e))
|
||||
else:
|
||||
self.assertTrue(False) # ray.get should throw an exception
|
||||
|
||||
@@ -100,8 +104,8 @@ class TaskStatusTest(unittest.TestCase):
|
||||
def __call__(self):
|
||||
return
|
||||
ray.remote(Foo())
|
||||
wait_for_errors("RemoteFunctionImportError", 1)
|
||||
self.assertTrue("There is a problem here." in ray.error_info()["RemoteFunctionImportError"][0]["message"])
|
||||
wait_for_errors(b"RemoteFunctionImportError", 1)
|
||||
self.assertTrue(b"There is a problem here." in ray.error_info()[b"RemoteFunctionImportError"][0][b"message"])
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
@@ -115,9 +119,9 @@ class TaskStatusTest(unittest.TestCase):
|
||||
raise Exception("The initializer failed.")
|
||||
return 0
|
||||
ray.reusables.foo = ray.Reusable(initializer)
|
||||
wait_for_errors("ReusableVariableImportError", 1)
|
||||
wait_for_errors(b"ReusableVariableImportError", 1)
|
||||
# Check that the error message is in the task info.
|
||||
self.assertTrue("The initializer failed." in ray.error_info()["ReusableVariableImportError"][0]["message"])
|
||||
self.assertTrue(b"The initializer failed." in ray.error_info()[b"ReusableVariableImportError"][0][b"message"])
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
@@ -133,9 +137,9 @@ class TaskStatusTest(unittest.TestCase):
|
||||
def use_foo():
|
||||
ray.reusables.foo
|
||||
use_foo.remote()
|
||||
wait_for_errors("ReusableVariableReinitializeError", 1)
|
||||
wait_for_errors(b"ReusableVariableReinitializeError", 1)
|
||||
# Check that the error message is in the task info.
|
||||
self.assertTrue("The reinitializer failed." in ray.error_info()["ReusableVariableReinitializeError"][0]["message"])
|
||||
self.assertTrue(b"The reinitializer failed." in ray.error_info()[b"ReusableVariableReinitializeError"][0][b"message"])
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
@@ -146,11 +150,11 @@ class TaskStatusTest(unittest.TestCase):
|
||||
if ray.worker.global_worker.mode == ray.WORKER_MODE:
|
||||
raise Exception("Function to run failed.")
|
||||
ray.worker.global_worker.run_function_on_all_workers(f)
|
||||
wait_for_errors("FunctionToRunError", 2)
|
||||
wait_for_errors(b"FunctionToRunError", 2)
|
||||
# Check that the error message is in the task info.
|
||||
self.assertEqual(len(ray.error_info()["FunctionToRunError"]), 2)
|
||||
self.assertTrue("Function to run failed." in ray.error_info()["FunctionToRunError"][0]["message"])
|
||||
self.assertTrue("Function to run failed." in ray.error_info()["FunctionToRunError"][1]["message"])
|
||||
self.assertEqual(len(ray.error_info()[b"FunctionToRunError"]), 2)
|
||||
self.assertTrue(b"Function to run failed." in ray.error_info()[b"FunctionToRunError"][0][b"message"])
|
||||
self.assertTrue(b"Function to run failed." in ray.error_info()[b"FunctionToRunError"][1][b"message"])
|
||||
|
||||
ray.worker.cleanup()
|
||||
|
||||
|
||||
@@ -4,9 +4,13 @@ from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import ray
|
||||
import sys
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
from importlib import reload
|
||||
|
||||
import ray.test.test_functions as test_functions
|
||||
|
||||
class MicroBenchmarkTest(unittest.TestCase):
|
||||
|
||||
+17
-6
@@ -10,6 +10,9 @@ import string
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
from importlib import reload
|
||||
|
||||
import ray.test.test_functions as test_functions
|
||||
import ray.array.remote as ra
|
||||
import ray.array.distributed as da
|
||||
@@ -24,7 +27,7 @@ def assert_equal(obj1, obj2):
|
||||
np.testing.assert_equal(obj1, obj2)
|
||||
elif hasattr(obj1, "__dict__") and hasattr(obj2, "__dict__"):
|
||||
special_keys = ["_pytype_"]
|
||||
assert set(obj1.__dict__.keys() + special_keys) == set(obj2.__dict__.keys() + special_keys), "Objects {} and {} are different.".format(obj1, obj2)
|
||||
assert set(list(obj1.__dict__.keys()) + special_keys) == set(list(obj2.__dict__.keys()) + special_keys), "Objects {} and {} are different.".format(obj1, obj2)
|
||||
for key in obj1.__dict__.keys():
|
||||
if key not in special_keys:
|
||||
assert_equal(obj1.__dict__[key], obj2.__dict__[key])
|
||||
@@ -40,17 +43,25 @@ def assert_equal(obj1, obj2):
|
||||
assert len(obj1) == len(obj2), "Objects {} and {} are tuples with different lengths.".format(obj1, obj2)
|
||||
for i in range(len(obj1)):
|
||||
assert_equal(obj1[i], obj2[i])
|
||||
elif ray.serialization.is_named_tuple(type(obj1)) or ray.serialization.is_named_tuple(type(obj2)):
|
||||
assert len(obj1) == len(obj2), "Objects {} and {} are named tuples with different lengths.".format(obj1, obj2)
|
||||
for i in range(len(obj1)):
|
||||
assert_equal(obj1[i], obj2[i])
|
||||
else:
|
||||
assert obj1 == obj2, "Objects {} and {} are different.".format(obj1, obj2)
|
||||
|
||||
PRIMITIVE_OBJECTS = [0, 0.0, 0.9, 0L, 1L << 62, "a", string.printable, "\u262F",
|
||||
if sys.version_info >= (3, 0):
|
||||
long_extras = [0, np.array([["hi", u"hi"], [1.3, 1]])]
|
||||
else:
|
||||
long_extras = [long(0), np.array([["hi", u"hi"], [1.3, long(1)]])]
|
||||
|
||||
PRIMITIVE_OBJECTS = [0, 0.0, 0.9, 1 << 62, "a", string.printable, "\u262F",
|
||||
u"hello world", u"\xff\xfe\x9c\x001\x000\x00", None, True,
|
||||
False, [], (), {}, np.int8(3), np.int32(4), np.int64(5),
|
||||
np.uint8(3), np.uint32(4), np.uint64(5), np.float32(1.9),
|
||||
np.float64(1.9), np.zeros([100, 100]),
|
||||
np.random.normal(size=[100, 100]), np.array(["hi", 3]),
|
||||
np.array(["hi", 3], dtype=object),
|
||||
np.array([["hi", u"hi"], [1.3, 1L]])]
|
||||
np.array(["hi", 3], dtype=object)] + long_extras
|
||||
|
||||
COMPLEX_OBJECTS = [[[[[[[[[[[[[]]]]]]]]]]]],
|
||||
{"obj{}".format(i): np.random.normal(size=[100, 100]) for i in range(10)},
|
||||
@@ -299,7 +310,7 @@ class APITest(unittest.TestCase):
|
||||
print("Still using old definition of f, trying again.")
|
||||
|
||||
# Test that we can close over plain old data.
|
||||
data = [np.zeros([3, 5]), (1, 2, "a"), [0.0, 1.0, 2L], 2L, {"a": np.zeros(3)}]
|
||||
data = [np.zeros([3, 5]), (1, 2, "a"), [0.0, 1.0, 1 << 62], 1 << 60, {"a": np.zeros(3)}]
|
||||
@ray.remote
|
||||
def g():
|
||||
return data
|
||||
@@ -334,7 +345,7 @@ class APITest(unittest.TestCase):
|
||||
def testGetMultiple(self):
|
||||
ray.init(start_ray_local=True, num_workers=0)
|
||||
object_ids = [ray.put(i) for i in range(10)]
|
||||
self.assertEqual(ray.get(object_ids), range(10))
|
||||
self.assertEqual(ray.get(object_ids), list(range(10)))
|
||||
ray.worker.cleanup()
|
||||
|
||||
def testWait(self):
|
||||
|
||||
Reference in New Issue
Block a user