Skip to content

Conversation

@suquark
Copy link
Member

@suquark suquark commented Dec 14, 2018

What do these changes do?

This PR migrates Python C extension to Cython bindings for the raylet client.

Related issue number

#3474
This also fixes #405

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10042/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10747/
Test PASSed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary to duplicate code for each id type. We can define one base class and have all other classes extend it. In the super class, we can leverage cls and self.__class__ to get the concrete type. Here is a short example.

class UniqueID(object):

    def __init__(self, data):
        self.data = data

    @classmethod
    def from_random(cls):
        return cls(b'')

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.data == other.data


class TaskID(UniqueID):
    pass


class ObjectID(UniqueID):
    pass


id1 = TaskID(b'')
id2 = TaskID.from_random()
id3 = ObjectID(b'')

assert type(id1) == TaskID
assert type(id2) == TaskID
assert type(id3) == ObjectID
assert id1 == id2
assert id1 != id3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's worth noticing that this is not real type safe. Because types in Python are dynamic. For example, if I have a function that is supposed to take a TaskID parameter, I can still pass in an ObjectID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason I am defining those IDs as independent classes is because those C++ types could be strong-typedefed in the near future.
I have also tried to reuse some duplicated parts. Unfortunately, Cython cannot recognize classes from cls or __class__ in many cases. So I still need to write a lot of extra code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see any other way to get rid of the code duplication? It would be good to resolve this before the PR is merged.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that all of these types will be different C++ classes in the future, so we should plan for that setting. It's also possible that they will have different methods, e.g, with ObjectID you could potentially call GetTaskID() or IsPut(), but that wouldn't make sense with an ActorID.

Copy link
Contributor

@pcmoritz pcmoritz Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, also this of course doesn't mean they can't share code. I'm pretty sure with interitence it can be made to work well that the common methods are defined only once, I'll give it a shot.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10792/
Test FAILed.

@suquark
Copy link
Member Author

suquark commented Jan 13, 2019

I have implemented all features in Cython. Some code still needs to be updated to fit the Cython interface.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10825/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10840/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10841/
Test FAILed.

pcmoritz pushed a commit that referenced this pull request Jan 18, 2019
* convert code to proper C++

* revert changes to "id.h" because #3765 has been merged.

* revert changes to Python bindings because they will be removed in #3541

* remove dependencies of Arrow logging

* revert changes to Arrow logging

* lint
function_id = ray.ObjectID(function_id_str)
driver_id = ray.ObjectID(driver_id_str)
function_id = ray.FunctionID(function_id_str)
# TODO(suquark): Make sure the type of "driver_id".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right type, do you want to remove the TODO?

JobID and DriverID are the same, and in the future I'd say we should transition to using DriverID exclusively. But given that in C++ it's called JobID, I think it's ok to call it JobID in python too until we change it everywhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we actually use both DriverID and JobID in C++. I agree about using only one (e.g., DriverID).

class_name = decode(class_name)
module = decode(module)
driver_id = ray.ObjectID(driver_id_str)
# TODO(suquark): Ensure the type of "driver_id".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

from libcpp.string cimport string as c_string
from libcpp cimport bool as c_bool

from libc.stdint cimport int64_t as c_int64, uint32_t as c_uint32, uint16_t as c_uint16, uint8_t as c_uint8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any clashes or should we just import these as int64_t etc?

cdef extern from "flatbuffers/flatbuffers.h" namespace "flatbuffers":
# Cython cannot rename a template class.
cdef cppclass Offset[T]:
uoffset_t o
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? Shall we call it offset instead?

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11070/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11075/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11084/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11087/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11092/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11093/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11096/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11100/
Test PASSed.

@pcmoritz pcmoritz force-pushed the interface branch 4 times, most recently from 141bc91 to 308985c Compare January 24, 2019 05:57
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11103/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11104/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11105/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11106/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11114/
Test PASSed.

@suquark
Copy link
Member Author

suquark commented Jan 24, 2019

Ready to merge. The CI errors come from the master branch.

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

Successfully merging this pull request may close these issues.

Replace all malloc/free calls with unique_ptr (or equivalent).

5 participants