Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when updating numpy array after ray.get, "output array is read-only". #369

Closed
robertnishihara opened this issue Mar 14, 2017 · 1 comment

Comments

@robertnishihara
Copy link
Collaborator

The following fails.

import numpy as np
import ray
ray.init()

@ray.remote
def f():
  return np.zeros(100)

x = ray.get(f.remote())

x[0] = 1

The last line fails with the following error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-1a754504edbf> in <module>()
----> 1 x[0] = 1

ValueError: assignment destination is read-only

If instead of x[0] = 1 I do x += np.ones(100) it fails with the following error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-acaf936369e9> in <module>()
----> 1 x += np.ones(100)

ValueError: output array is read-only
@robertnishihara
Copy link
Collaborator Author

The problem is the following. When f finishes executing, it returns a numpy array of zeros. That array is stored in the object store.

When you call ray.get to get the array, the array is still stored in the object store (in particular, it is not copied into the Python processes heap). Objects in the object store are immutable, and so the array values cannot be changed.

If you wish to change the array values, then you'll need to create a copy of the array locally and mutate that one. For example, the following should work.

y = np.copy(x)
y[0] = 1
y += np.ones(100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant