Skip to main content

More robust ray

Project description

Sunray

Tests Mypy codecov GitHub License PyPI - Python Version PyPI - Version Static Badge

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
  • 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

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sunray-0.9.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file sunray-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: sunray-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.10 Linux/6.5.0-1025-azure

File hashes

Hashes for sunray-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd62a35a4866c10c178a9c495efa0fe855619d7aa23d2d4733bd4b7fed4ee73c
MD5 537288e48f8b4656fde44b4e0923d822
BLAKE2b-256 1562399e923d5981e6a255ec682f074a47ff0376d21c1ff3a4f87647b0165225

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page