mirror of
https://github.com/wassname/ray.git
synced 2026-09-10 12:38:43 +08:00
Allow remote decorator to be used with no parentheses.
This commit is contained in:
+3
-3
@@ -10,15 +10,15 @@ However, to provide a more flexible API, we allow tasks to not only return
|
||||
values, but to also return object ids to values. As an examples, consider
|
||||
the following code.
|
||||
```python
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def f()
|
||||
return np.zeros(5)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def g()
|
||||
return f()
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def h()
|
||||
return g()
|
||||
```
|
||||
|
||||
@@ -5,7 +5,7 @@ functions. Remote functions are written like regular Python functions, but with
|
||||
the `@ray.remote` decorator on top.
|
||||
|
||||
```python
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def increment(n):
|
||||
return n + 1
|
||||
```
|
||||
|
||||
+6
-6
@@ -107,7 +107,7 @@ def add(a, b):
|
||||
```
|
||||
A remote function in Ray looks like this.
|
||||
```python
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def add(a, b):
|
||||
return a + b
|
||||
```
|
||||
@@ -194,7 +194,7 @@ around `time.sleep`.
|
||||
```python
|
||||
import time
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def sleep(n):
|
||||
time.sleep(n)
|
||||
return 0
|
||||
@@ -245,11 +245,11 @@ Computation graphs encode dependencies. For example, suppose we define
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def zeros(shape):
|
||||
return np.zeros(shape)
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def dot(a, b):
|
||||
return np.dot(a, b)
|
||||
```
|
||||
@@ -282,12 +282,12 @@ processes can also call remote functions. To illustrate this, consider the
|
||||
following example.
|
||||
|
||||
```python
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def sub_experiment(i, j):
|
||||
# Run the jth sub-experiment for the ith experiment.
|
||||
return i + j
|
||||
|
||||
@ray.remote()
|
||||
@ray.remote
|
||||
def run_experiment(i):
|
||||
sub_results = []
|
||||
# Launch tasks to perform 10 sub-experiments in parallel.
|
||||
|
||||
Reference in New Issue
Block a user