Skip to main content

ray-ease

Home · Report Bug · Request Feature · Useful Examples · License
Switch from serial to parallel computing without requiring any code modifications.

About the project

This package is a convenient Ray wrapper that enables the utilization of Ray decorated functions and actors as if they were regular local functions. With this tool, your program can seamlessly run in both parallel and serial modes without requiring any code modifications. This capability is particularly advantageous during the debugging phase, as parallelizing code may inadvertently introduce unnecessary complexities and overhead.

Installation

$ pip install ray-ease

Usage

Effortlessly parallelize your code by simply decorating your functions or classes with the parallelize decorator. Retrieve the results using the retrieve function. This enables you to parallelize your code with Ray, default behavior of the init function, or run it serially without any overhead from Ray with rez.init(config="serial").

[!NOTE]
To explore additional useful examples, please refer to the dedicated folder designated for this purpose.

Running a Task

import ray_ease as rez

rez.init()

# Define the square task.
@rez.parallelize
def square(x):
    return x * x

# Launch four parallel square tasks.
futures = [square(i) for i in range(4)]

# Retrieve results.
print(rez.retrieve(futures))
# -> [0, 1, 4, 9]

See Ray version for comparison.

Calling an Actor

import ray_ease as rez

rez.init()

# Define the Counter actor.
@rez.parallelize
class Counter:
    def __init__(self):
        self.i = 0

    def get(self):
        return self.i

    def incr(self, value):
        self.i += value

# Create a Counter actor.
c = Counter()

# Submit calls to the actor. These calls run asynchronously but in
# submission order on the remote actor process.
for _ in range(10):
    c.incr(1)

# Retrieve final actor state.
print(rez.retrieve(c.get()))
# -> 10

See Ray version for comparison.

Comparison with and without Ray

Parallel computation with Ray (see base example):

import time
import ray_ease as rez

rez.init(num_cpus=4) # Initialize Ray and specify this system has 4 CPUs.

@rez.parallelize
def do_some_work(x):
    time.sleep(1) # Replace this with work you need to do.
    return x

start = time.time()
results = rez.retrieve([do_some_work(x) for x in range(4)])
print("duration =", time.time() - start)
print("results =", results)

This yields the following output:

duration = 1.0233514308929443
results =  [0, 1, 2, 3]

As opposed to serial computation, obtained by specifying to ray_ease to use the serial config with rez.init("serial"):

import time
import ray_ease as rez

rez.init("serial")

@rez.parallelize
def do_some_work(x):
    time.sleep(1) # Replace this with work you need to do.
    return x

start = time.time()
results = rez.retrieve([do_some_work(x) for x in range(4)])
print("duration =", time.time() - start)
print("results =", results)

The outputs provide confirmation that the execution was carried out sequentially, taking approximately four times longer than before:

duration = 4.021065711975098
results =  [0, 1, 2, 3]

(back to top)

Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.

(back to top)

License

ray-ease was created by Arthur Elskens. It is licensed under the terms of the MIT license. See LICENSE for more information.

(back to top)

Metadata

Release files for ray-ease 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ray-ease 0.3.2
File Size Uploaded Provenance
ray_ease-0.3.2.tar.gz 17.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ray-ease 0.3.2
File Interpreter ABI Platform
ray_ease-0.3.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 33.6 kB

Release files / ray_ease-0.3.2.tar.gz

Download URL ray_ease-0.3.2.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bfd16ad31126e0a65cad5d60b7f8e7a4bae2f862d0ba5c4c9b93df9956b709ae
BLAKE2b-256 checksum
How to use checksums
44b39f13f0d1123004269f8d4b0ff70a016dff4217b7cccb3d4ad830568d24fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / ray_ease-0.3.2-py2.py3-none-any.whl

Download URL ray_ease-0.3.2-py2.py3-none-any.whl
Size 16.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5d7a8922f4e9292789c5a827590f28fa269c50c7865790e4dd5f56a424bc9952
BLAKE2b-256 checksum
How to use checksums
4bb27614372f289f710afcb1b76bb55a3fe25de7ecd6f5ee34e25615881d240e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Security for ray-ease 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page