ray-project / ray-legacy

An experimental distributed execution engine
BSD 3-Clause "New" or "Revised" License
21 stars 18 forks source link

Equality testing for objects in the object store #341

Open pcmoritz opened 8 years ago

pcmoritz commented 8 years ago

Objects a and b that are retrieved by ray.get have two additional fields (ray_deallocator and ray_objectid), which means they cannot be compared for equality.

The underlying issue is similar to #331

pcmoritz commented 8 years ago

As a workaround, this can be used:

from numpy.testing import assert_equal

def ray_assert_equal(a, b, attrs=[]):
  attrs.extend(["ray_deallocator", "ray_objectid"])
  a = a.__dict__
  b = b.__dict__
  A = dict((i, a[i]) for i in a if i not in attrs)
  B = dict((i, b[i]) for i in b if i not in attrs)
  assert_equal(A, B)

It compares member of a python object, except for ray_deallocator and ray_objectid; note that testing is not done recursively (it will fail if one of the members is a non-primitive python object). Recursive testing can be done with https://gist.github.com/samuraisam/901117.