mirror of
https://github.com/wassname/ray.git
synced 2026-08-11 05:51:40 +08:00
Allow remote decorator to be used with no parentheses.
This commit is contained in:
@@ -76,7 +76,7 @@ class TaskStatusTest(unittest.TestCase):
|
||||
return reducer, ()
|
||||
def __call__(self):
|
||||
return
|
||||
ray.remote()(Foo())
|
||||
ray.remote(Foo())
|
||||
for _ in range(100): # Retry if we need to wait longer.
|
||||
if len(ray.task_info()["failed_remote_function_imports"]) >= 1:
|
||||
break
|
||||
@@ -112,7 +112,7 @@ class TaskStatusTest(unittest.TestCase):
|
||||
def reinitializer(foo):
|
||||
raise Exception("The reinitializer failed.")
|
||||
ray.reusables.foo = ray.Reusable(initializer, reinitializer)
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_foo():
|
||||
ray.reusables.foo
|
||||
use_foo.remote()
|
||||
|
||||
+21
-21
@@ -262,42 +262,42 @@ class APITest(unittest.TestCase):
|
||||
ray.init(start_ray_local=True, num_workers=2)
|
||||
|
||||
# Test that we can define a remote function in the shell.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f(x):
|
||||
return x + 1
|
||||
self.assertEqual(ray.get(f.remote(0)), 1)
|
||||
|
||||
# Test that we can redefine the remote function.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f(x):
|
||||
return x + 10
|
||||
self.assertEqual(ray.get(f.remote(0)), 10)
|
||||
|
||||
# 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)}]
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def g():
|
||||
return data
|
||||
ray.get(g.remote())
|
||||
|
||||
# Test that we can close over modules.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def h():
|
||||
return np.zeros([3, 5])
|
||||
assert_equal(ray.get(h.remote()), np.zeros([3, 5]))
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def j():
|
||||
return time.time()
|
||||
ray.get(j.remote())
|
||||
|
||||
# Test that we can define remote functions that call other remote functions.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def k(x):
|
||||
return x + 1
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def l(x):
|
||||
return k.remote(x)
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def m(x):
|
||||
return ray.get(l.remote(x))
|
||||
self.assertEqual(ray.get(k.remote(1)), 2)
|
||||
@@ -309,7 +309,7 @@ class APITest(unittest.TestCase):
|
||||
def testSelect(self):
|
||||
ray.init(start_ray_local=True, num_workers=4)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f(delay):
|
||||
time.sleep(delay)
|
||||
return 1
|
||||
@@ -345,10 +345,10 @@ class APITest(unittest.TestCase):
|
||||
ray.reusables.foo = ray.Reusable(foo_initializer)
|
||||
ray.reusables.bar = ray.Reusable(bar_initializer, bar_reinitializer)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_foo():
|
||||
return ray.reusables.foo
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_bar():
|
||||
ray.reusables.bar.append(1)
|
||||
return ray.reusables.bar
|
||||
@@ -368,7 +368,7 @@ class APITest(unittest.TestCase):
|
||||
def f():
|
||||
sys.path.append("fake_directory")
|
||||
ray.worker.global_worker.run_function_on_all_workers(f)
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def get_path():
|
||||
return sys.path
|
||||
self.assertEqual("fake_directory", ray.get(get_path.remote())[-1])
|
||||
@@ -509,7 +509,7 @@ class PythonCExtensionTest(unittest.TestCase):
|
||||
ray.init(start_ray_local=True, num_workers=1)
|
||||
|
||||
# Make sure that we aren't accidentally messing up Python's reference counts.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f():
|
||||
return sys.getrefcount(None)
|
||||
first_count = ray.get(f.remote())
|
||||
@@ -522,7 +522,7 @@ class PythonCExtensionTest(unittest.TestCase):
|
||||
ray.init(start_ray_local=True, num_workers=1)
|
||||
|
||||
# Make sure that we aren't accidentally messing up Python's reference counts.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f():
|
||||
return sys.getrefcount(True)
|
||||
first_count = ray.get(f.remote())
|
||||
@@ -535,7 +535,7 @@ class PythonCExtensionTest(unittest.TestCase):
|
||||
ray.init(start_ray_local=True, num_workers=1)
|
||||
|
||||
# Make sure that we aren't accidentally messing up Python's reference counts.
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f():
|
||||
return sys.getrefcount(False)
|
||||
first_count = ray.get(f.remote())
|
||||
@@ -559,7 +559,7 @@ class ReusablesTest(unittest.TestCase):
|
||||
ray.reusables.foo = ray.Reusable(foo_initializer, foo_reinitializer)
|
||||
self.assertEqual(ray.reusables.foo, 1)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_foo():
|
||||
return ray.reusables.foo
|
||||
self.assertEqual(ray.get(use_foo.remote()), 1)
|
||||
@@ -573,7 +573,7 @@ class ReusablesTest(unittest.TestCase):
|
||||
|
||||
ray.reusables.bar = ray.Reusable(bar_initializer)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_bar():
|
||||
ray.reusables.bar.append(4)
|
||||
return ray.reusables.bar
|
||||
@@ -592,7 +592,7 @@ class ReusablesTest(unittest.TestCase):
|
||||
|
||||
ray.reusables.baz = ray.Reusable(baz_initializer, baz_reinitializer)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_baz(i):
|
||||
baz = ray.reusables.baz
|
||||
baz[i] = 1
|
||||
@@ -613,7 +613,7 @@ class ReusablesTest(unittest.TestCase):
|
||||
|
||||
ray.reusables.qux = ray.Reusable(qux_initializer, qux_reinitializer)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def use_qux():
|
||||
return ray.reusables.qux
|
||||
self.assertEqual(ray.get(use_qux.remote()), 0)
|
||||
@@ -634,7 +634,7 @@ class ClusterAttachingTest(unittest.TestCase):
|
||||
|
||||
ray.init(node_ip_address=node_ip_address, scheduler_address=scheduler_address)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f(x):
|
||||
return x + 1
|
||||
self.assertEqual(ray.get(f.remote(0)), 1)
|
||||
@@ -653,7 +653,7 @@ class ClusterAttachingTest(unittest.TestCase):
|
||||
|
||||
ray.init(node_ip_address=node_ip_address, scheduler_address=scheduler_address)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f(x):
|
||||
return x + 1
|
||||
self.assertEqual(ray.get(f.remote(0)), 1)
|
||||
|
||||
+18
-18
@@ -10,54 +10,54 @@ def handle_int(a, b):
|
||||
|
||||
# Test aliasing
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def test_alias_f():
|
||||
return np.ones([3, 4, 5])
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def test_alias_g():
|
||||
return test_alias_f.remote()
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def test_alias_h():
|
||||
return test_alias_g.remote()
|
||||
|
||||
# Test timing
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def empty_function():
|
||||
pass
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def trivial_function():
|
||||
return 1
|
||||
|
||||
# Test keyword arguments
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def keyword_fct1(a, b="hello"):
|
||||
return "{} {}".format(a, b)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def keyword_fct2(a="hello", b="world"):
|
||||
return "{} {}".format(a, b)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def keyword_fct3(a, b, c="hello", d="world"):
|
||||
return "{} {} {} {}".format(a, b, c, d)
|
||||
|
||||
# Test variable numbers of arguments
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def varargs_fct1(*a):
|
||||
return " ".join(map(str, a))
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def varargs_fct2(a, *b):
|
||||
return " ".join(map(str, b))
|
||||
|
||||
try:
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def kwargs_throw_exception(**c):
|
||||
return ()
|
||||
kwargs_exception_thrown = False
|
||||
@@ -65,7 +65,7 @@ except:
|
||||
kwargs_exception_thrown = True
|
||||
|
||||
try:
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def varargs_and_kwargs_throw_exception(a, b="hi", *c):
|
||||
return "{} {} {}".format(a, b, c)
|
||||
varargs_and_kwargs_exception_thrown = False
|
||||
@@ -74,11 +74,11 @@ except:
|
||||
|
||||
# test throwing an exception
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def throw_exception_fct1():
|
||||
raise Exception("Test function 1 intentionally failed.")
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def throw_exception_fct2():
|
||||
raise Exception("Test function 2 intentionally failed.")
|
||||
|
||||
@@ -88,18 +88,18 @@ def throw_exception_fct3(x):
|
||||
|
||||
# test Python mode
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def python_mode_f():
|
||||
return np.array([0, 0])
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def python_mode_g(x):
|
||||
x[0] = 1
|
||||
return x
|
||||
|
||||
# test no return values
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def no_op():
|
||||
pass
|
||||
|
||||
@@ -107,6 +107,6 @@ class TestClass(object):
|
||||
def __init__(self):
|
||||
self.a = 5
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def test_unknown_type():
|
||||
return TestClass()
|
||||
|
||||
Reference in New Issue
Block a user