renaming project, halo -> ray (#95)

This commit is contained in:
Robert Nishihara
2016-06-10 14:12:15 -07:00
committed by Philipp Moritz
parent 44ae1788ee
commit 4cc024ae36
41 changed files with 453 additions and 481 deletions
@@ -1,3 +1,3 @@
import libhalolib as lib
import libraylib as lib
import serialization
from worker import scheduler_info, register_module, connect, disconnect, pull, push, remote
@@ -1,7 +1,7 @@
from typing import List
import numpy as np
import halo.arrays.remote as ra
import halo
import ray.arrays.remote as ra
import ray
__all__ = ["BLOCK_SIZE", "DistArray", "assemble", "zeros", "ones", "copy",
"eye", "triu", "tril", "blockwise_dot", "dot", "transpose", "add", "subtract", "numpy_to_dist", "subblocks"]
@@ -55,13 +55,13 @@ class DistArray(object):
def assemble(self):
"""Assemble an array on this node from a distributed array object reference."""
first_block = halo.pull(self.objrefs[(0,) * self.ndim])
first_block = ray.pull(self.objrefs[(0,) * self.ndim])
dtype = first_block.dtype
result = np.zeros(self.shape, dtype=dtype)
for index in np.ndindex(*self.num_blocks):
lower = DistArray.compute_block_lower(index, self.shape)
upper = DistArray.compute_block_upper(index, self.shape)
result[[slice(l, u) for (l, u) in zip(lower, upper)]] = halo.pull(self.objrefs[index])
result[[slice(l, u) for (l, u) in zip(lower, upper)]] = ray.pull(self.objrefs[index])
return result
def __getitem__(self, sliced):
@@ -69,42 +69,42 @@ class DistArray(object):
a = self.assemble()
return a[sliced]
@halo.remote([DistArray], [np.ndarray])
@ray.remote([DistArray], [np.ndarray])
def assemble(a):
return a.assemble()
# TODO(rkn): what should we call this method
@halo.remote([np.ndarray], [DistArray])
@ray.remote([np.ndarray], [DistArray])
def numpy_to_dist(a):
result = DistArray(a.shape)
for index in np.ndindex(*result.num_blocks):
lower = DistArray.compute_block_lower(index, a.shape)
upper = DistArray.compute_block_upper(index, a.shape)
result.objrefs[index] = halo.push(a[[slice(l, u) for (l, u) in zip(lower, upper)]])
result.objrefs[index] = ray.push(a[[slice(l, u) for (l, u) in zip(lower, upper)]])
return result
@halo.remote([List[int], str], [DistArray])
@ray.remote([List[int], str], [DistArray])
def zeros(shape, dtype_name="float"):
result = DistArray(shape)
for index in np.ndindex(*result.num_blocks):
result.objrefs[index] = ra.zeros(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
return result
@halo.remote([List[int], str], [DistArray])
@ray.remote([List[int], str], [DistArray])
def ones(shape, dtype_name="float"):
result = DistArray(shape)
for index in np.ndindex(*result.num_blocks):
result.objrefs[index] = ra.ones(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
return result
@halo.remote([DistArray], [DistArray])
@ray.remote([DistArray], [DistArray])
def copy(a):
result = DistArray(a.shape)
for index in np.ndindex(*result.num_blocks):
result.objrefs[index] = a.objrefs[index] # We don't need to actually copy the objects because cluster-level objects are assumed to be immutable.
return result
@halo.remote([int, int, str], [DistArray])
@ray.remote([int, int, str], [DistArray])
def eye(dim1, dim2=-1, dtype_name="float"):
dim2 = dim1 if dim2 == -1 else dim2
shape = [dim1, dim2]
@@ -117,7 +117,7 @@ def eye(dim1, dim2=-1, dtype_name="float"):
result.objrefs[i, j] = ra.zeros(block_shape, dtype_name=dtype_name)
return result
@halo.remote([DistArray], [DistArray])
@ray.remote([DistArray], [DistArray])
def triu(a):
if a.ndim != 2:
raise Exception("Input must have 2 dimensions, but a.ndim is " + str(a.ndim))
@@ -131,7 +131,7 @@ def triu(a):
result.objrefs[i, j] = ra.zeros_like(a.objrefs[i, j])
return result
@halo.remote([DistArray], [DistArray])
@ray.remote([DistArray], [DistArray])
def tril(a):
if a.ndim != 2:
raise Exception("Input must have 2 dimensions, but a.ndim is " + str(a.ndim))
@@ -145,7 +145,7 @@ def tril(a):
result.objrefs[i, j] = ra.zeros_like(a.objrefs[i, j])
return result
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def blockwise_dot(*matrices):
n = len(matrices)
if n % 2 != 0:
@@ -156,7 +156,7 @@ def blockwise_dot(*matrices):
result += np.dot(matrices[i], matrices[n / 2 + i])
return result
@halo.remote([DistArray, DistArray], [DistArray])
@ray.remote([DistArray, DistArray], [DistArray])
def dot(a, b):
if a.ndim != 2:
raise Exception("dot expects its arguments to be 2-dimensional, but a.ndim = {}.".format(a.ndim))
@@ -171,7 +171,7 @@ def dot(a, b):
result.objrefs[i, j] = blockwise_dot(*args)
return result
@halo.remote([DistArray, List[int]], [DistArray])
@ray.remote([DistArray, List[int]], [DistArray])
def subblocks(a, *ranges):
"""
This function produces a distributed array from a subset of the blocks in the `a`. The result and `a` will have the same number of dimensions.For example,
@@ -202,7 +202,7 @@ def subblocks(a, *ranges):
result.objrefs[index] = a.objrefs[tuple([ranges[i][index[i]] for i in range(a.ndim)])]
return result
@halo.remote([DistArray], [DistArray])
@ray.remote([DistArray], [DistArray])
def transpose(a):
if a.ndim != 2:
raise Exception("transpose expects its argument to be 2-dimensional, but a.ndim = {}, a.shape = {}.".format(a.ndim, a.shape))
@@ -213,7 +213,7 @@ def transpose(a):
return result
# TODO(rkn): support broadcasting?
@halo.remote([DistArray, DistArray], [DistArray])
@ray.remote([DistArray, DistArray], [DistArray])
def add(x1, x2):
if x1.shape != x2.shape:
raise Exception("add expects arguments `x1` and `x2` to have the same shape, but x1.shape = {}, and x2.shape = {}.".format(x1.shape, x2.shape))
@@ -223,7 +223,7 @@ def add(x1, x2):
return result
# TODO(rkn): support broadcasting?
@halo.remote([DistArray, DistArray], [DistArray])
@ray.remote([DistArray, DistArray], [DistArray])
def subtract(x1, x2):
if x1.shape != x2.shape:
raise Exception("subtract expects arguments `x1` and `x2` to have the same shape, but x1.shape = {}, and x2.shape = {}.".format(x1.shape, x2.shape))
@@ -1,14 +1,14 @@
from typing import List
import numpy as np
import halo.arrays.remote as ra
import halo
import ray.arrays.remote as ra
import ray
from core import *
__all__ = ["tsqr", "modified_lu", "tsqr_hr", "qr"]
@halo.remote([DistArray], [DistArray, np.ndarray])
@ray.remote([DistArray], [DistArray, np.ndarray])
def tsqr(a):
"""
arguments:
@@ -17,10 +17,10 @@ def tsqr(a):
a.shape == (M, N)
K == min(M, N)
return values:
q: DistArray, if q_full = halo.context.pull(DistArray, q).assemble(), then
q: DistArray, if q_full = ray.context.pull(DistArray, q).assemble(), then
q_full.shape == (M, K)
np.allclose(np.dot(q_full.T, q_full), np.eye(K)) == True
r: np.ndarray, if r_val = halo.context.pull(np.ndarray, r), then
r: np.ndarray, if r_val = ray.context.pull(np.ndarray, r), then
r_val.shape == (K, N)
np.allclose(r, np.triu(r)) == True
"""
@@ -80,7 +80,7 @@ def tsqr(a):
return q_result, r
# TODO(rkn): This is unoptimized, we really want a block version of this.
@halo.remote([DistArray], [DistArray, np.ndarray, np.ndarray])
@ray.remote([DistArray], [DistArray, np.ndarray, np.ndarray])
def modified_lu(q):
"""
Algorithm 5 from http://www.eecs.berkeley.edu/Pubs/TechRpts/2013/EECS-2013-175.pdf
@@ -108,39 +108,39 @@ def modified_lu(q):
for i in range(b):
L[i, i] = 1
U = np.triu(q_work)[:b, :]
return numpy_to_dist(halo.push(L)), U, S # TODO(rkn): get rid of push and pull
return numpy_to_dist(ray.push(L)), U, S # TODO(rkn): get rid of push and pull
@halo.remote([np.ndarray, np.ndarray, np.ndarray, int], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray, np.ndarray, np.ndarray, int], [np.ndarray, np.ndarray])
def tsqr_hr_helper1(u, s, y_top_block, b):
y_top = y_top_block[:b, :b]
s_full = np.diag(s)
t = -1 * np.dot(u, np.dot(s_full, np.linalg.inv(y_top).T))
return t, y_top
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def tsqr_hr_helper2(s, r_temp):
s_full = np.diag(s)
return np.dot(s_full, r_temp)
@halo.remote([DistArray], [DistArray, np.ndarray, np.ndarray, np.ndarray])
@ray.remote([DistArray], [DistArray, np.ndarray, np.ndarray, np.ndarray])
def tsqr_hr(a):
"""Algorithm 6 from http://www.eecs.berkeley.edu/Pubs/TechRpts/2013/EECS-2013-175.pdf"""
q, r_temp = tsqr(a)
y, u, s = modified_lu(q)
y_blocked = halo.pull(y)
y_blocked = ray.pull(y)
t, y_top = tsqr_hr_helper1(u, s, y_blocked.objrefs[0, 0], a.shape[1])
r = tsqr_hr_helper2(s, r_temp)
return y, t, y_top, r
@halo.remote([np.ndarray, np.ndarray, np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray, np.ndarray, np.ndarray], [np.ndarray])
def qr_helper1(a_rc, y_ri, t, W_c):
return a_rc - np.dot(y_ri, np.dot(t.T, W_c))
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def qr_helper2(y_ri, a_rc):
return np.dot(y_ri.T, a_rc)
@halo.remote([DistArray], [DistArray, DistArray])
@ray.remote([DistArray], [DistArray, DistArray])
def qr(a):
"""Algorithm 7 from http://www.eecs.berkeley.edu/Pubs/TechRpts/2013/EECS-2013-175.pdf"""
m, n = a.shape[0], a.shape[1]
@@ -150,21 +150,21 @@ def qr(a):
a_work = DistArray()
a_work.construct(a.shape, np.copy(a.objrefs))
result_dtype = np.linalg.qr(halo.pull(a.objrefs[0, 0]))[0].dtype.name
r_res = halo.pull(zeros([k, n], result_dtype)) # TODO(rkn): It would be preferable not to pull this right after creating it.
y_res = halo.pull(zeros([m, k], result_dtype)) # TODO(rkn): It would be preferable not to pull this right after creating it.
result_dtype = np.linalg.qr(ray.pull(a.objrefs[0, 0]))[0].dtype.name
r_res = ray.pull(zeros([k, n], result_dtype)) # TODO(rkn): It would be preferable not to pull this right after creating it.
y_res = ray.pull(zeros([m, k], result_dtype)) # TODO(rkn): It would be preferable not to pull this right after creating it.
Ts = []
for i in range(min(a.num_blocks[0], a.num_blocks[1])): # this differs from the paper, which says "for i in range(a.num_blocks[1])", but that doesn't seem to make any sense when a.num_blocks[1] > a.num_blocks[0]
sub_dist_array = subblocks(a_work, range(i, a_work.num_blocks[0]), [i])
y, t, _, R = tsqr_hr(sub_dist_array)
y_val = halo.pull(y)
y_val = ray.pull(y)
for j in range(i, a.num_blocks[0]):
y_res.objrefs[j, i] = y_val.objrefs[j - i, 0]
if a.shape[0] > a.shape[1]:
# in this case, R needs to be square
R_shape = halo.pull(ra.shape(R))
R_shape = ray.pull(ra.shape(R))
eye_temp = ra.eye(R_shape[1], R_shape[0], dtype_name=result_dtype)
r_res.objrefs[i, i] = ra.dot(eye_temp, R)
else:
@@ -1,12 +1,12 @@
from typing import List
import numpy as np
import halo.arrays.remote as ra
import halo
import ray.arrays.remote as ra
import ray
from core import *
@halo.remote([List[int]], [DistArray])
@ray.remote([List[int]], [DistArray])
def normal(shape):
num_blocks = DistArray.compute_num_blocks(shape)
objrefs = np.empty(num_blocks, dtype=object)
@@ -1,77 +1,77 @@
from typing import List
import numpy as np
import halo
import ray
__all__ = ["zeros", "zeros_like", "ones", "eye", "dot", "vstack", "hstack", "subarray", "copy", "tril", "triu", "diag", "transpose", "add", "subtract", "sum", "shape"]
@halo.remote([List[int], str, str], [np.ndarray])
@ray.remote([List[int], str, str], [np.ndarray])
def zeros(shape, dtype_name="float", order="C"):
return np.zeros(shape, dtype=np.dtype(dtype_name), order=order)
@halo.remote([np.ndarray, str, str, bool], [np.ndarray])
@ray.remote([np.ndarray, str, str, bool], [np.ndarray])
def zeros_like(a, dtype_name="None", order="K", subok=True):
dtype_val = None if dtype_name == "None" else np.dtype(dtype_name)
return np.zeros_like(a, dtype=dtype_val, order=order, subok=subok)
@halo.remote([List[int], str, str], [np.ndarray])
@ray.remote([List[int], str, str], [np.ndarray])
def ones(shape, dtype_name="float", order="C"):
return np.ones(shape, dtype=np.dtype(dtype_name), order=order)
@halo.remote([int, int, int, str], [np.ndarray])
@ray.remote([int, int, int, str], [np.ndarray])
def eye(N, M=-1, k=0, dtype_name="float"):
M = N if M == -1 else M
return np.eye(N, M=M, k=k, dtype=np.dtype(dtype_name))
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def dot(a, b):
return np.dot(a, b)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def vstack(*xs):
return np.vstack(xs)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def hstack(*xs):
return np.hstack(xs)
# TODO(rkn): instead of this, consider implementing slicing
@halo.remote([np.ndarray, List[int], List[int]], [np.ndarray])
@ray.remote([np.ndarray, List[int], List[int]], [np.ndarray])
def subarray(a, lower_indices, upper_indices): # TODO(rkn): be consistent about using "index" versus "indices"
return a[[slice(l, u) for (l, u) in zip(lower_indices, upper_indices)]]
@halo.remote([np.ndarray, str], [np.ndarray])
@ray.remote([np.ndarray, str], [np.ndarray])
def copy(a, order="K"):
return np.copy(a, order=order)
@halo.remote([np.ndarray, int], [np.ndarray])
@ray.remote([np.ndarray, int], [np.ndarray])
def tril(m, k=0):
return np.tril(m, k=k)
@halo.remote([np.ndarray, int], [np.ndarray])
@ray.remote([np.ndarray, int], [np.ndarray])
def triu(m, k=0):
return np.triu(m, k=k)
@halo.remote([np.ndarray, int], [np.ndarray])
@ray.remote([np.ndarray, int], [np.ndarray])
def diag(v, k=0):
return np.diag(v, k=k)
@halo.remote([np.ndarray, List[int]], [np.ndarray])
@ray.remote([np.ndarray, List[int]], [np.ndarray])
def transpose(a, axes=[]):
axes = None if axes == [] else axes
return np.transpose(a, axes=axes)
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def add(x1, x2):
return np.add(x1, x2)
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def subtract(x1, x2):
return np.subtract(x1, x2)
@halo.remote([int, np.ndarray], [np.ndarray])
@ray.remote([int, np.ndarray], [np.ndarray])
def sum(axis, *xs):
return np.sum(xs, axis=axis)
@halo.remote([np.ndarray], [tuple])
@ray.remote([np.ndarray], [tuple])
def shape(a):
return np.shape(a)
@@ -1,88 +1,88 @@
from typing import List
import numpy as np
import halo
import ray
__all__ = ["matrix_power", "solve", "tensorsolve", "tensorinv", "inv",
"cholesky", "eigvals", "eigvalsh", "pinv", "slogdet", "det",
"svd", "eig", "eigh", "lstsq", "norm", "qr", "cond", "matrix_rank",
"LinAlgError", "multi_dot"]
@halo.remote([np.ndarray, int], [np.ndarray])
@ray.remote([np.ndarray, int], [np.ndarray])
def matrix_power(M, n):
return np.linalg.matrix_power(M, n)
@halo.remote([np.ndarray, np.ndarray], [np.ndarray])
@ray.remote([np.ndarray, np.ndarray], [np.ndarray])
def solve(a, b):
return np.linalg.solve(a, b)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray])
def tensorsolve(a):
raise NotImplementedError
@halo.remote([np.ndarray], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray])
def tensorinv(a):
raise NotImplementedError
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def inv(a):
return np.linalg.inv(a)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def cholesky(a):
return np.linalg.cholesky(a)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def eigvals(a):
return np.linalg.eigvals(a)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def eigvalsh(a):
raise NotImplementedError
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def pinv(a):
return np.linalg.pinv(a)
@halo.remote([np.ndarray], [int])
@ray.remote([np.ndarray], [int])
def slogdet(a):
raise NotImplementedError
@halo.remote([np.ndarray], [float])
@ray.remote([np.ndarray], [float])
def det(a):
return np.linalg.det(a)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray, np.ndarray])
def svd(a):
return np.linalg.svd(a)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray])
def eig(a):
return np.linalg.eig(a)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray])
def eigh(a):
return np.linalg.eigh(a)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray, int, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray, int, np.ndarray])
def lstsq(a, b):
return np.linalg.lstsq(a)
@halo.remote([np.ndarray], [float])
@ray.remote([np.ndarray], [float])
def norm(x):
return np.linalg.norm(x)
@halo.remote([np.ndarray], [np.ndarray, np.ndarray])
@ray.remote([np.ndarray], [np.ndarray, np.ndarray])
def qr(a):
return np.linalg.qr(a)
@halo.remote([np.ndarray], [float])
@ray.remote([np.ndarray], [float])
def cond(x):
return np.linalg.cond(x)
@halo.remote([np.ndarray], [int])
@ray.remote([np.ndarray], [int])
def matrix_rank(M):
return np.linalg.matrix_rank(M)
@halo.remote([np.ndarray], [np.ndarray])
@ray.remote([np.ndarray], [np.ndarray])
def multi_dot(*a):
raise NotImplementedError
@@ -1,7 +1,7 @@
from typing import List
import numpy as np
import halo
import ray
@halo.remote([List[int]], [np.ndarray])
@ray.remote([List[int]], [np.ndarray])
def normal(shape):
return np.random.normal(size=shape)
@@ -1,6 +1,6 @@
import importlib
import halo
import ray
def to_primitive(obj):
if hasattr(obj, "serialize"):
@@ -22,18 +22,18 @@ def from_primitive(primitive_obj):
def serialize(worker_capsule, obj):
primitive_obj = to_primitive(obj)
obj_capsule, contained_objrefs = halo.lib.serialize_object(worker_capsule, primitive_obj) # contained_objrefs is a list of the objrefs contained in obj
obj_capsule, contained_objrefs = ray.lib.serialize_object(worker_capsule, primitive_obj) # contained_objrefs is a list of the objrefs contained in obj
return obj_capsule, contained_objrefs
def deserialize(worker_capsule, capsule):
primitive_obj = halo.lib.deserialize_object(worker_capsule, capsule)
primitive_obj = ray.lib.deserialize_object(worker_capsule, capsule)
return from_primitive(primitive_obj)
def serialize_task(worker_capsule, func_name, args):
primitive_args = [(arg if isinstance(arg, halo.lib.ObjRef) else to_primitive(arg)) for arg in args]
return halo.lib.serialize_task(worker_capsule, func_name, primitive_args)
primitive_args = [(arg if isinstance(arg, ray.lib.ObjRef) else to_primitive(arg)) for arg in args]
return ray.lib.serialize_task(worker_capsule, func_name, primitive_args)
def deserialize_task(worker_capsule, task):
func_name, primitive_args, return_objrefs = halo.lib.deserialize_task(worker_capsule, task)
args = [(arg if isinstance(arg, halo.lib.ObjRef) else from_primitive(arg)) for arg in primitive_args]
func_name, primitive_args, return_objrefs = ray.lib.deserialize_task(worker_capsule, task)
args = [(arg if isinstance(arg, ray.lib.ObjRef) else from_primitive(arg)) for arg in primitive_args]
return func_name, args, return_objrefs
@@ -3,8 +3,8 @@ import os
import atexit
import time
import halo
import halo.worker as worker
import ray
import ray.worker as worker
_services_path = os.path.dirname(os.path.abspath(__file__))
@@ -58,9 +58,9 @@ def cleanup():
global drivers
for driver in drivers:
halo.disconnect(driver)
ray.disconnect(driver)
if len(drivers) == 0:
halo.disconnect()
ray.disconnect()
drivers = []
# atexit.register(cleanup)
@@ -97,7 +97,7 @@ def start_node(scheduler_address, node_ip_address, num_workers, worker_path=None
for _ in range(num_workers):
start_worker(worker_path, scheduler_address, objstore_address, address(node_ip_address, new_worker_port()))
time.sleep(0.3)
halo.connect(scheduler_address, objstore_address, address(node_ip_address, new_worker_port()))
ray.connect(scheduler_address, objstore_address, address(node_ip_address, new_worker_port()))
time.sleep(0.5)
def start_singlenode_cluster(return_drivers=False, num_objstores=1, num_workers_per_objstore=0, worker_path=None):
@@ -124,11 +124,11 @@ def start_singlenode_cluster(return_drivers=False, num_objstores=1, num_workers_
driver_workers = []
for i in range(num_objstores):
driver_worker = worker.Worker()
halo.connect(scheduler_address, objstore_address, address(IP_ADDRESS, new_worker_port()), driver_worker)
ray.connect(scheduler_address, objstore_address, address(IP_ADDRESS, new_worker_port()), driver_worker)
driver_workers.append(driver_worker)
drivers.append(driver_worker)
time.sleep(0.5)
return driver_workers
else:
halo.connect(scheduler_address, objstore_addresses[0], address(IP_ADDRESS, new_worker_port()))
ray.connect(scheduler_address, objstore_addresses[0], address(IP_ADDRESS, new_worker_port()))
time.sleep(0.5)
@@ -4,7 +4,7 @@ import funcsigs
import numpy as np
import pynumbuf
import halo
import ray
import serialization
class Worker(object):
@@ -17,10 +17,10 @@ class Worker(object):
def put_object(self, objref, value):
"""Put `value` in the local object store with objref `objref`. This assumes that the value for `objref` has not yet been placed in the local object store."""
if pynumbuf.serializable(value):
halo.lib.put_arrow(self.handle, objref, value)
ray.lib.put_arrow(self.handle, objref, value)
else:
object_capsule, contained_objrefs = serialization.serialize(self.handle, value) # contained_objrefs is a list of the objrefs contained in object_capsule
halo.lib.put_object(self.handle, objref, object_capsule, contained_objrefs)
ray.lib.put_object(self.handle, objref, object_capsule, contained_objrefs)
def get_object(self, objref):
"""
@@ -29,32 +29,32 @@ class Worker(object):
WARNING: get_object can only be called on a canonical objref.
"""
if halo.lib.is_arrow(self.handle, objref):
return halo.lib.get_arrow(self.handle, objref)
if ray.lib.is_arrow(self.handle, objref):
return ray.lib.get_arrow(self.handle, objref)
else:
object_capsule = halo.lib.get_object(self.handle, objref)
object_capsule = ray.lib.get_object(self.handle, objref)
return serialization.deserialize(self.handle, object_capsule)
def alias_objrefs(self, alias_objref, target_objref):
"""Make `alias_objref` refer to the same object that `target_objref` refers to."""
halo.lib.alias_objrefs(self.handle, alias_objref, target_objref)
ray.lib.alias_objrefs(self.handle, alias_objref, target_objref)
def register_function(self, function):
"""Notify the scheduler that this worker can execute the function with name `func_name`. Store the function `function` locally."""
halo.lib.register_function(self.handle, function.func_name, len(function.return_types))
ray.lib.register_function(self.handle, function.func_name, len(function.return_types))
self.functions[function.func_name] = function
def submit_task(self, func_name, args):
"""Tell the scheduler to schedule the execution of the function with name `func_name` with arguments `args`. Retrieve object references for the outputs of the function from the scheduler and immediately return them."""
task_capsule = serialization.serialize_task(self.handle, func_name, args)
objrefs = halo.lib.submit_task(self.handle, task_capsule)
objrefs = ray.lib.submit_task(self.handle, task_capsule)
return objrefs
# We make `global_worker` a global variable so that there is one worker per worker process.
global_worker = Worker()
def scheduler_info(worker=global_worker):
return halo.lib.scheduler_info(worker.handle);
return ray.lib.scheduler_info(worker.handle);
def register_module(module, recursive=False, worker=global_worker):
print "registering functions in module {}.".format(module.__name__)
@@ -69,32 +69,32 @@ def register_module(module, recursive=False, worker=global_worker):
def connect(scheduler_addr, objstore_addr, worker_addr, worker=global_worker):
if hasattr(worker, "handle"):
del worker.handle
worker.handle = halo.lib.create_worker(scheduler_addr, objstore_addr, worker_addr)
worker.handle = ray.lib.create_worker(scheduler_addr, objstore_addr, worker_addr)
def disconnect(worker=global_worker):
halo.lib.disconnect(worker.handle)
ray.lib.disconnect(worker.handle)
def pull(objref, worker=global_worker):
halo.lib.request_object(worker.handle, objref)
ray.lib.request_object(worker.handle, objref)
return worker.get_object(objref)
def push(value, worker=global_worker):
objref = halo.lib.get_objref(worker.handle)
objref = ray.lib.get_objref(worker.handle)
worker.put_object(objref, value)
return objref
def main_loop(worker=global_worker):
if not halo.lib.connected(worker.handle):
if not ray.lib.connected(worker.handle):
raise Exception("Worker is attempting to enter main_loop but has not been connected yet.")
halo.lib.start_worker_service(worker.handle)
ray.lib.start_worker_service(worker.handle)
def process_task(task): # wrapping these lines in a function should cause the local variables to go out of scope more quickly, which is useful for inspecting reference counts
func_name, args, return_objrefs = serialization.deserialize_task(worker.handle, task)
arguments = get_arguments_for_execution(worker.functions[func_name], args, worker) # get args from objstore
outputs = worker.functions[func_name].executor(arguments) # execute the function
store_outputs_in_objstore(return_objrefs, outputs, worker) # store output in local object store
halo.lib.notify_task_completed(worker.handle) # notify the scheduler that the task has completed
ray.lib.notify_task_completed(worker.handle) # notify the scheduler that the task has completed
while True:
task = halo.lib.wait_for_next_task(worker.handle)
task = ray.lib.wait_for_next_task(worker.handle)
process_task(task)
def remote(arg_types, return_types, worker=global_worker):
@@ -148,7 +148,7 @@ def check_return_values(function, result):
if len(result) != len(function.return_types):
raise Exception("The @remote decorator for function {} has {} return values with types {}, but {} returned {} values.".format(function.__name__, len(function.return_types), function.return_types, function.__name__, len(result)))
for i in range(len(result)):
if (not isinstance(result[i], function.return_types[i])) and (not isinstance(result[i], halo.lib.ObjRef)):
if (not isinstance(result[i], function.return_types[i])) and (not isinstance(result[i], ray.lib.ObjRef)):
raise Exception("The {}th return value for function {} has type {}, but the @remote decorator expected a return value of type {} or an ObjRef.".format(i, function.__name__, type(result[i]), function.return_types[i]))
# helper method, this should not be called by the user
@@ -167,7 +167,7 @@ def check_arguments(function, args):
else:
assert False, "This code should be unreachable."
if isinstance(arg, halo.lib.ObjRef):
if isinstance(arg, ray.lib.ObjRef):
# TODO(rkn): When we have type information in the ObjRef, do type checking here.
pass
else:
@@ -194,7 +194,7 @@ def get_arguments_for_execution(function, args, worker=global_worker):
else:
assert False, "This code should be unreachable."
if isinstance(arg, halo.lib.ObjRef):
if isinstance(arg, ray.lib.ObjRef):
# get the object from the local object store
print "Getting argument {} for function {}.".format(i, function.__name__)
argument = worker.get_object(arg)
@@ -214,7 +214,7 @@ def store_outputs_in_objstore(objrefs, outputs, worker=global_worker):
outputs = (outputs,)
for i in range(len(objrefs)):
if isinstance(outputs[i], halo.lib.ObjRef):
if isinstance(outputs[i], ray.lib.ObjRef):
# An ObjRef is being returned, so we must alias objrefs[i] so that it refers to the same object that outputs[i] refers to
print "Aliasing objrefs {} and {}".format(objrefs[i].val, outputs[i].val)
worker.alias_objrefs(objrefs[i], outputs[i])
+3 -3
View File
@@ -3,15 +3,15 @@ import sys
from setuptools import setup, Extension, find_packages
import setuptools
# because of relative paths, this must be run from inside halo/lib/python/
# because of relative paths, this must be run from inside ray/lib/python/
setup(
name = "halo",
name = "ray",
version = "0.1.dev0",
use_2to3=True,
packages=find_packages(),
package_data = {
"halo": ["libhalolib.so", "scheduler", "objstore"]
"ray": ["libraylib.so", "scheduler", "objstore"]
},
zip_safe=False
)