mirror of
https://github.com/wassname/ray.git
synced 2026-07-05 19:41:13 +08:00
add example functions to default worker (#210)
This commit is contained in:
committed by
Philipp Moritz
parent
eff6924b7c
commit
529e86ce64
@@ -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()
|
||||
|
||||
@@ -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.")
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user