RayBackend

The class is specific implementation of Backend interface using Ray.

API

class unidist.core.backends.ray.backend.RayBackend

The class that implements the interface in Backend using Ray.

static cluster_resources()

Get resources of Ray cluster.

Returns:

Dictionary with cluster nodes info in the form {“node_ip0”: {“CPU”: x0}, “node_ip1”: {“CPU”: x1}, …}.

Return type:

dict

static get(object_refs)

Get a remote object or a list of remote objects from distributed memory.

Parameters:

object_refs (ray.ObjectRef or list of ray.ObjectRef-s) – Ray ObjectRef or a list of Ray ObjectRef objects to get data from.

Returns:

A Python object or a list of Python objects.

Return type:

object

static get_ip()

Get node IP address.

Returns:

Node IP address.

Return type:

str

is_initialized()

Check if Ray backend has already been initialized.

Returns:

True or False.

Return type:

bool

static make_actor(cls, num_cpus, resources)

Define an actor class.

clsobject

Class to be an actor class.

num_cpusint

The number of CPUs to reserve for the lifetime of the actor.

resourcesdict

Custom resources to reserve for the lifetime of the actor.

Returns:

  • RayActor – The actor class type to create.

  • list – The list of arguments for RayActor constructor.

static make_remote_function(function, num_cpus, num_returns, resources)

Define a remote function.

functioncallable

Function to be a remote function.

num_cpusint

The number of CPUs to reserve for the remote function.

num_returnsint

The number of ObjectRef-s returned by the remote function invocation.

resourcesdict

Custom resources to reserve for the remote function.

Return type:

RayRemoteFunction

static num_cpus()

Get the number of CPUs used by the execution backend.

Return type:

int

static put(data)

Put data into distributed memory.

Parameters:

data (object) – Data to be put.

Returns:

Ray ObjectRef matching to data.

Return type:

ray.ObjectRef

static shutdown()

Shutdown Ray execution backend.

static wait(object_refs, num_returns=1)

Wait until object_refs are finished.

This method returns two lists. The first list consists of object refs that correspond to objects that completed computations. The second list corresponds to the rest of the object refs (which may or may not be ready).

Parameters:
  • object_refs (list of ray.ObjectRef-s) – List of Ray ObjectRefs to be waited.

  • num_returns (int, default: 1) – The number of Ray ObjectRefs that should be returned as ready.

Returns:

List of object refs that are ready and list of the remaining object refs.

Return type:

tuple