Skip to content

Instantly share code, notes, and snippets.

@mGalarnyk
Created September 1, 2021 18:58
Show Gist options
  • Save mGalarnyk/30c8672620c8655a37940be935899a57 to your computer and use it in GitHub Desktop.
Save mGalarnyk/30c8672620c8655a37940be935899a57 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)
@Agrover112
Copy link

Wow, ray is pretty good.

@Ohad-Multisense
Copy link

Ohad-Multisense commented Nov 7, 2021

it is not work for me, i am trying to run the code as is :(
but get error:

TypeError: can't pickle function objects

why it can be?

p.s. i am install ray and timebudget packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment