-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Add basic functionality for Cython functions and actors #1193
Conversation
Can one of the admins verify this patch? |
ok to test |
examples/cython/README.md
Outdated
- Several limitations come from Cython's own [unsupported](https://github.com/cython/cython/wiki/Unsupported) Python features. | ||
|
||
## License | ||
We include some code examples from the [BrainIAK](https://github.com/brainiak/brainiak) package. There are licenses associated with those examples, which may (or may not!) cause issue. We can remove prior to any merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the code is Apache 2, which it seems to be, this should be ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's Apache 2, can we remove this section?
python/ray/utils.py
Outdated
@@ -12,6 +12,21 @@ | |||
import ray.local_scheduler | |||
|
|||
|
|||
def iscython(obj): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this to is_cython, while Python often drops the _, in Ray we don't to make it more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I'll change.
test/cython_test.py
Outdated
import cython_examples as cyth | ||
|
||
|
||
def getRayResult(cython_func, *args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_ray_result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am deeply ashamed.
python/ray/signature.py
Outdated
@@ -27,6 +29,39 @@ | |||
""" | |||
|
|||
|
|||
def get_signature_params(func): | |||
"""Get signature parameters | |||
Probably the hackiest thing imaginable to support Cython built-ins. Create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, if there is a better way to do this, consider doing it that way (I don't see one right now); otherwise maybe make the comment sound less terrible, given all things I've seen people do with (to) Python, this is actually not that hacky ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! I'll admit the comment was more CYA, so if you guys are OK with it, then I'll reword the comment since I don't have a better answer. There's been some chatter in the Cython community (one example), but it seems that they're waiting on better Python support before doing anything about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 There are a few nitpicks, otherwise this looks really great! Thanks for contributing this, the Cython functionality will be great (I'm glad you got it working and also glad about the tests). Also locations of the files looks good to me.
Merged build finished. Test FAILed. |
Test FAILed. |
The Jenkins test failure is unrelated cc @richardliaw @ericl |
@pcmoritz Quick question: I saw on some other issue you guys explained why Travis and Jenkins, but I just can't seem to find it. So: why Travis and Jenkins (besides Travis time-outs)? |
Merged build finished. Test FAILed. |
Test FAILed. |
@danielsuo We do some heavier weight distributed tests in Jenkins; it is preferable to do it in Jenkins because the machines it runs on are more powerful and the Travis builds are already quite long as it is. We could do everything in Jenkins but Travis has a very nice UI so we like it for the lighter weight tests. |
examples/cython/cython_main.py
Outdated
|
||
@cli.command() | ||
def example1(): | ||
"Cython def function" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason for 1 quote commenting (as opposed to three from above?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I also noticed that ray prefers double to single quotes where possible, so I changed all those as well.
python/ray/signature.py
Outdated
raise TypeError('{0!r} is not a Python function we can process' | ||
.format(func)) | ||
|
||
return [(k, v) for k, v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for readability will return list(funcsigs.signature(func).parameters.items())
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ah I see this is vestige code from previously; but still would be nice to change to above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments above :)
Merged build finished. Test FAILed. |
Test FAILed. |
According to the github UI there don't seem to be merge conflicts; however Travis doesn't seem to run which normally only happens if there are merge conflicts. We can wait a bit longer and then if Travis still hasn't run the last commit, you can do a rebase anyways and force push and see if that helps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this patch, this is really nice work! I left a few more comments (most extremely minor).
If you don't mind me pushing to your branch, I'm happy to make the changes myself.
python setup.py install --user | ||
popd | ||
|
||
elif [[ "$LINT" == "1" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not install anything in the linting builds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you're right.
examples/cython/.gitignore
Outdated
@@ -0,0 +1,6 @@ | |||
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about moving these to the top-level .gitignore
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing; I put in a local .gitignore
since I didn't want to mess with the top-level one. Would it also be useful to put typical virtual environment directories? I waver on that one because even though there are some conventions (e.g., venv
), it seems like folks have their own preferences / not totally standardized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the ignores for dynamic libraries are already in the top-level .gitignore
.
I think build
is reasonable to go in top-level, but do we want *.c
? The Cython convention is to ignore *.c
files in repositories, but include them in distributions so users don't need to install cython to use the package. The concern is if, for some reason, we have C code. I put added *.c
for now since we're in C++ / Python land.
@@ -0,0 +1,29 @@ | |||
from __future__ import absolute_import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all of the new files, can we use all three
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I held off for the *.pyx files, but included an additional note in the documentation about Python 2 vs. 3 + where folks can get more information.
examples/cython/README.md
Outdated
@@ -0,0 +1,28 @@ | |||
# Cython in Ray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to include this in the online documentation.
That would require moving this to doc/source/
and linking to it from doc/source/index.rst
.
That could be done as a follow up if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
examples/cython/README.md
Outdated
- Several limitations come from Cython's own [unsupported](https://github.com/cython/cython/wiki/Unsupported) Python features. | ||
|
||
## License | ||
We include some code examples from the [BrainIAK](https://github.com/brainiak/brainiak) package. There are licenses associated with those examples, which may (or may not!) cause issue. We can remove prior to any merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's Apache 2, can we remove this section?
|
||
def masked_log(x): | ||
"""x is a 1D numpy array""" | ||
"""returns -Inf for x <=0 and log(x) otherwise""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should only have one doc string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lalala not my fault all upstream. Updated to latest upstream.
@danielsuo there's no need to rebase on the master. We're just confused about why the Travis tests weren't automatically running. But my guess is if we push another commit on top of this then that will trigger the Travis tests. |
Weird, the new commit isn't triggering Travis either. Typically this would happen if the PR isn't mergeable, but just tested and there's nothing conflicting with master. Nothing looks out of the ordinary with Travis either (besides, of course, not building on the last two commits). My Travis was triggered (still has trouble with timeouts and not receiving |
@robertnishihara appreciate the offer to help, but it seems that you have more than enough on your plate! |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
I'm not really sure what's going on with Travis, so I duplicated the PR and am running tests in #1202. |
Tests passed on #1202 |
Very easy PR process, much appreciated! |
A first stab at addressing #944. Tests, including new ones for Cython, pass (besides timeouts) on my latest Travis build.
Some notes for reviewers:
signature.py
iscython
utility function), but they might be wrong