Skip to main content
Article·ray.io
distributed-computingparallel-processingreinforcement-learningpythonray

Ray

Learn how to use Ray, an open-source framework, to scale your Python applications and AI workloads with easy-to-use APIs for distributed computing.

beginner15 minutes6 steps
The play
  1. Install Ray
    Install Ray using pip. This will give you the core Ray libraries and command-line tools.
  2. Initialize Ray
    Initialize a Ray cluster. This starts the Ray runtime environment.
  3. Define a Ray Task
    Define a Python function and decorate it with `@ray.remote` to turn it into a Ray task. Ray tasks can be executed in parallel on the Ray cluster.
  4. Execute Tasks in Parallel
    Call the remote function using `.remote()` to submit the task to the Ray cluster. This returns a `Future` (an `ObjectID`) immediately.
  5. Retrieve Results
    Use `ray.get()` to retrieve the results of the Ray tasks. `ray.get()` blocks until the results are available.
  6. Shutdown Ray
    Shutdown the Ray cluster when you are finished.
Starter code
Start by installing Ray and initializing a local Ray cluster. Then, define a simple function and use `@ray.remote` to turn it into a Ray task. Submit several tasks in parallel and retrieve the results.
Source
Ray — Action Pack