Skip to content

Instantly share code, notes, and snippets.

@simrit1
Forked from mGalarnyk/rayProject.py
Created September 15, 2021 00:42
Show Gist options
  • Save simrit1/780c486fe50842f4d353754dd1ab9e55 to your computer and use it in GitHub Desktop.
Save simrit1/780c486fe50842f4d353754dd1ab9e55 to your computer and use it in GitHub Desktop.
import math
import numpy as np
from timebudget import timebudget
import ray
iterations_count = round(1e7)
@ray.remote
def complex_operation(input_index):
print("Complex operation. Input index: {:2d}".format(input_index))
[math.exp(i) * math.sinh(i) for i in [1] * iterations_count]
@ray.remote
def complex_operation_numpy(input_index):
print("Complex operation (numpy). Input index: {:2d}".format(input_index))
data = np.ones(iterations_count)
np.exp(data) * np.sinh(data)
@timebudget
def run_complex_operations(operation, input):
ray.get([operation.remote(i) for i in input])
ray.init()
input = range(10)
print('Without NumPy')
run_complex_operations(complex_operation, input)
print('NumPy')
run_complex_operations(complex_operation_numpy, input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment