Remove Ray environment variables from codebase. (#590)

This commit is contained in:
Robert Nishihara
2017-05-24 18:29:40 -07:00
committed by Philipp Moritz
parent c647dd5f6c
commit c5bc76193f
4 changed files with 13 additions and 569 deletions
-37
View File
@@ -101,43 +101,6 @@ def temporary_helper_function():
sys.path.pop(-1)
ray.worker.cleanup()
def testFailImportingEnvironmentVariable(self):
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
# This will throw an exception when the environment variable is imported on
# the workers.
def initializer():
if ray.worker.global_worker.mode == ray.WORKER_MODE:
raise Exception("The initializer failed.")
return 0
ray.env.foo = ray.EnvironmentVariable(initializer)
wait_for_errors(b"register_environment_variable", 2)
# Check that the error message is in the task info.
self.assertIn(b"The initializer failed.", ray.error_info()[0][b"message"])
ray.worker.cleanup()
def testFailReinitializingVariable(self):
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
def initializer():
return 0
def reinitializer(foo):
raise Exception("The reinitializer failed.")
ray.env.foo = ray.EnvironmentVariable(initializer, reinitializer)
@ray.remote
def use_foo():
ray.env.foo
use_foo.remote()
wait_for_errors(b"reinitialize_environment_variable", 1)
# Check that the error message is in the task info.
self.assertIn(b"The reinitializer failed.",
ray.error_info()[0][b"message"])
ray.worker.cleanup()
def testFailedFunctionToRun(self):
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
-191
View File
@@ -659,36 +659,6 @@ class APITest(unittest.TestCase):
x = f.remote(1)
ray.get([h.remote([x]), h.remote([x])])
def testCachingEnvironmentVariables(self):
# Test that we can define environment variables before the driver is
# connected.
def foo_initializer():
return 1
def bar_initializer():
return []
def bar_reinitializer(bar):
return []
ray.env.foo = ray.EnvironmentVariable(foo_initializer)
ray.env.bar = ray.EnvironmentVariable(bar_initializer, bar_reinitializer)
@ray.remote
def use_foo():
return ray.env.foo
@ray.remote
def use_bar():
ray.env.bar.append(1)
return ray.env.bar
self.init_ray()
self.assertEqual(ray.get(use_foo.remote()), 1)
self.assertEqual(ray.get(use_foo.remote()), 1)
self.assertEqual(ray.get(use_bar.remote()), [1])
self.assertEqual(ray.get(use_bar.remote()), [1])
def testCachingFunctionsToRun(self):
# Test that we export functions to run on all workers before the driver is
# connected.
@@ -914,167 +884,6 @@ class PythonModeTest(unittest.TestCase):
ray.worker.cleanup()
def testEnvironmentVariablesInPythonMode(self):
reload(test_functions)
ray.init(driver_mode=ray.PYTHON_MODE)
def l_init():
return []
def l_reinit(l):
return []
ray.env.l = ray.EnvironmentVariable(l_init, l_reinit)
@ray.remote
def use_l():
l = ray.env.l
l.append(1)
return l
# Get the local copy of the environment variable. This should be stateful.
l = ray.env.l
assert_equal(l, [])
# Make sure the remote function does what we expect.
assert_equal(ray.get(use_l.remote()), [1])
assert_equal(ray.get(use_l.remote()), [1])
# Make sure the local copy of the environment variable has not been
# mutated.
assert_equal(l, [])
l = ray.env.l
assert_equal(l, [])
# Make sure that running a remote function does not reset the state of the
# local copy of the environment variable.
l.append(2)
assert_equal(ray.get(use_l.remote()), [1])
assert_equal(l, [2])
ray.worker.cleanup()
class EnvironmentVariablesTest(unittest.TestCase):
def testEnvironmentVariables(self):
ray.init(num_workers=1)
# Test that we can add a variable to the key-value store.
def foo_initializer():
return 1
def foo_reinitializer(foo):
return foo
ray.env.foo = ray.EnvironmentVariable(foo_initializer, foo_reinitializer)
self.assertEqual(ray.env.foo, 1)
@ray.remote
def use_foo():
return ray.env.foo
self.assertEqual(ray.get(use_foo.remote()), 1)
self.assertEqual(ray.get(use_foo.remote()), 1)
self.assertEqual(ray.get(use_foo.remote()), 1)
# Test that we can add a variable to the key-value store, mutate it, and
# reset it.
def bar_initializer():
return [1, 2, 3]
ray.env.bar = ray.EnvironmentVariable(bar_initializer)
@ray.remote
def use_bar():
ray.env.bar.append(4)
return ray.env.bar
self.assertEqual(ray.get(use_bar.remote()), [1, 2, 3, 4])
self.assertEqual(ray.get(use_bar.remote()), [1, 2, 3, 4])
self.assertEqual(ray.get(use_bar.remote()), [1, 2, 3, 4])
# Test that we can use the reinitializer.
def baz_initializer():
return np.zeros([4])
def baz_reinitializer(baz):
for i in range(len(baz)):
baz[i] = 0
return baz
ray.env.baz = ray.EnvironmentVariable(baz_initializer, baz_reinitializer)
@ray.remote
def use_baz(i):
baz = ray.env.baz
baz[i] = 1
return baz
assert_equal(ray.get(use_baz.remote(0)), np.array([1, 0, 0, 0]))
assert_equal(ray.get(use_baz.remote(1)), np.array([0, 1, 0, 0]))
assert_equal(ray.get(use_baz.remote(2)), np.array([0, 0, 1, 0]))
assert_equal(ray.get(use_baz.remote(3)), np.array([0, 0, 0, 1]))
# Make sure the reinitializer is actually getting called. Note that this is
# not the correct usage of a reinitializer because it does not reset qux to
# its original state. This is just for testing.
def qux_initializer():
return 0
def qux_reinitializer(x):
return x + 1
ray.env.qux = ray.EnvironmentVariable(qux_initializer, qux_reinitializer)
@ray.remote
def use_qux():
return ray.env.qux
self.assertEqual(ray.get(use_qux.remote()), 0)
self.assertEqual(ray.get(use_qux.remote()), 1)
self.assertEqual(ray.get(use_qux.remote()), 2)
ray.worker.cleanup()
def testUsingEnvironmentVariablesOnDriver(self):
ray.init(num_workers=1)
# Test that we can add a variable to the key-value store.
def foo_initializer():
return []
def foo_reinitializer(foo):
return []
ray.env.foo = ray.EnvironmentVariable(foo_initializer, foo_reinitializer)
@ray.remote
def use_foo():
foo = ray.env.foo
foo.append(1)
return foo
# Check that running a remote function does not reset the enviroment
# variable on the driver.
foo = ray.env.foo
self.assertEqual(foo, [])
foo.append(2)
self.assertEqual(foo, [2])
foo.append(3)
self.assertEqual(foo, [2, 3])
self.assertEqual(ray.get(use_foo.remote()), [1])
self.assertEqual(ray.get(use_foo.remote()), [1])
self.assertEqual(ray.get(use_foo.remote()), [1])
# Check that the copy of foo on the driver has not changed.
self.assertEqual(foo, [2, 3])
foo = ray.env.foo
self.assertEqual(foo, [2, 3])
ray.worker.cleanup()
class UtilsTest(unittest.TestCase):