Name | sunray JSON |
Version |
0.10.0
JSON |
| download |
home_page | None |
Summary | More robust ray |
upload_time | 2025-01-02 02:52:06 |
maintainer | None |
docs_url | None |
author | ZhengYu, Xu |
requires_python | <4.0,>=3.9 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Sunray
[![Tests](https://github.com/zen-xu/sunray/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/zen-xu/sunray/actions/workflows/test.yaml)
[![Mypy](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml/badge.svg?branch=main)](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml)
[![codecov](https://codecov.io/gh/zen-xu/sunray/graph/badge.svg?token=NkaEIVRqk6)](https://codecov.io/gh/zen-xu/sunray)
![GitHub License](https://img.shields.io/github/license/zen-xu/sunray)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sunray)
![PyPI - Version](https://img.shields.io/pypi/v/sunray)
![Static Badge](https://img.shields.io/badge/ray_min_version-2.20.0-blue)
[Ray](https://github.com/ray-project/ray) is a unified framework for scaling AI and Python applications. However, it falls short in offering friendly type hints, particularly when it comes to working with the `Actor`.
To address this shortfall, sunray provides enhanced and more robust type hints.
## install
```shell
pip install sunray
```
## Let's vs.
### Round 1: Build an actor
| sunray | ray |
| :-------------------------------------------------------------------------: | :----------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor.jpg) |
- sunray returns `Actor[Demo]`, but ray returns `ObjectRef[Demo]`
- ray mypy raise error `Type[Demo] has no attribute "remote"`
### Round 2: Get actor remote methods
| sunray | ray |
| :---------------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor_methods.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor_methods.jpg) |
- sunray list all remote methods
- ray list nothing
### Round 3: Actor remote method call
| sunray | ray |
| :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_method_remote_call.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_method_remote_call.jpg) |
- sunray correctly provided parameter hints.
- ray ...
### Round 4: Annotate with Actor
| sunray | ray |
| :------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor_annotation.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor_annotation.jpg) |
- with sunray, just annotate it with `Actor[Demo]`.
- with ray, I don't known.
### Round 5: Stream
| sunray | ray |
| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_stream.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_stream.jpg) |
- sunray correctly identified that `stream` returns a generator.
- ray still returns ObjectRef.
### Round 6: Unpack result
| sunray | ray |
| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_unpack.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_unpack.jpg) |
- sunray will auto unpack tuple result if options specify `unpack=True`.
- ray need to specify how many return numbers, so you need to count it.
- ray mypy raise error 'RemoteFunctionNoArgs has no attribute "options"'.
### Round 7: Get actor
| sunray | ray |
| :-----------------------------------------------------------------------------: | :--------------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_get_actor.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_get_actor.jpg) |
- sunray get_actor will return `ActorHandle`, and return `Actor[Demo]` if you specify with generic type.
- ray just return `Any`.
### Round 8: Call self remote method
| sunray | ray |
| :-------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_call_self_remote_method.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_call_self_remote_method.jpg) |
- sunray maintains a consistent calling convention, whether it's from internal or external functions.
- ray, you need to first obtain the current actor from the running context, and then call through the actor.
### Round 9: Lazy Computation
| sunray | ray |
| :------------------------------------------------------------------------: | :---------------------------------------------------------------------: |
| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_bind.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_bind.jpg) |
- sunray can successfully track the input parameter types and output types.
- ray does not have this capability.
## API
`sunray` re-export all apis from `ray.core` with friendly type hints. In addition, `sunray` provides `ActorMixin` which is used to help creating more robust actors.
### ActorMixin
`ActorMixin` is a mixin, and provides a classmethod `new_actor`
```python
import sunray
class Demo(
# Here to specify default actor options
sunray.ActorMixin, name="DemoActor", num_cpus=1, concurrency_groups={"g1": 1}
):
def __init__(self, init_v: int):
self.init_v = init_v
# annotate `add` is a remote_method
@sunray.remote_method
def add(self, v: int) -> int:
return self.init_v + v
# support directly call remote_method
@sunray.remote_method
def calculate(self, v: int) -> int:
return self.add(v)
# support specify remote method options
@sunray.remote_method(concurrency_group="g1")
async def sleep(self): ...
# construct the actor
actor = Demo.new_actor().remote(1)
# call remote method
ref = actor.methods.add.remote(1)
print(sunray.get(ref))
```
Raw data
{
"_id": null,
"home_page": null,
"name": "sunray",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "ZhengYu, Xu",
"author_email": "zen-xu@outlook.com",
"download_url": null,
"platform": null,
"description": "# Sunray\n\n[![Tests](https://github.com/zen-xu/sunray/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/zen-xu/sunray/actions/workflows/test.yaml)\n[![Mypy](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml/badge.svg?branch=main)](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml)\n[![codecov](https://codecov.io/gh/zen-xu/sunray/graph/badge.svg?token=NkaEIVRqk6)](https://codecov.io/gh/zen-xu/sunray)\n![GitHub License](https://img.shields.io/github/license/zen-xu/sunray)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sunray)\n![PyPI - Version](https://img.shields.io/pypi/v/sunray)\n![Static Badge](https://img.shields.io/badge/ray_min_version-2.20.0-blue)\n\n[Ray](https://github.com/ray-project/ray) is a unified framework for scaling AI and Python applications. However, it falls short in offering friendly type hints, particularly when it comes to working with the `Actor`.\n\nTo address this shortfall, sunray provides enhanced and more robust type hints.\n\n## install\n\n```shell\npip install sunray\n```\n\n## Let's vs.\n\n### Round 1: Build an actor\n\n| sunray | ray |\n| :-------------------------------------------------------------------------: | :----------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor.jpg) |\n\n- sunray returns `Actor[Demo]`, but ray returns `ObjectRef[Demo]`\n- ray mypy raise error `Type[Demo] has no attribute \"remote\"`\n\n### Round 2: Get actor remote methods\n| sunray | ray |\n| :---------------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor_methods.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor_methods.jpg) |\n\n- sunray list all remote methods\n- ray list nothing\n\n### Round 3: Actor remote method call\n| sunray | ray |\n| :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_method_remote_call.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_method_remote_call.jpg) |\n\n- sunray correctly provided parameter hints.\n- ray ...\n\n### Round 4: Annotate with Actor\n| sunray | ray |\n| :------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_actor_annotation.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_actor_annotation.jpg) |\n\n- with sunray, just annotate it with `Actor[Demo]`.\n- with ray, I don't known.\n\n### Round 5: Stream\n| sunray | ray |\n| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_stream.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_stream.jpg) |\n\n- sunray correctly identified that `stream` returns a generator.\n- ray still returns ObjectRef.\n\n### Round 6: Unpack result\n| sunray | ray |\n| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_unpack.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_unpack.jpg) |\n\n- sunray will auto unpack tuple result if options specify `unpack=True`.\n- ray need to specify how many return numbers, so you need to count it.\n- ray mypy raise error 'RemoteFunctionNoArgs has no attribute \"options\"'.\n\n### Round 7: Get actor\n| sunray | ray |\n| :-----------------------------------------------------------------------------: | :--------------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_get_actor.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_get_actor.jpg) |\n\n- sunray get_actor will return `ActorHandle`, and return `Actor[Demo]` if you specify with generic type.\n- ray just return `Any`.\n\n### Round 8: Call self remote method\n| sunray | ray |\n| :-------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_call_self_remote_method.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_call_self_remote_method.jpg) |\n\n- sunray maintains a consistent calling convention, whether it's from internal or external functions.\n- ray, you need to first obtain the current actor from the running context, and then call through the actor.\n\n### Round 9: Lazy Computation\n| sunray | ray |\n| :------------------------------------------------------------------------: | :---------------------------------------------------------------------: |\n| ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/sunray_bind.jpg) | ![](https://zenxu-github-asset.s3.us-east-2.amazonaws.com/ray_bind.jpg) |\n\n- sunray can successfully track the input parameter types and output types.\n- ray does not have this capability.\n\n## API\n\n`sunray` re-export all apis from `ray.core` with friendly type hints. In addition, `sunray` provides `ActorMixin` which is used to help creating more robust actors.\n\n### ActorMixin\n\n`ActorMixin` is a mixin, and provides a classmethod `new_actor`\n\n```python\nimport sunray\n\n\nclass Demo(\n # Here to specify default actor options\n sunray.ActorMixin, name=\"DemoActor\", num_cpus=1, concurrency_groups={\"g1\": 1}\n):\n def __init__(self, init_v: int):\n self.init_v = init_v\n\n # annotate `add` is a remote_method\n @sunray.remote_method\n def add(self, v: int) -> int:\n return self.init_v + v\n\n # support directly call remote_method\n @sunray.remote_method\n def calculate(self, v: int) -> int:\n return self.add(v)\n\n # support specify remote method options\n @sunray.remote_method(concurrency_group=\"g1\")\n async def sleep(self): ...\n\n\n# construct the actor\nactor = Demo.new_actor().remote(1)\n\n# call remote method\nref = actor.methods.add.remote(1)\nprint(sunray.get(ref))\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "More robust ray",
"version": "0.10.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5faf49dafbd64b9c013b24807fb61147361f52a171f570c9ae7973612323a059",
"md5": "fa34c02260965e78a3b122662d4b7f41",
"sha256": "edd9caf94035d9f049af7299b64b3bae657e20c019ac625ece09c04047b6b64c"
},
"downloads": -1,
"filename": "sunray-0.10.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fa34c02260965e78a3b122662d4b7f41",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 22724,
"upload_time": "2025-01-02T02:52:06",
"upload_time_iso_8601": "2025-01-02T02:52:06.645950Z",
"url": "https://files.pythonhosted.org/packages/5f/af/49dafbd64b9c013b24807fb61147361f52a171f570c9ae7973612323a059/sunray-0.10.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-02 02:52:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sunray"
}