diff --git a/scripts/default_worker.py b/scripts/default_worker.py index 2ee6b9542..522d43df1 100644 --- a/scripts/default_worker.py +++ b/scripts/default_worker.py @@ -4,6 +4,7 @@ import numpy as np import ray.array.remote as ra import ray.array.distributed as da +import example_functions import ray import ray.services as services @@ -24,5 +25,6 @@ if __name__ == "__main__": ray.register_module(da) ray.register_module(da.random) ray.register_module(da.linalg) + ray.register_module(example_functions) worker.main_loop() diff --git a/scripts/example_functions.py b/scripts/example_functions.py new file mode 100644 index 000000000..e424e9b5e --- /dev/null +++ b/scripts/example_functions.py @@ -0,0 +1,25 @@ +import ray +import numpy as np +from typing import List + +@ray.remote([int], [float]) +def estimate_pi(n): + x = np.random.uniform(size=n) + y = np.random.uniform(size=n) + return 4 * np.mean(x ** 2 + y ** 2 < 1) + +@ray.remote([int], [int]) +def increment(x): + return x + 1 + +@ray.remote([List[int]], [np.ndarray]) +def zeros(shape): + return np.zeros(shape) + +@ray.remote([np.ndarray, np.ndarray], [np.ndarray]) +def dot(a, b): + return np.dot(a, b) + +@ray.remote([], []) +def throw_exception(): + raise Exception("This function intentionally failed.") diff --git a/scripts/shell.py b/scripts/shell.py index b0164ce08..2c1bb75c1 100644 --- a/scripts/shell.py +++ b/scripts/shell.py @@ -8,6 +8,7 @@ import ray.worker as worker import ray.array.remote as ra import ray.array.distributed as da +import example_functions DEFAULT_NUM_WORKERS = 10 DEFAULT_WORKER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "default_worker.py")