Name | sunray JSON |
Version |
0.11.1
JSON |
| download |
home_page | None |
Summary | More robust ray |
upload_time | 2025-02-11 02:40:00 |
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
[](https://github.com/zen-xu/sunray/actions/workflows/test.yaml)
[](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml)
[](https://codecov.io/gh/zen-xu/sunray)




[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 |
| :-------------------------------------------------------------------------: | :----------------------------------------------------------------------: |
|  |  |
- 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 |
| :---------------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |
|  |  |
- sunray list all remote methods
- ray list nothing
### Round 3: Actor remote method call
| sunray | ray |
| :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: |
|  |  |
- sunray correctly provided parameter hints.
- ray ...
### Round 4: Annotate with Actor
| sunray | ray |
| :------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: |
|  |  |
- with sunray, just annotate it with `Actor[Demo]`.
- with ray, I don't known.
### Round 5: Stream
| sunray | ray |
| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |
|  |  |
- sunray correctly identified that `stream` returns a generator.
- ray still returns ObjectRef.
### Round 6: Unpack result
| sunray | ray |
| :--------------------------------------------------------------------------: | :-----------------------------------------------------------------------: |
|  |  |
- 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 |
| :-----------------------------------------------------------------------------: | :--------------------------------------------------------------------------: |
|  |  |
- 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 |
| :-------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |
|  |  |
- 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 |
| :------------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|  |  |
- 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[](https://github.com/zen-xu/sunray/actions/workflows/test.yaml)\n[](https://github.com/zen-xu/sunray/actions/workflows/test-mypy.yaml)\n[](https://codecov.io/gh/zen-xu/sunray)\n\n\n\n\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|  |  |\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|  |  |\n\n- sunray list all remote methods\n- ray list nothing\n\n### Round 3: Actor remote method call\n| sunray | ray |\n| :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: |\n|  |  |\n\n- sunray correctly provided parameter hints.\n- ray ...\n\n### Round 4: Annotate with Actor\n| sunray | ray |\n| :------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: |\n|  |  |\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|  |  |\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|  |  |\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|  |  |\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|  |  |\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|  |  |\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.11.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "870bd1f076ca7a76312c399040fe084e1628a86dc7b25d479d0476208d26e06a",
"md5": "66f6bd866a495a7aafe4ad029e3a6256",
"sha256": "7bd65a6054329e457251477d2da3214288cd4d6959454f8f9d2aea62cd8eb30f"
},
"downloads": -1,
"filename": "sunray-0.11.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "66f6bd866a495a7aafe4ad029e3a6256",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 23634,
"upload_time": "2025-02-11T02:40:00",
"upload_time_iso_8601": "2025-02-11T02:40:00.314287Z",
"url": "https://files.pythonhosted.org/packages/87/0b/d1f076ca7a76312c399040fe084e1628a86dc7b25d479d0476208d26e06a/sunray-0.11.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-11 02:40:00",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sunray"
}