Project description
Sunray
![Static Badge](https://pypi-camo.freetls.fastly.net/d104d5ef7fd40f8299077e9d15965b46a5ac92ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7261795f6d696e5f76657273696f6e2d322e32302e302d626c7565)
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
pip install sunray
Let's vs.
Round 1: Build an actor
sunray |
ray |
![](https://pypi-camo.freetls.fastly.net/2dd74de19731e9659fa915a97dd75ba8dea62b6e/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f6163746f722e6a7067) |
![](https://pypi-camo.freetls.fastly.net/a0c9f594d7a3dff9d1eecea833a2602f7aa4a31e/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f6163746f722e6a7067) |
- 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://pypi-camo.freetls.fastly.net/066f4ed784b806c4ae2038cab0677e1433c40a45/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f6163746f725f6d6574686f64732e6a7067) |
![](https://pypi-camo.freetls.fastly.net/7cd2b4f081fb475f8e0e06d04f33c1d155fa6bff/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f6163746f725f6d6574686f64732e6a7067) |
- sunray list all remote methods
- ray list nothing
Round 3: Actor remote method call
sunray |
ray |
![](https://pypi-camo.freetls.fastly.net/68669e80137becf467927004557e91cb1efecbdd/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f6d6574686f645f72656d6f74655f63616c6c2e6a7067) |
![](https://pypi-camo.freetls.fastly.net/3196e394c78ef47711b10de5290173b4a1de3d18/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f6d6574686f645f72656d6f74655f63616c6c2e6a7067) |
- sunray correctly provided parameter hints.
- ray ...
Round 4: Annotate with Actor
sunray |
ray |
![](https://pypi-camo.freetls.fastly.net/09475ba35d5cdd4e8f7aef342354b93169ed6ae6/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f6163746f725f616e6e6f746174696f6e2e6a7067) |
![](https://pypi-camo.freetls.fastly.net/1a07bbf98d2d80377f717e45e0796286eb3f2cbf/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f6163746f725f616e6e6f746174696f6e2e6a7067) |
- with sunray, just annotate it with
Actor[Demo]
.
- with ray, I don't known.
Round 5: Stream
sunray |
ray |
![](https://pypi-camo.freetls.fastly.net/469e2e5d7d4eaabce1d582ec0075e4311391838b/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f73747265616d2e6a7067) |
![](https://pypi-camo.freetls.fastly.net/f69e5f5a3088a6bc0694c4d1ab99a9907e6f495b/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f73747265616d2e6a7067) |
- sunray correctly identified that
stream
returns a generator.
- ray still returns ObjectRef.
Round 6: Unpack result
sunray |
ray |
![](https://pypi-camo.freetls.fastly.net/cadbe1d3db5cdc45112e9c3c30b4f7bb8a57f11e/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f756e7061636b2e6a7067) |
![](https://pypi-camo.freetls.fastly.net/dc49be45a178aee1c8d458ea90e1cccee8da7aee/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f756e7061636b2e6a7067) |
- 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://pypi-camo.freetls.fastly.net/a2d1ac2c1f290556fb30a7391b595e0de2034783/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f6765745f6163746f722e6a7067) |
![](https://pypi-camo.freetls.fastly.net/46521445151abfad479ff89f2b3b029f67bf06bd/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f6765745f6163746f722e6a7067) |
- 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://pypi-camo.freetls.fastly.net/3baeeb267d84196b9d468ac15029ecded715d667/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f63616c6c5f73656c665f72656d6f74655f6d6574686f642e6a7067) |
![](https://pypi-camo.freetls.fastly.net/0b70bc96ebfd3d3b7d6d2e4016c690402ca1ea9b/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f63616c6c5f73656c665f72656d6f74655f6d6574686f642e6a7067) |
- 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://pypi-camo.freetls.fastly.net/c1356d39e9da9cd4665174726e29adea7ff17ed8/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f73756e7261795f62696e642e6a7067) |
![](https://pypi-camo.freetls.fastly.net/25f682a44d0d02e429bde94f23d1a0ee2d6e1a5c/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f7261795f62696e642e6a7067) |
- 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
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))
Better Remote Pdb
Support code highlighting and completion |
![](https://pypi-camo.freetls.fastly.net/280039faf71ee5c9c4ba310c1dd37093441b4815/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f727064622d312e6a7067) |
Better display variable information |
![](https://pypi-camo.freetls.fastly.net/e75cfe4d2c5740e490e71e85f5d2c82dc51b73ac/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f727064622d322e6a7067) |
Support inspect variables |
![](https://pypi-camo.freetls.fastly.net/d2b6f04a64a4e4cfc17cac5ec4c64344eb63dcd7/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f727064622d332e6a7067) |
Support IPython magic funcs |
![](https://pypi-camo.freetls.fastly.net/bd39e0335b625321d9204acd52115283666dfcb0/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f727064622d342e6a7067) |
Support time/timeit magic funcs |
![](https://pypi-camo.freetls.fastly.net/b54e9d23db42e71d97f276a0ace8e2239d1a3def/68747470733a2f2f7a656e78752d6769746875622d61737365742e73332e75732d656173742d322e616d617a6f6e6177732e636f6d2f727064622d352e6a7067) |
RPDB Environments
SUNRAY_REMOTE_PDB
: Enable sunray as the pdb backend; otherwise, use ray. (Default yes
)
SUNRAY_REMOTE_PDB_SHOW_LAYOUTS
: If enabled, you will get a more user-friendly debug display. (Default yes
)
SUNRAY_REMOTE_PDB_THEME
: The pdb theme. (Default ansi_dark
)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution