def test_protocol_version(init_and_serve): server_handle = init_and_serve ray = RayAPIStub() info1 = ray.connect("localhost:50051") local_py_version = ".".join([str(x) for x in list(sys.version_info)[:3]]) assert info1["protocol_version"] == CURRENT_PROTOCOL_VERSION, info1 ray.disconnect() time.sleep(1) def mock_connection_response(): return ray_client_pb2.ConnectionInfoResponse( num_clients=1, python_version=local_py_version, ray_version="", ray_commit="", protocol_version="2050-01-01", # from the future ) # inject mock connection function server_handle.data_servicer._build_connection_response = \ mock_connection_response ray = RayAPIStub() with pytest.raises(RuntimeError): _ = ray.connect("localhost:50051") ray = RayAPIStub() info3 = ray.connect("localhost:50051", ignore_version=True) assert info3["num_clients"] == 1, info3 ray.disconnect()
def test_python_version(): server_handle, _ = ray_client_server.init_and_serve("localhost:50051") try: ray = RayAPIStub() info1 = ray.connect("localhost:50051") assert info1["python_version"] == ".".join( [str(x) for x in list(sys.version_info)[:3]]) ray.disconnect() time.sleep(1) def mock_connection_response(): return ray_client_pb2.ConnectionInfoResponse( num_clients=1, python_version="2.7.12", ray_version="", ray_commit="", ) # inject mock connection function server_handle.data_servicer._build_connection_response = \ mock_connection_response ray = RayAPIStub() with pytest.raises(RuntimeError): _ = ray.connect("localhost:50051") ray = RayAPIStub() info3 = ray.connect("localhost:50051", ignore_version=True) assert info3["num_clients"] == 1, info3 ray.disconnect() finally: ray_client_server.shutdown_with_server(server_handle.grpc_server) time.sleep(2)
def test_idempotent_disconnect(init_and_serve): from ray.util.client import ray ray.disconnect() ray.disconnect() ray.connect("localhost:50051") ray.disconnect() ray.disconnect()
def test_ray_client(call_ray_start): from ray.util.client import ray ray.connect("localhost:20000") @ray.remote def f(): return "hello client" assert ray.get(f.remote()) == "hello client"
def test_basic_preregister(init_and_serve): from ray.util.client import ray ray.connect("localhost:50051") val = ray.get(hello_world.remote()) print(val) assert val >= 20 assert val <= 200 c = C.remote(3) x = c.double.remote() y = c.double.remote() ray.wait([x, y]) val = ray.get(c.get.remote()) assert val == 12 ray.disconnect()
def test_basic_preregister(): from ray.util.client import ray server, _ = ray_client_server.init_and_serve("localhost:50051") try: ray.connect("localhost:50051") val = ray.get(hello_world.remote()) print(val) assert val >= 20 assert val <= 200 c = C.remote(3) x = c.double.remote() y = c.double.remote() ray.wait([x, y]) val = ray.get(c.get.remote()) assert val == 12 finally: ray.disconnect() ray_client_server.shutdown_with_server(server) time.sleep(2)
def test_basic_preregister(init_and_serve): """Tests conversion of Ray actors and remote functions to client actors and client remote functions. Checks that the conversion works when disconnecting and reconnecting client sessions. """ from ray.util.client import ray for _ in range(2): ray.connect("localhost:50051") val = ray.get(hello_world.remote()) print(val) assert val >= 20 assert val <= 200 c = C.remote(3) x = c.double.remote() y = c.double.remote() ray.wait([x, y]) val = ray.get(c.get.remote()) assert val == 12 ray.disconnect()
def testObjStore(self): node_ip_address = "127.0.0.1" scheduler_address = ray.services.start_ray_local(num_objstores=2, num_workers=0, worker_path=None) ray.connect(node_ip_address, scheduler_address, mode=ray.SCRIPT_MODE) objstore_addresses = [objstore_info["address"] for objstore_info in ray.scheduler_info()["objstores"]] w1 = ray.worker.Worker() w2 = ray.worker.Worker() ray.reusables._cached_reusables = [] # This is a hack to make the test run. ray.connect(node_ip_address, scheduler_address, objstore_address=objstore_addresses[0], mode=ray.SCRIPT_MODE, worker=w1) ray.reusables._cached_reusables = [] # This is a hack to make the test run. ray.connect(node_ip_address, scheduler_address, objstore_address=objstore_addresses[1], mode=ray.SCRIPT_MODE, worker=w2) for cls in [Foo, Bar, Baz, Qux, SubQux, Exception, CustomError, Point, NamedTupleExample]: ray.register_class(cls) # putting and getting an object shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w1) result = ray.get(objectid, w1) assert_equal(result, data) # putting an object, shipping it to another worker, and getting it shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w1) result = ray.get(objectid, w2) assert_equal(result, data) # putting an object, shipping it to another worker, and getting it shouldn't change it for data in RAY_TEST_OBJECTS: objectid = ray.put(data, w2) result = ray.get(objectid, w1) assert_equal(result, data) # This test fails. See https://github.com/ray-project/ray/issues/159. # getting multiple times shouldn't matter # for data in [np.zeros([10, 20]), np.random.normal(size=[45, 25]), np.zeros([10, 20], dtype=np.dtype("float64")), np.zeros([10, 20], dtype=np.dtype("float32")), np.zeros([10, 20], dtype=np.dtype("int64")), np.zeros([10, 20], dtype=np.dtype("int32"))]: # objectid = worker.put(data, w1) # result = worker.get(objectid, w2) # result = worker.get(objectid, w2) # result = worker.get(objectid, w2) # assert_equal(result, data) # Getting a buffer after modifying it before it finishes should return updated buffer objectid = ray.libraylib.get_objectid(w1.handle) buf = ray.libraylib.allocate_buffer(w1.handle, objectid, 100) buf[0][0] = 1 ray.libraylib.finish_buffer(w1.handle, objectid, buf[1], 0) completedbuffer = ray.libraylib.get_buffer(w1.handle, objectid) self.assertEqual(completedbuffer[0][0], 1) # We started multiple drivers manually, so we will disconnect them manually. ray.disconnect(worker=w1) ray.disconnect(worker=w2) ray.worker.cleanup()