pip install "ray[default]"
pip install anyscale
anyscale init --name helloworld
hello.pyin your working directory and run it with
@ray.remotetells Python that the annotated function is to be run on a Ray cluster.
say_hiis 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.
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.
ANYSCALE_CLI_TOKENenvironment 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.