Package: ray-ease
ray-easeHome·Report Bug·Request Feature·Useful Examples·LicenseSwitch from serial to parallel computing without requiring any code modifications.About the projectThis package is a convenientRaywrapper 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 particularlyadvantageous during the debugging phase, as parallelizing code may inadvertently introduce unnecessary complexities and overhead.Installation$pipinstallray-easeUsageEffortlessly parallelize your code by simply decorating your functions or classes with theparallelizedecorator. Retrieve the results using theretrievefunction. This enables you to parallelize your code with Ray, default behavior of theinitfunction, or run it serially without any overhead from Ray withrez.init(config="serial").[!NOTE]To explore additional useful examples, please refer to thededicated folderdesignated for this purpose.Running a Taskimportray_easeasrezrez.init()# Define the square task.@rez.parallelizedefsquare(x):returnx*x# Launch four parallel square tasks.futures=[square(i)foriinrange(4)]# Retrieve results.print(rez.retrieve(futures))# -> [0, 1, 4, 9]SeeRay versionfor comparison.Calling an Actorimportray_easeasrezrez.init()# Define the Counter actor.@rez.parallelizeclassCounter:def__init__(self):self.i=0defget(self):returnself.idefincr(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_inrange(10):c.incr(1)# Retrieve final actor state.print(rez.retrieve(c.get()))# -> 10SeeRay versionfor comparison.Comparison with and without RayParallel computation with Ray (seebase example):importtimeimportray_easeasrezrez.init(num_cpus=4)# Initialize Ray and specify this system has 4 CPUs.@rez.parallelizedefdo_some_work(x):time.sleep(1)# Replace this with work you need to do.returnxstart=time.time()results=rez.retrieve([do_some_work(x)forxinrange(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 toray_easeto use theserial configwithrez.init("serial"):importtimeimportray_easeasrezrez.init("serial")@rez.parallelizedefdo_some_work(x):time.sleep(1)# Replace this with work you need to do.returnxstart=time.time()results=rez.retrieve([do_some_work(x)forxinrange(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)ContributingInterested 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)Licenseray-easewas created by Arthur Elskens. It is licensed under the terms of the MIT license. See LICENSE for more information.(back to top)