[Deprecated] Builder API

API reference

circle-info

This documentation covers using the Anyscale Ray Client through the ray.client API, which will be deprecated. If you're using Ray 1.5 or higher, follow the instructions in the Anyscale Ray Client API Reference instead.

To connect to a cluster using anyscale client builder you can get started with running ray.client("anyscale://cluster_name").connect(). Anyscale will automatically detect your laptop's ray and python versions and start a compatible cluster with a cluster_env that has the same ray/python versions as your laptop.

Connection Options

To create or connect to a ray cluster, use ray.client(url). This method returns a client object, which can be optionally manipulated by builder methods, before calling .connect() to initialize the connection with the ray cluster. The url can be provided explicitly in the code or by setting the RAY_ADDRESS environment variable. For example:

1)

# script.py
import ray
ray.client().connect()

and then run RAY_ADDRESS=anyscale://cluster_name python script.py is equivalent to

2)

# script.py
import ray
ray.client("anyscale://cluster_name").connect()

and then run python script.py

The Connection String

The connection string for ray.client() specifies which Ray cluster to use. To connect to Anyscale, this URL will begin with "anyscale." You have the option of using parameters in the connection string to modify the connection's configuration. Here are the options for this connection string:

ray.client("anyscale://{cluster_name}" +
                      "?update={True|False}" +
                      "&autosuspend={timeInMinutes}"  +
                      "&cluster_env={cluster_env}" +
                      "&cluster_compute={cluster_compute}"
                      ).connect()

Note that each of these methods has a correlation in the builder API below.

Builder Methods

The object returned by ray.client(url) can be subsequently modified by the methods documented below:

ClientContext

Calling ray.client("anyscale://...").connect() returns a ClientContext object. This object provides information about the cluster (Ray version, Python version, and a URL to the Ray dashboard). The ClientContext also provides a disconnect() method that will disconnect from the current cluster. Finally, you may also use ClientContext as a context manager, which will automatically call disconnect() for you after the with block is complete.

Last updated

Was this helpful?