Skip to main content

Get Started

Welcome to the Anyscale platform, we are glad to have you on board!

This quickstart assumes:

Remote "Hello, World" from scratch

Save the following as and run it with python

import ray
import anyscale

def say_hi(message):
return f"Hello, {message}."

ray.init("anyscale://") # or `ray.init("anyscale://hello_cluster")` to name the cluster


What happened?

In this example, you have run your code in a remote, distributed environment using Anyscale.

  • @ray.remote tells Python that the annotated function is to be run on a Ray cluster.
  • say_hi is a function which returns its single argument appended to a friendly greeting. Since it is annotated with @ray.remote, you have to call it as a remote function.
  • ray.init("anyscale://hello_cluster") initiates the connection to a Ray cluster managed by Anyscale. A Ray client's connection string begins with anyscale:// for all clusters managed by Anyscale. This example creates or uses a cluster called hello_cluster; if the cluster does not exist, it will be created and subsequent attempts to connect will re-use this cluster.
  • The last line of the script invokes the remote function and prints its output. say_hi.remote("World") creates a non-blocking function call, which ray.get(...) subsequently waits for and returns. In between, Ray and Anyscale have marshalled the resources to compute the result of this function.
  • The script authenticated automatically via one of two methods. A script connecting to Anyscale will read a token from the ANYSCALE_CLI_TOKEN environment variable, or if that variable is not set, will look at the user's credentials file at ~/.anyscale/credentials.json. If neither method succeeds to authenticate, then Anyscale refuses to run the script.

Why does it matter?

The example remote function above is not practical; it takes longer to run in the cloud than it would locally. To realize the potential of Anyscale and Ray, you'll find yourself heading in the following directions:

  • More complex non-blocking functions show how Ray parallelizes and sequences tasks for high utilization.
  • Actors encapsulate functionality into distributed and scalable stateful objects.
  • Long running API servers, implemented as Actors, provide replicated endpoints for high-volume API calls.
  • Distributed iterators and data structures provide parallel abstractions over pythonic idioms.
  • Higher-level libraries like Ray Tune or RLlib leverage Ray under the hood to provide parallelization without coding it at all.

Next steps

  • Learn some Anyscale concepts more deeply.
  • Check out the Ray documentation. The Ray client interacts with Ray clusters the same way that it does when connecting to Anyscale, so any project you've written for Ray will also work on the Anyscale platform.
  • Migrate your project from Open Source Ray to Anyscale.