ray API Reference
Unified framework for scaling AI and Python applications through distributed computing.
ray.AUTO_INIT_APIS
Python Library Documentation: set object class set(object) | set() -> new empty set object | set(iterable) -> new set object | | Build an unordered collection of unique elements. | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __contains__(...) | x.__contains__(y) <==> y in x. | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __gt__(self, value, /) | Return self>value. | | __iand__(self, value, /) | Return self&=value. | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __ior__(self, value, /) | Return self|=value. | | __isub__(self, value, /) | Return self-=value. | | __iter__(self, /) | Implement iter(self). | | __ixor__(self, value, /) | Return self^=value. | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __reduce__(...) | Return state information for pickling. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rsub__(self, value, /) | Return value-self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(...) | S.__sizeof__() -> size of S in memory, in bytes | | __sub__(self, value, /) | Return self-value. | | __xor__(self, value, /) | Return self^value. | | add(...) | Add an element to a set. | | This has no effect if the element is already present. | | clear(...) | Remove all elements from this set. | | copy(...) | Return a shallow copy of a set. | | difference(...) | Return the difference of two or more sets as a new set. | | (i.e. all elements that are in this set but not the others.) | | difference_update(...) | Remove all elements of another set from this set. | | discard(...) | Remove an element from a set if it is a member. | | Unlike set.remove(), the discard() method does not raise | an exception when an element is missing from the set. | | intersection(...) | Return the intersection of two sets as a new set. | | (i.e. all elements that are in both sets.) | | intersection_update(...) | Update a set with the intersection of itself and another. | | isdisjoint(...) | Return True if two sets have a null intersection. | | issubset(self, other, /) | Test whether every element in the set is in other. | | issuperset(self, other, /) | Test whether every element in other is in the set. | | pop(...) | Remove and return an arbitrary set element. | Raises KeyError if the set is empty. | | remove(...) | Remove an element from a set; it must be a member. | | If the element is not a member, raise a KeyError. | | symmetric_difference(...) | Return the symmetric difference of two sets as a new set. | | (i.e. all elements that are in exactly one of the sets.) | | symmetric_difference_update(...) | Update a set with the symmetric difference of itself and another. | | union(...) | Return the union of sets as a new set. | | (i.e. all elements that are in either set.) | | update(...) | Update a set with the union of itself and others. | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__(...) | See PEP 585 | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None
ray.ActorClassID
Python Library Documentation: class ActorClassID in module ray._raylet class ActorClassID(UniqueID) | ActorClassID(id) | | Method resolution order: | ActorClassID | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | ActorClassID.from_hex(cls, hex_id) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from UniqueID: | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods inherited from UniqueID: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.ActorID
Python Library Documentation: class ActorID in module ray._raylet class ActorID(BaseID) | ActorID(id) | | Method resolution order: | ActorID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | binary(self) | ActorID.binary(self) | | hex(self) | ActorID.hex(self) | | is_nil(self) | ActorID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | ActorID.from_hex(cls, hex_id) | | from_random() | ActorID.from_random(cls) | | nil() | ActorID.nil(cls) | | of(job_id, parent_task_id, parent_task_counter) | ActorID.of(cls, job_id, parent_task_id, parent_task_counter) | | size() | ActorID.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | job_id | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.ClientBuilder
Python Library Documentation: class ClientBuilder in module ray.client_builder class ClientBuilder(builtins.object) | ClientBuilder(address: Optional[str]) -> None | | Builder for a Ray Client connection. This class can be subclassed by | custom builder classes to modify connection behavior to include additional | features or altered semantics. One example is the ``_LocalClientBuilder``. | | .. warning:: | | **DEPRECATED**: This API is deprecated and may be removed in future Ray releases. | | Methods defined here: | | __init__(self, address: Optional[str]) -> None | Initialize self. See help(type(self)) for accurate signature. | | connect(self) -> ray.client_builder.ClientContext | Begin a connection to the address passed in via ray.client(...). | | Returns: | ClientInfo: Dataclass with information about the setting. This | includes the server's version of Python & Ray as well as the | dashboard_url. | | env(self, env: Dict[str, Any]) -> 'ClientBuilder' | Set an environment for the session. | Args: | env (Dict[st, Any]): A runtime environment to use for this | connection. See :ref:`runtime-environments` for what values are | accepted in this dict. | | namespace(self, namespace: str) -> 'ClientBuilder' | Sets the namespace for the session. | Args: | namespace: Namespace to use. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
ray.ClusterID
Python Library Documentation: class ClusterID in module ray._raylet class ClusterID(UniqueID) | ClusterID(id) | | Method resolution order: | ClusterID | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | ClusterID.from_hex(cls, hex_id) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from UniqueID: | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods inherited from UniqueID: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.DynamicObjectRefGenerator
Python Library Documentation: class DynamicObjectRefGenerator in module ray._private.object_ref_generator
class DynamicObjectRefGenerator(builtins.object)
| DynamicObjectRefGenerator(refs: "Deque['ray.ObjectRef']")
|
| **DeveloperAPI:** This API may change across minor Ray releases.
|
| Methods defined here:
|
| __init__(self, refs: "Deque['ray.ObjectRef']")
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> "Iterator('ray.ObjectRef')"
|
| __len__(self) -> 'int'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
ray.FunctionID
Python Library Documentation: class FunctionID in module ray._raylet class FunctionID(UniqueID) | FunctionID(id) | | Method resolution order: | FunctionID | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | FunctionID.from_hex(cls, hex_id) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from UniqueID: | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods inherited from UniqueID: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.JobID
Python Library Documentation: class JobID in module ray._raylet class JobID(BaseID) | JobID(id) | | Method resolution order: | JobID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | binary(self) | JobID.binary(self) | | hex(self) | JobID.hex(self) | | int(self) | JobID.int(self) | | is_nil(self) | JobID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | JobID.from_hex(cls, hex_id) | | from_int(value) | JobID.from_int(cls, value) | | nil() | JobID.nil(cls) | | size() | JobID.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.Language
Python Library Documentation: class Language in module ray._raylet class Language(builtins.object) | Methods defined here: | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | Language.__reduce__(self) | | __repr__(...) | Return repr(self). | | value(self) | Language.value(self) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | CPP = CPP | | JAVA = JAVA | | PYTHON = PYTHON | | __hash__ = None | | __pyx_vtable__ = <capsule object NULL>
ray.LoggingConfig
Python Library Documentation: class LoggingConfig in module ray._private.ray_logging.logging_config
class LoggingConfig(builtins.object)
| LoggingConfig(encoding: str = 'TEXT', log_level: str = 'INFO', additional_log_standard_attrs: list = <factory>) -> None
|
| Logging configuration for a Ray job. These configurations are used to set up the
| root logger of the driver process and all Ray tasks and actor processes that belong
| to the job.
|
| Examples: 1. Configure the logging to use TEXT encoding.
| .. testcode::
|
| import ray
| import logging
|
| ray.init(
| logging_config=ray.LoggingConfig(encoding="TEXT", log_level="INFO", additional_log_standard_attrs=['name'])
| )
|
| @ray.remote
| def f():
| logger = logging.getLogger(__name__)
| logger.info("This is a Ray task")
|
| ray.get(f.remote())
| ray.shutdown()
|
| .. testoutput::
| :options: +MOCK
|
| 2025-02-12 12:25:16,836 INFO test-log-config.py:11 -- This is a Ray task name=__main__ job_id=01000000 worker_id=51188d9448be4664bf2ea26ac410b67acaaa970c4f31c5ad3ae776a5 node_id=f683dfbffe2c69984859bc19c26b77eaf3866c458884c49d115fdcd4 task_id=c8ef45ccd0112571ffffffffffffffffffffffff01000000 task_name=f task_func_name=test-log-config.f timestamp_ns=1739391916836884000
|
| 2. Configure the logging to use JSON encoding.
| .. testcode::
|
| import ray
| import logging
|
| ray.init(
| logging_config=ray.LoggingConfig(encoding="JSON", log_level="INFO", additional_log_standard_attrs=['name'])
| )
|
| @ray.remote
| def f():
| logger = logging.getLogger(__name__)
| logger.info("This is a Ray task")
|
| ray.get(f.remote())
| ray.shutdown()
|
| .. testoutput::
| :options: +MOCK
|
| {"asctime": "2025-02-12 12:25:48,766", "levelname": "INFO", "message": "This is a Ray task", "filename": "test-log-config.py", "lineno": 11, "name": "__main__", "job_id": "01000000", "worker_id": "6d307578014873fcdada0fa22ea6d49e0fb1f78960e69d61dfe41f5a", "node_id": "69e3a5e68bdc7eb8ac9abb3155326ee3cc9fc63ea1be04d11c0d93c7", "task_id": "c8ef45ccd0112571ffffffffffffffffffffffff01000000", "task_name": "f", "task_func_name": "test-log-config.f", "timestamp_ns": 1739391948766949000}
|
| Args:
| encoding: Encoding type for the logs. The valid values are
| {list(_logging_configurator.get_supported_encodings())}
| log_level: Log level for the logs. Defaults to 'INFO'. You can set
| it to 'DEBUG' to receive more detailed debug logs.
| additional_log_standard_attrs: List of additional standard python logger attributes to
| include in the log. Defaults to an empty list. The list of already
| included standard attributes are: "asctime", "levelname", "message",
| "filename", "lineno", "exc_text". The list of valid attributes are specified
| here: http://docs.python.org/library/logging.html#logrecord-attributes
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, encoding: str = 'TEXT', log_level: str = 'INFO', additional_log_standard_attrs: list = <factory>) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> Dict[str, object]
| Serialize to a plain dict suitable for JSON transport.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: Dict[str, object]) -> 'LoggingConfig'
| Create a LoggingConfig from a dict, ignoring unknown keys.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'additional_log_standard_attrs': <class 'list'>, 'e...
|
| __dataclass_fields__ = {'additional_log_standard_attrs': Field(name='a...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('encoding', 'log_level', 'additional_log_standard_at...
|
| encoding = 'TEXT'
|
| log_level = 'INFO'
ray.NON_AUTO_INIT_APIS
Python Library Documentation: set object class set(object) | set() -> new empty set object | set(iterable) -> new set object | | Build an unordered collection of unique elements. | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __contains__(...) | x.__contains__(y) <==> y in x. | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __gt__(self, value, /) | Return self>value. | | __iand__(self, value, /) | Return self&=value. | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __ior__(self, value, /) | Return self|=value. | | __isub__(self, value, /) | Return self-=value. | | __iter__(self, /) | Implement iter(self). | | __ixor__(self, value, /) | Return self^=value. | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __reduce__(...) | Return state information for pickling. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rsub__(self, value, /) | Return value-self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(...) | S.__sizeof__() -> size of S in memory, in bytes | | __sub__(self, value, /) | Return self-value. | | __xor__(self, value, /) | Return self^value. | | add(...) | Add an element to a set. | | This has no effect if the element is already present. | | clear(...) | Remove all elements from this set. | | copy(...) | Return a shallow copy of a set. | | difference(...) | Return the difference of two or more sets as a new set. | | (i.e. all elements that are in this set but not the others.) | | difference_update(...) | Remove all elements of another set from this set. | | discard(...) | Remove an element from a set if it is a member. | | Unlike set.remove(), the discard() method does not raise | an exception when an element is missing from the set. | | intersection(...) | Return the intersection of two sets as a new set. | | (i.e. all elements that are in both sets.) | | intersection_update(...) | Update a set with the intersection of itself and another. | | isdisjoint(...) | Return True if two sets have a null intersection. | | issubset(self, other, /) | Test whether every element in the set is in other. | | issuperset(self, other, /) | Test whether every element in other is in the set. | | pop(...) | Remove and return an arbitrary set element. | Raises KeyError if the set is empty. | | remove(...) | Remove an element from a set; it must be a member. | | If the element is not a member, raise a KeyError. | | symmetric_difference(...) | Return the symmetric difference of two sets as a new set. | | (i.e. all elements that are in exactly one of the sets.) | | symmetric_difference_update(...) | Update a set with the symmetric difference of itself and another. | | union(...) | Return the union of sets as a new set. | | (i.e. all elements that are in either set.) | | update(...) | Update a set with the union of itself and others. | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__(...) | See PEP 585 | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None
ray.NodeID
Python Library Documentation: class NodeID in module ray._raylet class NodeID(UniqueID) | NodeID(id) | | Method resolution order: | NodeID | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | NodeID.from_hex(cls, hex_id) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from UniqueID: | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods inherited from UniqueID: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.ObjectID
Python Library Documentation: class ObjectRef in module ray class ObjectRef(ray._raylet.BaseID) | ObjectRef(id, owner_addr=u'', call_site_data=u'', skip_adding_local_ref=False, tensor_transport: Optional[str] = None) | | Method resolution order: | ObjectRef | ray._raylet.BaseID | builtins.object | | Methods defined here: | | __await__(...) | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | as_future(self, _internal=False) -> 'asyncio.Future' | ObjectRef.as_future(self, _internal=False) -> asyncio.Future | Wrap ObjectRef with an asyncio.Future. | | Note that the future cancellation will not cancel the correspoding | task when the ObjectRef representing return object of a task. | | binary(self) | ObjectRef.binary(self) | | call_site(self) | ObjectRef.call_site(self) | | future(self) -> 'concurrent.futures.Future' | ObjectRef.future(self) -> concurrent.futures.Future | Wrap ObjectRef with a concurrent.futures.Future | | Note that the future cancellation will not cancel the correspoding | task when the ObjectRef representing return object of a task. | Additionally, future.running() will always be ``False`` even if the | underlying task is running. | | hex(self) | ObjectRef.hex(self) | | is_nil(self) | ObjectRef.is_nil(self) | | job_id(self) | ObjectRef.job_id(self) | | owner_address(self) | ObjectRef.owner_address(self) | | task_id(self) | ObjectRef.task_id(self) | | tensor_transport(self) | ObjectRef.tensor_transport(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__ = GenericAlias(...) | Represent a PEP 585 generic type | | E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,). | | from_random() | ObjectRef.from_random(cls) | | nil() | ObjectRef.nil(cls) | | size() | ObjectRef.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from ray._raylet.BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from ray._raylet.BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes) | | from_hex(hex_id) | BaseID.from_hex(cls, hex_id)
ray.ObjectRef
Python Library Documentation: class ObjectRef in module ray class ObjectRef(ray._raylet.BaseID) | ObjectRef(id, owner_addr=u'', call_site_data=u'', skip_adding_local_ref=False, tensor_transport: Optional[str] = None) | | Method resolution order: | ObjectRef | ray._raylet.BaseID | builtins.object | | Methods defined here: | | __await__(...) | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | as_future(self, _internal=False) -> 'asyncio.Future' | ObjectRef.as_future(self, _internal=False) -> asyncio.Future | Wrap ObjectRef with an asyncio.Future. | | Note that the future cancellation will not cancel the correspoding | task when the ObjectRef representing return object of a task. | | binary(self) | ObjectRef.binary(self) | | call_site(self) | ObjectRef.call_site(self) | | future(self) -> 'concurrent.futures.Future' | ObjectRef.future(self) -> concurrent.futures.Future | Wrap ObjectRef with a concurrent.futures.Future | | Note that the future cancellation will not cancel the correspoding | task when the ObjectRef representing return object of a task. | Additionally, future.running() will always be ``False`` even if the | underlying task is running. | | hex(self) | ObjectRef.hex(self) | | is_nil(self) | ObjectRef.is_nil(self) | | job_id(self) | ObjectRef.job_id(self) | | owner_address(self) | ObjectRef.owner_address(self) | | task_id(self) | ObjectRef.task_id(self) | | tensor_transport(self) | ObjectRef.tensor_transport(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__ = GenericAlias(...) | Represent a PEP 585 generic type | | E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,). | | from_random() | ObjectRef.from_random(cls) | | nil() | ObjectRef.nil(cls) | | size() | ObjectRef.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from ray._raylet.BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from ray._raylet.BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes) | | from_hex(hex_id) | BaseID.from_hex(cls, hex_id)
ray.ObjectRefGenerator
Python Library Documentation: class ObjectRefGenerator in module ray
class ObjectRefGenerator(builtins.object)
| ObjectRefGenerator(generator_ref: "'ray.ObjectRef'", worker: "'Worker'")
|
| A generator to obtain object references from a task in a streaming manner.
|
| The class is compatible with the Python generator and async generator interfaces.
|
| The class is not thread-safe.
|
| Do not initialize the class and create an instance directly.
| The instance should be created by `.remote`.
|
| .. testcode::
|
| import ray
| from typing import Generator
|
| @ray.remote(num_returns="streaming")
| def gen() -> Generator[int, None, None]:
| for i in range(5):
| yield i
|
| obj_ref_gen: ray.ObjectRefGenerator = gen.remote()
| for obj_ref in obj_ref_gen:
| print("Got:", ray.get(obj_ref))
|
| Methods defined here:
|
| __aiter__(self) -> "'ObjectRefGenerator'" from ray._private.object_ref_generator.ObjectRefGenerator
|
| async __anext__(self) from ray._private.object_ref_generator.ObjectRefGenerator
|
| __del__(self) from ray._private.object_ref_generator.ObjectRefGenerator
|
| __getstate__(self) from ray._private.object_ref_generator.ObjectRefGenerator
| Helper for pickle.
|
| __init__(self, generator_ref: "'ray.ObjectRef'", worker: "'Worker'") from ray._private.object_ref_generator.ObjectRefGenerator
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> "'ObjectRefGenerator'" from ray._private.object_ref_generator.ObjectRefGenerator
|
| __next__(self) -> "'ray.ObjectRef'" from ray._private.object_ref_generator.ObjectRefGenerator
| Waits until a next ref is available and returns the object ref.
|
| Raises StopIteration if there's no more objects
| to generate.
|
| The object ref will contain an exception if the task fails.
| When the generator task returns N objects, it can return
| up to N + 1 objects (if there's a system failure, the
| last object will contain a system level exception).
|
| async aclose(self) from ray._private.object_ref_generator.ObjectRefGenerator
|
| async asend(self, value) from ray._private.object_ref_generator.ObjectRefGenerator
|
| async athrow(self, value) from ray._private.object_ref_generator.ObjectRefGenerator
|
| close(self) from ray._private.object_ref_generator.ObjectRefGenerator
|
| completed(self) -> "'ray.ObjectRef'" from ray._private.object_ref_generator.ObjectRefGenerator
| Returns an object ref that is ready when
| a generator task completes.
|
| If the task is failed unexpectedly (e.g., worker failure),
| the `ray.get(gen.completed())` raises an exception.
|
| The function returns immediately.
|
| is_finished(self) -> 'bool' from ray._private.object_ref_generator.ObjectRefGenerator
| If True, it means the generator is finished
| and all output is taken. False otherwise.
|
| When True, if next(gen) is called, it will raise StopIteration
| or StopAsyncIteration
|
| The function returns immediately.
|
| next_ready(self) -> 'bool' from ray._private.object_ref_generator.ObjectRefGenerator
| If True, it means the output of next(gen) is ready and
| ray.get(next(gen)) returns immediately. False otherwise.
|
| It returns False when next(gen) raises a StopIteration
| (this condition should be checked using is_finished).
|
| The function returns immediately.
|
| send(self, value) from ray._private.object_ref_generator.ObjectRefGenerator
|
| throw(self, value) from ray._private.object_ref_generator.ObjectRefGenerator
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
ray.PlacementGroupID
Python Library Documentation: class PlacementGroupID in module ray._raylet class PlacementGroupID(BaseID) | PlacementGroupID(id) | | Method resolution order: | PlacementGroupID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | binary(self) | PlacementGroupID.binary(self) | | hex(self) | PlacementGroupID.hex(self) | | is_nil(self) | PlacementGroupID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | PlacementGroupID.from_hex(cls, hex_id) | | from_random() | PlacementGroupID.from_random(cls) | | nil() | PlacementGroupID.nil(cls) | | of(job_id) | PlacementGroupID.of(cls, job_id) | | size() | PlacementGroupID.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.RESTORE_WORKER_MODE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
ray.SCRIPT_MODE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
ray.SPILL_WORKER_MODE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
ray.TaskID
Python Library Documentation: class TaskID in module ray._raylet class TaskID(BaseID) | TaskID(id) | | Method resolution order: | TaskID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | actor_id(self) | TaskID.actor_id(self) | | binary(self) | TaskID.binary(self) | | hex(self) | TaskID.hex(self) | | is_nil(self) | TaskID.is_nil(self) | | job_id(self) | TaskID.job_id(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | for_actor_creation_task(actor_id) | TaskID.for_actor_creation_task(cls, actor_id) | | for_actor_task(job_id, parent_task_id, parent_task_counter, actor_id) | TaskID.for_actor_task(cls, job_id, parent_task_id, parent_task_counter, actor_id) | | for_driver_task(job_id) | TaskID.for_driver_task(cls, job_id) | | for_fake_task(job_id) | TaskID.for_fake_task(cls, job_id) | | for_normal_task(job_id, parent_task_id, parent_task_counter) | TaskID.for_normal_task(cls, job_id, parent_task_id, parent_task_counter) | | from_hex(hex_id) | TaskID.from_hex(cls, hex_id) | | nil() | TaskID.nil(cls) | | size() | TaskID.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.UniqueID
Python Library Documentation: class UniqueID in module ray._raylet class UniqueID(BaseID) | UniqueID(id) | | Method resolution order: | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes) | | from_hex(hex_id) | BaseID.from_hex(cls, hex_id)
ray.WORKER_MODE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
ray.WorkerID
Python Library Documentation: class WorkerID in module ray._raylet class WorkerID(UniqueID) | WorkerID(id) | | Method resolution order: | WorkerID | UniqueID | BaseID | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Class methods defined here: | | from_hex(hex_id) | WorkerID.from_hex(cls, hex_id) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __pyx_vtable__ = <capsule object NULL> | | ---------------------------------------------------------------------- | Methods inherited from UniqueID: | | binary(self) | UniqueID.binary(self) | | hex(self) | UniqueID.hex(self) | | is_nil(self) | UniqueID.is_nil(self) | | ---------------------------------------------------------------------- | Class methods inherited from UniqueID: | | from_random() | UniqueID.from_random(cls) | | nil() | UniqueID.nil(cls) | | size() | UniqueID.size(cls) | | ---------------------------------------------------------------------- | Methods inherited from BaseID: | | __bytes__(self) | BaseID.__bytes__(self) | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(self) | BaseID.__reduce__(self) | | __repr__(...) | Return repr(self). | | __str__(self, /) | Return str(self). | | redis_shard_hash(self) | BaseID.redis_shard_hash(self) | | ---------------------------------------------------------------------- | Class methods inherited from BaseID: | | from_binary(id_bytes) | BaseID.from_binary(cls, id_bytes)
ray.available_resources
Python Library Documentation: function available_resources in module ray._private.state
available_resources()
Get the current available cluster resources.
This is different from `cluster_resources` in that this will return idle
(available) resources rather than total resources.
Note that this information can grow stale as tasks start and finish.
Returns:
A dictionary mapping resource name to the total quantity of that
resource in the cluster. Note that if a resource (e.g., "CPU")
is currently not available (i.e., quantity is 0), it will not
be included in this dictionary.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.cancel
Python Library Documentation: function cancel in module ray._private.worker
cancel(ray_waitable: Union[ForwardRef('ObjectRef[R]'), ForwardRef('ObjectRefGenerator[R]')], *, force: bool = False, recursive: bool = True) -> None
Cancels a task.
Cancel API has a different behavior depending on if it is a remote function
(Task) or a remote Actor method (Actor Task).
Task:
If the specified Task is pending execution, it is cancelled and not
executed. If the Task is currently executing, the behavior depends
on the `force` flag. When `force=False`, a KeyboardInterrupt is
raised in Python and when `force=True`, the executing Task
immediately exits. If the Task is already finished, nothing happens.
Cancelled Tasks aren't retried. `max_task_retries` aren't respected.
Calling ray.get on a cancelled Task raises a TaskCancelledError
if the Task has been scheduled or interrupted.
It raises a WorkerCrashedError if `force=True`.
If `recursive=True`, all the child Tasks and Actor Tasks
are cancelled. If `force=True` and `recursive=True`, `force=True`
is ignored for child Actor Tasks.
Actor Task:
If the specified Task is pending execution, it is cancelled and not
executed. If the Task is currently executing, the behavior depends
on the execution model of an Actor. If it is a regular Actor
or a threaded Actor, Ray sets a cancellation flag that can be checked
via `ray.get_runtime_context().is_canceled()` within the task body.
This allows for graceful cancellation by periodically checking the
cancellation status. If it is an async Actor, Ray cancels a `asyncio.Task`.
The semantic of cancellation is equivalent to asyncio's cancellation.
https://docs.python.org/3/library/asyncio-task.html#task-cancellation
Note: `is_canceled()` is not supported for async actors and will raise
a RuntimeError. If the Task has finished, nothing happens.
Only `force=False` is allowed for an Actor Task. Otherwise, it raises
`ValueError`. Use `ray.kill(actor)` instead to kill an Actor.
Cancelled Tasks aren't retried. `max_task_retries` aren't respected.
Calling ray.get on a cancelled Task raises a TaskCancelledError
if the Task has been scheduled or interrupted.
If `recursive=True`, all the child Tasks and actor Tasks
are cancelled.
Args:
ray_waitable: :class:`~ObjectRef` and
:class:`~ObjectRefGenerator`
returned by the task that should be canceled.
force: Whether to force-kill a running task by killing
the worker that is running the task.
recursive: Whether to try to cancel tasks submitted by the
task specified.
ray.client
Python Library Documentation: function client in module ray.client_builder
client(address: Optional[str] = None, _deprecation_warn_enabled: bool = True) -> ray.client_builder.ClientBuilder
Creates a ClientBuilder based on the provided address. The address can be
of the following forms:
* None: Connects to or creates a local cluster and connects to it.
* ``"local"``: Creates a new cluster locally and connects to it.
* ``"IP:Port"``: Connects to a Ray Client Server at the given address.
* ``"module://inner_address"``: load module.ClientBuilder & pass
inner_address
The _deprecation_warn_enabled flag enables deprecation warnings, and is
for internal use only. Set it to False to suppress client deprecation
warnings.
.. warning::
**DEPRECATED**: This API is deprecated and may be removed in future Ray releases.
ray.cluster_resources
Python Library Documentation: function cluster_resources in module ray._private.state
cluster_resources()
Get the current total cluster resources.
Note that this information can grow stale as nodes are added to or removed
from the cluster.
Returns:
A dictionary mapping resource name to the total quantity of that
resource in the cluster.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.get
Python Library Documentation: function get in module ray._private.worker
get(object_refs: Union[ForwardRef('ObjectRef[Any]'), Sequence[ForwardRef('ObjectRef[Any]')], ray.experimental.compiled_dag_ref.CompiledDAGRef, Sequence[ray.experimental.compiled_dag_ref.CompiledDAGRef]], *, timeout: Optional[float] = None, _use_object_store: bool = False) -> Union[Any, List[Any]]
Get a remote object or a list of remote objects from the object store.
This method blocks until the object corresponding to the object ref is
available in the local object store. If this object is not in the local
object store, it will be shipped from an object store that has it (once the
object has been created). If object_refs is a list, then the objects
corresponding to each object in the list will be returned.
Ordering for an input list of object refs is preserved for each object
returned. That is, if an object ref to A precedes an object ref to B in the
input list, then A will precede B in the returned list.
This method will issue a warning if it's running inside async context,
you can use ``await object_ref`` instead of ``ray.get(object_ref)``. For
a list of object refs, you can use ``await asyncio.gather(*object_refs)``.
Passing :class:`~ObjectRefGenerator` is not allowed.
Related patterns and anti-patterns:
- :doc:`/ray-core/patterns/ray-get-loop`
- :doc:`/ray-core/patterns/unnecessary-ray-get`
- :doc:`/ray-core/patterns/ray-get-submission-order`
- :doc:`/ray-core/patterns/ray-get-too-many-objects`
Args:
object_refs: Object ref of the object to get or a list of object refs
to get.
timeout: The maximum amount of time in seconds to
wait before returning. Set this to None will block until the
corresponding object becomes available. Setting ``timeout=0`` will
return the object immediately if it's available, else raise
GetTimeoutError in accordance with the above docstring.
_use_object_store: [Alpha] To fetch an RDT object through the object store
instead of using its designated tensor transport. You can set this to True
for cases where the caller does not support the object's tensor transport,
e.g., the tensor transport is "nccl" and the caller is not part of the collective.
When this is False (default), Ray will use the object store for normal objects,
and attempt to use the object's tensor transport for RDT objects.
Returns:
A Python object or a list of Python objects.
Raises:
GetTimeoutError: A GetTimeoutError is raised if a timeout is set and
the get takes longer than timeout to return.
Exception: An exception is raised immediately if any task that created
the object or that created one of the objects raised an exception,
without waiting for the remaining ones to finish.
ray.get_actor
Python Library Documentation: function get_actor in module ray._private.worker
get_actor(name: str, namespace: Optional[str] = None) -> 'ray.actor.ActorHandle'
Get a handle to a named actor.
Gets a handle to an actor with the given name. The actor must
have been created with Actor.options(name="name").remote(). This
works for both detached & non-detached actors.
This method is a sync call and it'll timeout after 60s. This can be modified
by setting OS env RAY_gcs_server_request_timeout_seconds before starting
the cluster.
Args:
name: The name of the actor.
namespace: The namespace of the actor, or None to specify the current
namespace.
Returns:
ActorHandle to the actor.
Raises:
ValueError: if the named actor does not exist.
ray.get_gpu_ids
Python Library Documentation: function get_gpu_ids in module ray._private.worker
get_gpu_ids() -> Union[List[int], List[str]]
Get the IDs of the GPUs that are available to the worker.
This method should only be called inside of a task or actor, and not a driver.
If the CUDA_VISIBLE_DEVICES environment variable was set when the worker
started up, then the IDs returned by this method will be a subset of the
IDs in CUDA_VISIBLE_DEVICES. If not, the IDs will fall in the range
[0, NUM_GPUS - 1], where NUM_GPUS is the number of GPUs that the node has.
Returns:
A list of GPU IDs.
ray.get_runtime_context
Python Library Documentation: function get_runtime_context in module ray.runtime_context
get_runtime_context() -> ray.runtime_context.RuntimeContext
Get the runtime context of the current driver/worker.
The obtained runtime context can be used to get the metadata
of the current driver, task, or actor.
Example:
.. testcode::
import ray
# Get the job id.
ray.get_runtime_context().get_job_id()
# Get the session name (used as SessionName label in Ray metrics).
ray.get_runtime_context().get_session_name()
# Get the actor id.
ray.get_runtime_context().get_actor_id()
# Get the task id.
ray.get_runtime_context().get_task_id()
ray.init
Python Library Documentation: function init in module ray._private.worker
init(address: Optional[str] = None, *, num_cpus: Optional[int] = None, num_gpus: Optional[int] = None, resources: Optional[Dict[str, float]] = None, labels: Optional[Dict[str, str]] = None, object_store_memory: Optional[int] = None, local_mode: bool = False, ignore_reinit_error: bool = False, include_dashboard: Optional[bool] = None, dashboard_host: str = '127.0.0.1', dashboard_port: Optional[int] = None, job_config: 'ray.job_config.JobConfig' = None, configure_logging: bool = True, logging_level: int = 'info', logging_format: Optional[str] = None, logging_config: Optional[ray._private.ray_logging.logging_config.LoggingConfig] = None, log_to_driver: Optional[bool] = None, namespace: Optional[str] = None, runtime_env: Union[Dict[str, Any], ForwardRef('RuntimeEnv'), NoneType] = None, enable_resource_isolation: bool = False, cgroup_path: Optional[str] = None, system_reserved_cpu: Optional[float] = None, system_reserved_memory: Optional[int] = None, proxy_server_url: Optional[str] = None, **kwargs) -> ray._private.worker.BaseContext
Connect to an existing Ray cluster or start one and connect to it.
This method handles two cases; either a Ray cluster already exists and we
just attach this driver to it or we start all of the processes associated
with a Ray cluster and attach to the newly started cluster.
Note: This method overwrite sigterm handler of the driver process.
In most cases, it is enough to just call this method with no arguments.
This will autodetect an existing Ray cluster or start a new Ray instance if
no existing cluster is found:
.. testcode::
ray.init()
To explicitly connect to an existing local cluster, use this as follows. A
ConnectionError will be thrown if no existing local cluster is found.
.. testcode::
:skipif: True
ray.init(address="auto")
To connect to an existing remote cluster, use this as follows (substituting
in the appropriate address). Note the addition of "ray://" at the beginning
of the address. This requires `ray[client]`.
.. testcode::
:skipif: True
ray.init(address="ray://123.45.67.89:10001")
More details for starting and connecting to a remote cluster can be found
here: https://docs.ray.io/en/master/cluster/getting-started.html
You can also define an environment variable called `RAY_ADDRESS` in
the same format as the `address` parameter to connect to an existing
cluster with ray.init() or ray.init(address="auto").
Args:
address: The address of the Ray cluster to connect to. The provided
address is resolved as follows:
1. If a concrete address (e.g., localhost:<port>) is provided, try to
connect to it. Concrete addresses can be prefixed with "ray://" to
connect to a remote cluster. For example, passing in the address
"ray://123.45.67.89:50005" will connect to the cluster at the given
address.
2. If no address is provided, try to find an existing Ray instance
to connect to. This is done by first checking the environment
variable `RAY_ADDRESS`. If this is not defined, check the address
of the latest cluster started (found in
/tmp/ray/ray_current_cluster) if available. If this is also empty,
then start a new local Ray instance.
3. If the provided address is "auto", then follow the same process
as above. However, if there is no existing cluster found, this will
throw a ConnectionError instead of starting a new local Ray
instance.
4. If the provided address is "local", start a new local Ray
instance, even if there is already an existing local Ray instance.
num_cpus: Number of CPUs the user wishes to assign to each
raylet. By default, this is set based on virtual cores.
num_gpus: Number of GPUs the user wishes to assign to each
raylet. By default, this is set based on detected GPUs.
resources: A dictionary mapping the names of custom resources to the
quantities for them available.
labels: [Experimental] The key-value labels of the node.
object_store_memory: The amount of memory (in bytes) to start the
object store with.
By default, this is 30% of available system memory capped by
the shm size and 200G but can be set higher.
local_mode: No longer supported. For interactive debugging consider
using the Ray distributed debugger.
ignore_reinit_error: If true, Ray suppresses errors from calling
ray.init() a second time. Ray won't be restarted.
include_dashboard: Boolean flag indicating whether or not to start the
Ray dashboard, which displays the status of the Ray
cluster. If this argument is None, then the UI will be started if
the relevant dependencies are present.
dashboard_host: The host to bind the dashboard server to. Use localhost
(127.0.0.1/::1) for local access only, or 0.0.0.0/:: for all
interfaces. Defaults to localhost.
dashboard_port: The port to bind the dashboard server to.
Defaults to 8265 and Ray will automatically find a free port if
8265 is not available.
job_config: The job configuration.
configure_logging: True (default) if configuration of logging is
allowed here. Otherwise, the user may want to configure it
separately.
logging_level: Logging level for the "ray" logger of the driver process,
defaults to logging.INFO. Ignored unless "configure_logging" is true.
logging_format: Logging format for the "ray" logger of the driver process,
defaults to a string containing a timestamp, filename, line number, and
message. See the source file ray_constants.py for details. Ignored unless
"configure_logging" is true.
logging_config: [Experimental] Logging configuration will be applied to the
root loggers for both the driver process and all worker processes belonging
to the current job. See :class:`~ray.LoggingConfig` for details.
log_to_driver: If true, the output from all of the worker
processes on all nodes will be directed to the driver.
namespace: A namespace is a logical grouping of jobs and named actors.
runtime_env: The runtime environment to use
for this job (see :ref:`runtime-environments` for details).
enable_resource_isolation: Enable resource isolation through cgroupv2 by reserving
memory and cpu resources for ray system processes. To use, only cgroupv2 (not cgroupv1)
must be enabled with read and write permissions for the raylet. Cgroup memory and
cpu controllers must also be enabled.
cgroup_path: The path for the cgroup the raylet should use to enforce resource isolation.
By default, the cgroup used for resource isolation will be /sys/fs/cgroup.
The process starting ray must have read/write permissions to this path.
Cgroup memory and cpu controllers must be enabled for this cgroup.
This option only works if enable_resource_isolation is True.
system_reserved_cpu: The number of cpu cores to reserve for ray system processes.
Cores can be fractional i.e. 1.5 means one and a half a cpu core.
By default, the value will be atleast 1 core, and at maximum 3 cores. The default value
is calculated using the formula min(3.0, max(1.0, 0.05 * num_cores_on_the_system))
This option only works if enable_resource_isolation is True.
system_reserved_memory: The amount of memory (in bytes) to reserve for ray system processes.
By default, the value will be atleast 500MB, and at most 10GB. The default value is
calculated using the formula min(10GB, max(500MB, 0.10 * memory_available_on_the_system))
This option only works if enable_resource_isolation is True.
proxy_server_url: [Experimental] The server url to redirect dashboard backend requests to.
By default, the dashboard requests will be directed to the Ray api server.
If you have a custom server to serve the dashboard requests,
you can set this option to override the server url.
Ex: proxy_server_url=http://historyserver:8080
**kwargs: Hidden / experimental options. Recognized keys include
``object_spilling_directory`` (path to spill objects to; defaults
to the node's session dir),
``_enable_object_reconstruction`` (reconstruct lost objects by
re-executing their task),
``_plasma_directory`` (override the plasma mmap file directory),
``_node_ip_address`` (the IP address of this node),
``_driver_object_store_memory`` (deprecated),
``_memory`` (reservable memory resource in bytes),
``_redis_username`` / ``_redis_password`` (Redis auth),
``_temp_dir`` (root temp directory; must be absolute),
``_metrics_export_port`` (Prometheus metrics port),
``_system_config`` (RayConfig override dict; testing only),
``_tracing_startup_hook`` (callable to set up tracing), and
``_node_name`` (user-provided node identifier). These options
are unstable and may change without notice.
Returns:
If the provided address includes a protocol, for example by prepending
"ray://" to the address to get "ray://1.2.3.4:10001", then a
ClientContext is returned with information such as settings, server
versions for ray and python, and the dashboard_url. Otherwise,
a RayContext is returned with ray and python versions, and address
information about the started processes.
Raises:
Exception: An exception is raised if an inappropriate combination of
arguments is passed in.
ray.is_initialized
Python Library Documentation: function is_initialized in module ray._private.worker
is_initialized() -> bool
Check if ray.init has been called yet.
Returns:
True if ray.init has already been called and false otherwise.
ray.java_actor_class
Python Library Documentation: function java_actor_class in module ray.cross_language
java_actor_class(class_name: str)
Define a Java actor class.
Args:
class_name: Java class name.
**PublicAPI (beta):** This API is in beta and may change before becoming stable.
ray.java_function
Python Library Documentation: function java_function in module ray.cross_language
java_function(class_name: str, function_name: str)
Define a Java function.
Args:
class_name: Java class name.
function_name: Java function name.
**PublicAPI (beta):** This API is in beta and may change before becoming stable.
ray.kill
Python Library Documentation: function kill in module ray._private.worker
kill(actor: 'ray.actor.ActorHandle', *, no_restart: bool = True)
Kill an actor forcefully.
This will interrupt any running tasks on the actor, causing them to fail
immediately. ``atexit`` handlers installed in the actor will not be run.
If you want to kill the actor but let pending tasks finish,
you can call ``actor.__ray_terminate__.remote()`` instead to queue a
termination task. Any ``atexit`` handlers installed in the actor *will*
be run in this case.
If the actor is a detached actor, subsequent calls to get its handle via
ray.get_actor will fail.
Args:
actor: Handle to the actor to kill.
no_restart: Whether or not this actor should be restarted if
it's a restartable actor.
ray.logger
Python Library Documentation: Logger in module logging object
class Logger(Filterer)
| Logger(name, level=0)
|
| Instances of the Logger class represent a single logging channel. A
| "logging channel" indicates an area of an application. Exactly how an
| "area" is defined is up to the application developer. Since an
| application can have any number of areas, logging channels are identified
| by a unique string. Application areas can be nested (e.g. an area
| of "input processing" might include sub-areas "read CSV files", "read
| XLS files" and "read Gnumeric files"). To cater for this natural nesting,
| channel names are organized into a namespace hierarchy where levels are
| separated by periods, much like the Java or Python package namespace. So
| in the instance given above, channel names might be "input" for the upper
| level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels.
| There is no arbitrary limit to the depth of nesting.
|
| Method resolution order:
| Logger
| Filterer
| builtins.object
|
| Methods defined here:
|
| __init__(self, name, level=0)
| Initialize the logger with a name and an optional level.
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| addHandler(self, hdlr)
| Add the specified handler to this logger.
|
| callHandlers(self, record)
| Pass a record to all relevant handlers.
|
| Loop through all handlers for this logger and its parents in the
| logger hierarchy. If no handler was found, output a one-off error
| message to sys.stderr. Stop searching up the hierarchy whenever a
| logger with the "propagate" attribute set to zero is found - that
| will be the last logger whose handlers are called.
|
| critical(self, msg, *args, **kwargs)
| Log 'msg % args' with severity 'CRITICAL'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.critical("Houston, we have a %s", "major disaster", exc_info=True)
|
| debug(self, msg, *args, **kwargs)
| Log 'msg % args' with severity 'DEBUG'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.debug("Houston, we have a %s", "thorny problem", exc_info=True)
|
| error(self, msg, *args, **kwargs)
| Log 'msg % args' with severity 'ERROR'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.error("Houston, we have a %s", "major problem", exc_info=True)
|
| exception(self, msg, *args, exc_info=True, **kwargs)
| Convenience method for logging an ERROR with exception information.
|
| fatal(self, msg, *args, **kwargs)
| Don't use this method, use critical() instead.
|
| findCaller(self, stack_info=False, stacklevel=1)
| Find the stack frame of the caller so that we can note the source
| file name, line number and function name.
|
| getChild(self, suffix)
| Get a logger which is a descendant to this one.
|
| This is a convenience method, such that
|
| logging.getLogger('abc').getChild('def.ghi')
|
| is the same as
|
| logging.getLogger('abc.def.ghi')
|
| It's useful, for example, when the parent logger is named using
| __name__ rather than a literal string.
|
| getChildren(self)
|
| getEffectiveLevel(self)
| Get the effective level for this logger.
|
| Loop through this logger and its parents in the logger hierarchy,
| looking for a non-zero logging level. Return the first one found.
|
| handle(self, record)
| Call the handlers for the specified record.
|
| This method is used for unpickled records received from a socket, as
| well as those created locally. Logger-level filtering is applied.
|
| hasHandlers(self)
| See if this logger has any handlers configured.
|
| Loop through all handlers for this logger and its parents in the
| logger hierarchy. Return True if a handler was found, else False.
| Stop searching up the hierarchy whenever a logger with the "propagate"
| attribute set to zero is found - that will be the last logger which
| is checked for the existence of handlers.
|
| info(self, msg, *args, **kwargs)
| Log 'msg % args' with severity 'INFO'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.info("Houston, we have a %s", "notable problem", exc_info=True)
|
| isEnabledFor(self, level)
| Is this logger enabled for level 'level'?
|
| log(self, level, msg, *args, **kwargs)
| Log 'msg % args' with the integer severity 'level'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.log(level, "We have a %s", "mysterious problem", exc_info=True)
|
| makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)
| A factory method which can be overridden in subclasses to create
| specialized LogRecords.
|
| removeHandler(self, hdlr)
| Remove the specified handler from this logger.
|
| setLevel(self, level)
| Set the logging level of this logger. level must be an int or a str.
|
| warn(self, msg, *args, **kwargs)
|
| warning(self, msg, *args, **kwargs)
| Log 'msg % args' with severity 'WARNING'.
|
| To pass exception information, use the keyword argument exc_info with
| a true value, e.g.
|
| logger.warning("Houston, we have a %s", "bit of a problem", exc_info=True)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| manager = <logging.Manager object>
|
| root = <RootLogger root (WARNING)>
|
| ----------------------------------------------------------------------
| Methods inherited from Filterer:
|
| addFilter(self, filter)
| Add the specified filter to this handler.
|
| filter(self, record)
| Determine if a record is loggable by consulting all the filters.
|
| The default is to allow the record to be logged; any filter can veto
| this by returning a false value.
| If a filter attached to a handler returns a log record instance,
| then that instance is used in place of the original log record in
| any further processing of the event by that handler.
| If a filter returns any other true value, the original log record
| is used in any further processing of the event by that handler.
|
| If none of the filters return false values, this method returns
| a log record.
| If any of the filters return a false value, this method returns
| a false value.
|
| .. versionchanged:: 3.2
|
| Allow filters to be just callables.
|
| .. versionchanged:: 3.12
| Allow filters to return a LogRecord instead of
| modifying it in place.
|
| removeFilter(self, filter)
| Remove the specified filter from this handler.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Filterer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
ray.method
Python Library Documentation: function method in module ray.actor
method(*args, **kwargs)
Annotate an actor method.
.. code-block:: python
@ray.remote
class Foo:
@ray.method(num_returns=2)
def bar(self):
return 1, 2
f = Foo.remote()
_, _ = f.bar.remote()
Args:
num_returns: The number of object refs that should be returned by
invocations of this actor method. The default value is 1 for a
normal actor task and "streaming" for an actor generator task (a
function that yields objects instead of returning them).
max_task_retries: How many times to retry an actor task if the task
fails due to a runtime error, e.g., the actor has died. The
default value is 0. If set to -1, the system will retry the
failed task until the task succeeds, or the actor has reached
its max_restarts limit. If set to `n > 0`, the system will retry
the failed task up to n times, after which the task will throw a
`RayActorError` exception upon :obj:`ray.get`. Note that Python
exceptions may trigger retries
*only if* `retry_exceptions` is set for the method, in that case
when `max_task_retries` runs out the task will rethrow the
exception from the task. You can override this number with the
method's `max_task_retries` option in `@ray.method` decorator or
in `.option()`.
retry_exceptions: Boolean of whether to retry all Python
exceptions, or a list of allowlist exceptions to retry. The default
value is False (only retry tasks upon system failures and if
max_task_retries is set)
concurrency_group: The name of the concurrency group
to use for the actor method. By default, the actor is
single-threaded and runs all actor tasks on the same thread.
See :ref:`Defining Concurrency Groups <defining-concurrency-groups>`.
tensor_transport: [Alpha] The tensor transport protocol to
use for the actor method. If a tensor transport is specified,
Ray will store a *reference* instead of a copy of any torch.Tensors found inside
values returned by this task, and the tensors will be sent directly
to other tasks using the specified transport. The object store will be used
when this is None (default). "NIXL", "NCCL", and "GLOO" (case-insensitive) are
the three transports supported by default. The NCCL and GLOO transports
require first creating a collective with the involved actors using
:func:`ray.experimental.collective.create_collective_group`.
See :ref:`Ray Direct Transport (RDT) <direct-transport>` for more
details.
ray.nodes
Python Library Documentation: function nodes in module ray._private.state
nodes()
Get a list of the nodes in the cluster (for debugging only).
Returns:
Information about the Ray clients in the cluster.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.put
Python Library Documentation: function put in module ray._private.worker
put(value: ~R, *, _owner: Optional[ForwardRef('ray.actor.ActorHandle')] = None, _tensor_transport: Optional[str] = None) -> 'ray.ObjectRef[R]'
Store an object in the object store.
The object may not be evicted while a reference to the returned ID exists.
Related patterns and anti-patterns:
- :doc:`/ray-core/patterns/return-ray-put`
- :doc:`/ray-core/patterns/pass-large-arg-by-value`
- :doc:`/ray-core/patterns/closure-capture-large-objects`
Args:
value: The Python object to be stored.
_owner: This experimental argument has been removed in Ray 2.56.
_tensor_transport: [Alpha] The tensor transport to use for the GPU object.
Currently, this only supports one-sided tensor transports such as "nixl".
When this is None (default), Ray will use the object store.
Returns:
The object ref assigned to this value.
ray.ray_constants
Python Library Documentation: _DeprecationWrapper in ray._private object ray._private.ray_constants = class _DeprecationWrapper(builtins.object) | ray._private.ray_constants(name, real_worker) | | Methods defined here: | | __getattr__(self, attr) | | __init__(self, name, real_worker) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
ray.remote
Python Library Documentation: function remote in module ray._private.worker
remote(*args: Any, **kwargs: Any) -> Union[ray.remote_function.RemoteFunction, ray.actor.ActorClass]
Defines a remote function or an actor class.
This function can be used as a decorator with no arguments
to define a remote function or actor as follows:
.. testcode::
import ray
@ray.remote
def f(a, b, c):
return a + b + c
object_ref = f.remote(1, 2, 3)
result = ray.get(object_ref)
assert result == (1 + 2 + 3)
@ray.remote
class Foo:
def __init__(self, arg):
self.x = arg
def method(self, a):
return self.x + a
actor_handle = Foo.remote(123)
object_ref = actor_handle.method.remote(321)
result = ray.get(object_ref)
assert result == (123 + 321)
Equivalently, use a function call to create a remote function or actor.
.. testcode::
def g(a, b, c):
return a + b + c
remote_g = ray.remote(g)
object_ref = remote_g.remote(1, 2, 3)
assert ray.get(object_ref) == (1 + 2 + 3)
class Bar:
def __init__(self, arg):
self.x = arg
def method(self, a):
return self.x + a
RemoteBar = ray.remote(Bar)
actor_handle = RemoteBar.remote(123)
object_ref = actor_handle.method.remote(321)
result = ray.get(object_ref)
assert result == (123 + 321)
It can also be used with specific keyword arguments as follows:
.. testcode::
@ray.remote(num_gpus=1, max_calls=1, num_returns=2)
def f():
return 1, 2
@ray.remote(num_cpus=2, resources={"CustomResource": 1})
class Foo:
def method(self):
return 1
Remote task and actor objects returned by @ray.remote can also be
dynamically modified with the same arguments as above using
``.options()`` as follows:
.. testcode::
:hide:
ray.shutdown()
ray.init(num_cpus=5, num_gpus=5)
.. testcode::
@ray.remote(num_gpus=1, max_calls=1, num_returns=2)
def f():
return 1, 2
f_with_2_gpus = f.options(num_gpus=2)
object_refs = f_with_2_gpus.remote()
assert ray.get(object_refs) == [1, 2]
@ray.remote(num_cpus=2, resources={"CustomResource": 1})
class Foo:
def method(self):
return 1
Foo_with_no_resources = Foo.options(num_cpus=1, resources=None)
foo_actor = Foo_with_no_resources.remote()
assert ray.get(foo_actor.method.remote()) == 1
A remote actor will be terminated when all actor handle to it
in Python is deleted, which will cause them to complete any outstanding
work and then shut down. If you only have 1 reference to an actor handle,
calling ``del actor`` *could* trigger actor deletion. Note that your program
may have multiple references to the same ActorHandle, and actor termination
will not occur until the reference count goes to 0. See the Python
documentation for more context about object deletion.
https://docs.python.org/3.9/reference/datamodel.html#object.__del__
If you want to kill actors immediately, you can also call ``ray.kill(actor)``.
.. tip::
Avoid repeatedly passing in large arguments to remote task or method calls.
Instead, use ray.put to create a copy of the object in the object store.
See :ref:`more info here <ray-pass-large-arg-by-value>`.
Args:
*args: When used as a bare decorator (``@ray.remote``), the single
positional argument is the function or class being decorated.
**kwargs: When used with options (``@ray.remote(...)`` or
``ray.remote(...)``), the decorator options. Accepted keys:
- ``num_returns``: *remote functions only*. Number of object refs
returned by the remote function invocation. The default is 1.
Pass ``"dynamic"`` to allow the task to decide at runtime;
callers receive an ``ObjectRef[DynamicObjectRefGenerator]``.
See :ref:`dynamic generators <dynamic-generators>` for details.
- ``num_cpus``: CPU resources to reserve for the task or actor.
By default, tasks use 1 CPU resource and actors use 1 CPU for
scheduling and 0 CPU for running. See
:ref:`specifying resource requirements <resource-requirements>`.
- ``num_gpus``: GPU resources to reserve. Default is 0.
See :ref:`Ray GPU support <gpu-support>`.
- ``resources``: Dict of :ref:`custom resources <custom-resources>`
mapping resource names to float quantities.
- ``label_selector``: [Experimental] Labels required for the node
this actor can be scheduled on (key-value expressions).
- ``fallback_strategy``: [Experimental] Soft scheduling constraints
expressed as a list of decorator-option dicts. Currently only
``label_selector`` is supported.
- ``accelerator_type``: Require a node with the specified
accelerator type. See :ref:`accelerator types <accelerator_types>`.
- ``memory``: Heap memory request in bytes for this task/actor.
- ``max_calls``: *remote functions only*. Maximum number of times
a worker can execute this function before it must exit. By
default infinite for CPU tasks and 1 for GPU tasks.
- ``max_restarts``: *actors only*. Maximum number of times the
actor should be restarted when it dies unexpectedly. ``-1``
means restart indefinitely.
- ``max_task_retries``: *actors only*. How many times to retry
an actor task if it fails due to a system error.
- ``max_retries``: *remote functions only*. Maximum number of
times to rerun the function when the worker crashes
unexpectedly. Default is 3; ``-1`` means infinite retries.
- ``allow_out_of_order_execution``: *actors only*. Whether Ray
may execute actor tasks out of order.
- ``runtime_env``: Runtime environment for this actor or task and
its children. See :ref:`runtime-environments`.
- ``retry_exceptions``: *remote functions only*. Whether
application-level errors should be retried up to ``max_retries``
times, or a list of allow-listed exceptions to retry.
- ``scheduling_strategy``: How to schedule the remote function or
actor. See :ref:`Ray scheduling strategies
<ray-scheduling-strategies>`.
- ``_labels``: Key-value labels for the task or actor.
Returns:
The decorated remote function or actor class, or a decorator that
applies the supplied options when used as ``@ray.remote(...)``.
ray.serialization
Python Library Documentation: _DeprecationWrapper in ray._private object ray._private.serialization = class _DeprecationWrapper(builtins.object) | ray._private.serialization(name, real_worker) | | Methods defined here: | | __getattr__(self, attr) | | __init__(self, name, real_worker) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
ray.shutdown
Python Library Documentation: function shutdown in module ray._private.worker
shutdown(_exiting_interpreter: bool = False)
Disconnect the worker, and terminate processes started by ray.init().
This will automatically run at the end when a Python process that uses Ray
exits. It is ok to run this twice in a row. The primary use case for this
function is to cleanup state between tests.
Note that this will clear any remote function definitions, actor
definitions, and existing actors, so if you wish to use any previously
defined remote functions or actors after calling ray.shutdown(), then you
need to redefine them. If they were defined in an imported module, then you
will need to reload the module.
.. note::
The behavior of ``ray.shutdown()`` differs depending on how the cluster
was initialized:
* If a new local Ray cluster was started by ``ray.init()`` (i.e., no
``address`` argument was provided and no existing cluster was found,
or ``address="local"`` was explicitly used), ``ray.shutdown()`` will
terminate all the local Ray processes (raylet, object store, etc.)
that were spawned by ``ray.init()``.
* If you connected to an existing cluster (e.g., via
``ray.init(address="auto")`` or ``ray.init(address="ray://<ip>:<port>")``),
``ray.shutdown()`` will only disconnect the client from the cluster.
It will **not** shut down the remote cluster. The cluster will
continue running and can be connected to again.
Args:
_exiting_interpreter: True if this is called by the atexit hook
and false otherwise. If we are exiting the interpreter, we will
wait a little while to print any extra error messages.
ray.state
Python Library Documentation: _DeprecationWrapper in ray._private object ray._private.state = class _DeprecationWrapper(builtins.object) | ray._private.state(name, real_worker) | | Methods defined here: | | __getattr__(self, attr) | | __init__(self, name, real_worker) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
ray.timeline
Python Library Documentation: function timeline in module ray._private.state
timeline(filename: Optional[str] = None)
Return a list of profiling events that can viewed as a timeline.
Ray profiling must be enabled by setting the RAY_PROFILING=1 environment
variable prior to starting Ray, and set RAY_task_events_report_interval_ms=0
To view this information as a timeline, simply dump it as a json file by
passing in "filename" or using json.dump, and then load go to
chrome://tracing in the Chrome web browser and load the dumped file.
Args:
filename: If a filename is provided, the timeline is dumped to that
file.
Returns:
If filename is not provided, this returns a list of profiling events.
Each profile event is a dictionary.
Raises:
RuntimeError: An exception is raised if ray.init() has not been called yet.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.wait
Python Library Documentation: function wait in module ray._private.worker
wait(ray_waitables: List[Union[ray.ObjectRef, ray.ObjectRefGenerator]], *, num_returns: int = 1, timeout: Optional[float] = None, fetch_local: bool = True) -> Tuple[List[Union[ray.ObjectRef, ray.ObjectRefGenerator]], List[Union[ray.ObjectRef, ray.ObjectRefGenerator]]]
Return a list of IDs that are ready and a list of IDs that are not.
If timeout is set, the function returns either when the requested number of
IDs are ready or when the timeout is reached, whichever occurs first. If it
is not set, the function simply waits until that number of objects is ready
and returns that exact number of object refs.
`ray_waitables` is a list of :class:`~ray.ObjectRef` and
:class:`~ray.ObjectRefGenerator`.
The method returns two lists, ready and unready `ray_waitables`.
ObjectRef:
object refs that correspond to objects that are available
in the object store are in the first list.
The rest of the object refs are in the second list.
ObjectRefGenerator:
Generators whose next reference (that will be obtained
via `next(generator)`) has a corresponding object available
in the object store are in the first list.
All other generators are placed in the second list.
Ordering of the input list of ray_waitables is preserved. That is, if A
precedes B in the input list, and both are in the ready list, then A will
precede B in the ready list. This also holds true if A and B are both in
the remaining list.
This method will issue a warning if it's running inside an async context.
Instead of ``ray.wait(ray_waitables)``, you can use
``await asyncio.wait(ray_waitables)``.
Related patterns and anti-patterns:
- :doc:`/ray-core/patterns/limit-pending-tasks`
- :doc:`/ray-core/patterns/ray-get-submission-order`
Args:
ray_waitables: List of :class:`~ObjectRef` or
:class:`~ObjectRefGenerator` for objects that may or may
not be ready. Note that these must be unique.
num_returns: The number of ray_waitables that should be returned.
timeout: The maximum amount of time in seconds to wait before
returning.
fetch_local: If True, wait for the object to be downloaded onto
the local node before returning it as ready. If the `ray_waitable`
is a generator, it will wait until the next object in the generator
is downloaed. If False, ray.wait() will not trigger fetching of
objects to the local node and will return immediately once the
object is available anywhere in the cluster.
Returns:
A list of object refs that are ready and a list of the remaining object
IDs.
ray.worker
Python Library Documentation: _DeprecationWrapper in ray._private object ray._private.worker = class _DeprecationWrapper(builtins.object) | ray._private.worker(name, real_worker) | | Methods defined here: | | __getattr__(self, attr) | | __init__(self, name, real_worker) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
ray.util.ActorPool
Python Library Documentation: class ActorPool in module ray.util.actor_pool
class ActorPool(builtins.object)
| ActorPool(actors: list)
|
| Utility class to operate on a fixed pool of actors.
|
| Arguments:
| actors: List of Ray actor handles to use in this pool.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| print(list(pool.map(lambda a, v: a.double.remote(v),
| [1, 2, 3, 4])))
|
| .. testoutput::
|
| [2, 4, 6, 8]
|
| **DeveloperAPI:** This API may change across minor Ray releases.
|
| Methods defined here:
|
| __init__(self, actors: list)
| Initialize self. See help(type(self)) for accurate signature.
|
| get_next(self, timeout: Optional[float] = None, ignore_if_timedout: bool = False)
| Returns the next pending result in order.
|
| This returns the next result produced by submit(), blocking for up to
| the specified timeout until it is available.
|
| Arguments:
| timeout: Max seconds to wait for the next result. ``None`` waits
| indefinitely.
| ignore_if_timedout: When True, drop the timed-out task and raise
| ``TimeoutError`` after advancing past it instead of leaving it
| in place.
|
| Returns:
| The next result.
|
| Raises:
| TimeoutError: if the timeout is reached.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| print(pool.get_next())
|
| .. testoutput::
|
| 2
|
| get_next_unordered(self, timeout: Optional[float] = None, ignore_if_timedout: bool = False)
| Returns any of the next pending results.
|
| This returns some result produced by submit(), blocking for up to
| the specified timeout until it is available. Unlike get_next(), the
| results are not always returned in same order as submitted, which can
| improve performance.
|
| Arguments:
| timeout: Max seconds to wait for the next result. ``None`` waits
| indefinitely.
| ignore_if_timedout: When True, drop the timed-out task and raise
| ``TimeoutError`` after advancing past it instead of leaving it
| in place.
|
| Returns:
| The next result.
|
| Raises:
| TimeoutError: if the timeout is reached.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| pool.submit(lambda a, v: a.double.remote(v), 2)
| print(pool.get_next_unordered())
| print(pool.get_next_unordered())
|
| .. testoutput::
| :options: +MOCK
|
| 4
| 2
|
| has_free(self)
| Returns whether there are any idle actors available.
|
| Returns:
| True if there are any idle actors and no pending submits.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1 = Actor.remote()
| pool = ActorPool([a1])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| print(pool.has_free())
| print(pool.get_next())
| print(pool.has_free())
|
| .. testoutput::
|
| False
| 2
| True
|
| has_next(self)
| Returns whether there are any pending results to return.
|
| Returns:
| True if there are any pending results not yet returned.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| print(pool.has_next())
| print(pool.get_next())
| print(pool.has_next())
|
| .. testoutput::
|
| True
| 2
| False
|
| map(self, fn: Callable[[ForwardRef('ray.actor.ActorHandle'), ~V], Any], values: List[~V])
| Apply the given function in parallel over the actors and values.
|
| This returns an ordered iterator that will return results of the map
| as they finish. Note that you must iterate over the iterator to force
| the computation to finish.
|
| Arguments:
| fn: Function that takes (actor, value) as argument and
| returns an ObjectRef computing the result over the value. The
| actor will be considered busy until the ObjectRef completes.
| values: List of values that fn(actor, value) should be
| applied to.
|
| Returns:
| Iterator over results from applying fn to the actors and values.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| print(list(pool.map(lambda a, v: a.double.remote(v),
| [1, 2, 3, 4])))
|
| .. testoutput::
|
| [2, 4, 6, 8]
|
| map_unordered(self, fn: Callable[[ForwardRef('ray.actor.ActorHandle'), ~V], Any], values: List[~V])
| Similar to map(), but returning an unordered iterator.
|
| This returns an unordered iterator that will return results of the map
| as they finish. This can be more efficient that map() if some results
| take longer to compute than others.
|
| Arguments:
| fn: Function that takes (actor, value) as argument and
| returns an ObjectRef computing the result over the value. The
| actor will be considered busy until the ObjectRef completes.
| values: List of values that fn(actor, value) should be
| applied to.
|
| Returns:
| Iterator over results from applying fn to the actors and values.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| print(list(pool.map_unordered(lambda a, v: a.double.remote(v),
| [1, 2, 3, 4])))
|
| .. testoutput::
| :options: +MOCK
|
| [6, 8, 4, 2]
|
| pop_idle(self)
| Removes an idle actor from the pool.
|
| Returns:
| An idle actor if one is available.
| None if no actor was free to be removed.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1 = Actor.remote()
| pool = ActorPool([a1])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| assert pool.pop_idle() is None
| assert pool.get_next() == 2
| assert pool.pop_idle() == a1
|
| push(self, actor: 'ray.actor.ActorHandle')
| Pushes a new actor into the current list of idle actors.
|
| Arguments:
| actor: The Ray actor handle to add to the pool's idle set.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1])
| pool.push(a2)
|
| submit(self, fn: Callable[[ForwardRef('ray.actor.ActorHandle'), ~V], Any], value: ~V)
| Schedule a single task to run in the pool.
|
| This has the same argument semantics as map(), but takes on a single
| value instead of a list of values. The result can be retrieved using
| get_next() / get_next_unordered().
|
| Arguments:
| fn: Function that takes (actor, value) as argument and
| returns an ObjectRef computing the result over the value. The
| actor will be considered busy until the ObjectRef completes.
| value: Value to compute a result for.
|
| Examples:
| .. testcode::
|
| import ray
| from ray.util.actor_pool import ActorPool
|
| @ray.remote
| class Actor:
| def double(self, v):
| return 2 * v
|
| a1, a2 = Actor.remote(), Actor.remote()
| pool = ActorPool([a1, a2])
| pool.submit(lambda a, v: a.double.remote(v), 1)
| pool.submit(lambda a, v: a.double.remote(v), 2)
| print(pool.get_next(), pool.get_next())
|
| .. testoutput::
|
| 2 4
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
ray.util.List
Python Library Documentation: _SpecialGenericAlias in module typing
List = typing.List
A generic version of list.
ray.util.PublicAPI
Python Library Documentation: function PublicAPI in module ray.util.annotations
PublicAPI(*args: Any, **kwargs: Any)
Annotation for documenting public APIs.
Public APIs are classes and methods exposed to end users of Ray.
If ``stability="alpha"``, the API can be used by advanced users who are
tolerant to and expect breaking changes.
If ``stability="beta"``, the API is still public and can be used by early
users, but are subject to change.
If ``stability="stable"``, the APIs will remain backwards compatible across
minor Ray releases (e.g., Ray 1.4 -> 1.8).
For a full definition of the stability levels, please refer to the
:ref:`Ray API Stability definitions <api-stability>`.
Args:
*args: When used as a bare ``@PublicAPI`` decorator, contains the
wrapped function or class as the single positional argument.
**kwargs: Supported keyword arguments are ``stability`` (one of
``"stable"``, ``"beta"``, ``"alpha"``) and ``api_group`` (used
only for doc rendering; APIs in the same group are grouped
together in the API doc pages).
Returns:
Either the annotated object (when used as ``@PublicAPI``) or a
decorator that annotates an object (when used as
``@PublicAPI(...)``).
Examples:
>>> from ray.util.annotations import PublicAPI
>>> @PublicAPI
... def func(x):
... return x
>>> @PublicAPI(stability="beta")
... def func(y):
... return y
ray.util.as_completed
Python Library Documentation: function as_completed in module ray.util.helpers
as_completed(refs: 'Sequence[ObjectRef]', *, chunk_size: int = 10, yield_obj_refs: bool = False, **kwargs) -> Iterator[Union[Any, ForwardRef('ObjectRef')]]
Given a list of Ray task references, yield results as they become available.
Unlike calling :meth:`~ray.get` on a list of references (i.e., `ray.get(refs)`) which
waits for all results to be ready, this function begins to yield result as soon as
a batch of `chunk_size` results are ready.
.. note::
Generally there is no guarantee on the order of results. For example, the first result
is not necessarily the first one completed, but rather the first one submitted in the
first available batch (See :meth:`~ray.wait` for more details about
preservation of submission order).
.. note::
Use this function instead of calling :meth:`~ray.get` inside a for loop. See
https://docs.ray.io/en/latest/ray-core/patterns/ray-get-loop.html for more details.
Example:
Suppose we have a function that sleeps for x seconds depending on the input.
We expect to obtain a partially sorted list of results.
.. testcode:: python
import ray
import time
@ray.remote
def f(x):
time.sleep(x)
return x
refs = [f.remote(i) for i in [10, 4, 6, 8, 2]]
for x in ray.util.as_completed(refs, chunk_size=2):
print(x)
.. testoutput::
:options: +MOCK
# Output:
4
2
6
8
10
Args:
refs: A list of Ray object refs.
chunk_size: The number of tasks to wait for in each iteration (default 10).
The parameter is passed as `num_returns` to :meth:`~ray.wait` internally.
yield_obj_refs: If True, return Ray remote refs instead of results (by calling :meth:`~ray.get`).
**kwargs: Additional keyword arguments to pass to :meth:`~ray.wait`, e.g.,
`timeout` and `fetch_local`.
Yields:
Union[Any, ObjectRef]: The results (or optionally their Ray references) of the Ray tasks as they complete.
**PublicAPI (alpha):** This API is in alpha and may change before becoming stable.
ray.util.client_mode_hook
Python Library Documentation: function client_mode_hook in module ray._private.client_mode_hook
client_mode_hook(func: ~F) -> ~F
Decorator for whether to use the 'regular' ray version of a function,
or the Ray Client version of that function.
Args:
func: This function. This is set when this function is used
as a decorator.
Returns:
The wrapped function that dispatches to the regular or client version.
ray.util.connect
Python Library Documentation: function connect in module ray.util.client_connect
connect(conn_str: str, secure: bool = False, metadata: List[Tuple[str, str]] = None, connection_retries: int = 3, job_config: ray.job_config.JobConfig = None, namespace: str = None, *, ignore_version: bool = False, _credentials: Optional[ForwardRef('grpc.ChannelCredentials')] = None, ray_init_kwargs: Optional[Dict[str, Any]] = None) -> Dict[str, Any]
.. warning::
**DEPRECATED**: This API is deprecated and may be removed in future Ray releases.
Use ray.init(ray://<head_node_ip_address>:<ray_client_server_port>) instead. See detailed usage at https://docs.ray.io/en/releases-2.56.1/ray-core/package-ref.html#ray-init.
ray.util.deregister_serializer
Python Library Documentation: function deregister_serializer in module ray.util.serialization
deregister_serializer(cls: type)
Deregister the serializer associated with the type ``cls``.
There is no effect if the serializer is unavailable.
Args:
cls: A Python class/type.
ray.util.disable_log_once_globally
Python Library Documentation: function disable_log_once_globally in module ray.util.debug
disable_log_once_globally()
Make log_once() return False in this process.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.util.disconnect
Python Library Documentation: function disconnect in module ray.util.client_connect
disconnect()
Disconnects from server; is idempotent.
.. warning::
**DEPRECATED**: This API is deprecated and may be removed in future Ray releases.
Use ray.shutdown() instead. See detailed usage at https://docs.ray.io/en/releases-2.56.1/ray-core/package-ref.html#ray-shutdown.
ray.util.enable_periodic_logging
Python Library Documentation: function enable_periodic_logging in module ray.util.debug
enable_periodic_logging()
Make log_once() periodically return True in this process.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.util.get_current_placement_group
Python Library Documentation: function get_current_placement_group in module ray.util.placement_group
get_current_placement_group() -> Optional[ray.util.placement_group.PlacementGroup]
Get the current placement group which a task or actor is using.
It returns None if there's no current placement group for the worker.
For example, if you call this method in your driver, it returns None
(because drivers never belong to any placement group).
Examples:
.. testcode::
import ray
from ray.util.placement_group import get_current_placement_group
from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
@ray.remote
def f():
# This returns the placement group the task f belongs to.
# It means this pg is identical to the pg created below.
return get_current_placement_group()
pg = ray.util.placement_group([{"CPU": 2}])
assert ray.get(f.options(
scheduling_strategy=PlacementGroupSchedulingStrategy(
placement_group=pg)).remote()) == pg
# Driver doesn't belong to any placement group,
# so it returns None.
assert get_current_placement_group() is None
Returns:
PlacementGroup: Placement group object.
None if the current task or actor wasn't
created with any placement group.
ray.util.get_node_instance_id
Python Library Documentation: function get_node_instance_id in module ray._private.services
get_node_instance_id()
Get the specified node instance id of the current node.
Returns:
The node instance id of the current node.
ray.util.get_node_ip_address
Python Library Documentation: function get_node_ip_address in module ray._private.services
get_node_ip_address(address=None)
# NOTE: This API should not be used when you obtain the
# IP address when ray.init is not called because
# it cannot find the IP address if it is specified by
# ray start --node-ip-address. You should instead use
# get_node_to_connect_ip_address.
ray.util.get_placement_group
Python Library Documentation: function get_placement_group in module ray.util.placement_group
get_placement_group(placement_group_name: str) -> ray.util.placement_group.PlacementGroup
Get a placement group object with a global name.
Args:
placement_group_name: Global name of the placement group to look up.
Returns:
None if can't find a placement group with the given name.
The placement group object otherwise.
ray.util.inspect_serializability
Python Library Documentation: function inspect_serializability in module ray.util.check_serialize
inspect_serializability(base_obj: Any, name: Optional[str] = None, depth: int = 3, print_file: Optional[Any] = None) -> Tuple[bool, Set[ray.util.check_serialize.FailureTuple]]
Identifies what objects are preventing serialization.
Args:
base_obj: Object to be serialized.
name: Optional name of string.
depth: Depth of the scope stack to walk through. Defaults to 3.
print_file: file argument that will be passed to print().
Returns:
bool: True if serializable.
set[FailureTuple]: Set of unserializable objects.
.. versionadded:: 1.1.0
**DeveloperAPI:** This API may change across minor Ray releases.
ray.util.list_named_actors
Python Library Documentation: function list_named_actors in module ray.util
list_named_actors(all_namespaces: bool = False) -> List[str]
List all named actors in the system.
Actors must have been created with Actor.options(name="name").remote().
This works for both detached & non-detached actors.
By default, only actors in the current namespace will be returned
and the returned entries will simply be their name.
If `all_namespaces` is set to True, all actors in the cluster will be
returned regardless of namespace, and the returned entries will be of the
form {"namespace": namespace, "name": name}.
**PublicAPI (beta):** This API is in beta and may change before becoming stable.
ray.util.log_once
Python Library Documentation: function log_once in module ray.util.debug
log_once(key: str) -> bool
Returns True if this is the "first" call for a given key.
Various logging settings can adjust the definition of "first".
Args:
key: A unique identifier for the call site.
Returns:
True if this is the first call for ``key`` (subject to the current
``log_once`` settings), False otherwise.
Example:
.. testcode::
import logging
from ray.util.debug import log_once
logger = logging.getLogger(__name__)
if log_once("some_key"):
logger.info("Some verbose logging statement")
**DeveloperAPI:** This API may change across minor Ray releases.
ray.util.map_unordered
Python Library Documentation: function map_unordered in module ray.util.helpers
map_unordered(fn: 'RemoteFunction', items: Iterable[Any], *, backpressure_size: Optional[int] = 100, chunk_size: int = 10, yield_obj_refs: bool = False, **kwargs) -> Iterator[Union[Any, ForwardRef('ObjectRef')]]
Apply a Ray remote function to a list of items and return an iterator that yields
the completed results as they become available.
This helper function applies backpressure to control the number of pending tasks, following the
design pattern described in
https://docs.ray.io/en/latest/ray-core/patterns/limit-pending-tasks.html.
.. note::
There is generally no guarantee on the order of results.
Example:
Suppose we have a function that sleeps for x seconds depending on the input.
We expect to obtain a partially sorted list of results.
.. testcode:: python
import ray
import time
@ray.remote
def f(x):
time.sleep(x)
return x
# Example 1: chunk_size=2
for x in ray.util.map_unordered(f, [10, 4, 6, 8, 2], chunk_size=2):
print(x)
.. testoutput::
:options: +MOCK
4
2
6
8
10
.. testcode:: python
# Example 2: backpressure_size=2, chunk_size=1
for x in ray.util.map_unordered(f, [10, 4, 6, 8, 2], backpressure_size=2, chunk_size=1):
print(x)
.. testoutput::
:options: +MOCK
4
10
6
8
2
Args:
fn: A remote function to apply to the list of items. For more complex use cases, use Ray Data's
:meth:`~ray.data.Dataset.map` / :meth:`~ray.data.Dataset.map_batches` instead.
items: An iterable of items to apply the function to.
backpressure_size: Maximum number of in-flight tasks allowed before
calling a blocking :meth:`~ray.wait` (default 100). If None, no backpressure is applied.
chunk_size: The number of tasks to wait for when the number of in-flight tasks exceeds
`backpressure_size`. The parameter is passed as `num_returns` to :meth:`~ray.wait` internally.
yield_obj_refs: If True, return Ray remote refs instead of results (by calling :meth:`~ray.get`).
**kwargs: Additional keyword arguments to pass to :meth:`~ray.wait`, e.g.,
`timeout` and `fetch_local`.
Yields:
Union[Any, ObjectRef]: The results (or optionally their Ray references) of the Ray tasks as they complete.
.. seealso::
:meth:`~ray.util.as_completed`
Call this method for an existing list of Ray object refs.
:meth:`~ray.data.Dataset.map`
Use Ray Data APIs (e.g., :meth:`~ray.data.Dataset.map` and :meth:`~ray.data.Dataset.map_batches`)
for better control and complex use cases, e.g., functions with multiple arguments.
.. note::
This is an altenative to `pool.imap_unordered()` in Ray's Actor-based `multiprocessing.Pool`.
See https://docs.ray.io/en/latest/ray-more-libs/multiprocessing.html for more details.
**PublicAPI (alpha):** This API is in alpha and may change before becoming stable.
ray.util.placement_group
Python Library Documentation: function placement_group in module ray.util.placement_group
placement_group(bundles: List[Dict[str, float]], strategy: str = 'PACK', name: str = '', lifetime: Optional[str] = None, _soft_target_node_id: Optional[str] = None, bundle_label_selector: List[Dict[str, str]] = None) -> ray.util.placement_group.PlacementGroup
Asynchronously creates a PlacementGroup.
Args:
bundles: A list of bundles which
represent the resources requirements.
strategy: The strategy to create the placement group.
- "PACK": Packs Bundles into as few nodes as possible.
- "SPREAD": Places Bundles across distinct nodes as even as possible.
- "STRICT_PACK": Packs Bundles into one node. The group is
not allowed to span multiple nodes.
- "STRICT_SPREAD": Packs Bundles across distinct nodes.
name: The name of the placement group.
lifetime: Either `None`, which defaults to the placement group
will fate share with its creator and will be deleted once its
creator is dead, or "detached", which means the placement group
will live as a global object independent of the creator.
_soft_target_node_id: (Private, Experimental) Soft hint where bundles of
this placement group should be placed.
The target node is specified by it's hex ID.
If the target node has no available resources or died,
bundles can be placed elsewhere.
This currently only works with STRICT_PACK pg.
bundle_label_selector: A list of label selectors to apply to a
placement group on a per-bundle level.
Raises:
ValueError: if bundle type is not a list.
ValueError: if empty bundle or empty resource bundles are given.
ValueError: if the wrong lifetime arguments are given.
Returns:
PlacementGroup: Placement group object.
ray.util.placement_group_table
Python Library Documentation: function placement_group_table in module ray.util.placement_group
placement_group_table(placement_group: ray.util.placement_group.PlacementGroup = None) -> dict
Get the state of the placement group from GCS.
Args:
placement_group: placement group to see
states.
Returns:
A dictionary describing the state of the given placement group, or
the table of all placement groups if ``placement_group`` is None.
**DeveloperAPI:** This API may change across minor Ray releases.
ray.util.register_serializer
Python Library Documentation: function register_serializer in module ray.util.serialization
register_serializer(cls: type, *, serializer: <built-in function callable>, deserializer: <built-in function callable>)
Use the given serializer to serialize instances of type ``cls``,
and use the deserializer to deserialize the serialized object.
Args:
cls: A Python class/type.
serializer: A function that converts an instances of
type ``cls`` into a serializable object (e.g. python dict
of basic objects).
deserializer: A function that constructs the
instance of type ``cls`` from the serialized object.
This function itself must be serializable.
ray.util.remove_placement_group
Python Library Documentation: function remove_placement_group in module ray.util.placement_group
remove_placement_group(placement_group: ray.util.placement_group.PlacementGroup) -> None
Asynchronously remove placement group.
Args:
placement_group: The placement group to delete.
ray.util.wrap_auto_init
Python Library Documentation: function wrap_auto_init in module ray._private.auto_init_hook wrap_auto_init(fn)