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

Add basic functionality for Cython functions and actors #1193

Merged
merged 6 commits into from
Nov 10, 2017
Merged

Add basic functionality for Cython functions and actors #1193

merged 6 commits into from
Nov 10, 2017

Conversation

danielsuo
Copy link
Contributor

@danielsuo danielsuo commented Nov 8, 2017

A first stab at addressing #944. Tests, including new ones for Cython, pass (besides timeouts) on my latest Travis build.

Some notes for reviewers:

  • Usage here
  • Pay special attention to the signature 'ripping' in signature.py
  • Made some guesses where things might go (e.g., tests, the iscython utility function), but they might be wrong

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@pcmoritz
Copy link
Contributor

pcmoritz commented Nov 8, 2017

ok to test

- 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.
Copy link
Contributor

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great!

Copy link
Collaborator

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?

@@ -12,6 +12,21 @@
import ray.local_scheduler


def iscython(obj):
Copy link
Contributor

@pcmoritz pcmoritz Nov 8, 2017

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.

Copy link
Contributor Author

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.

import cython_examples as cyth


def getRayResult(cython_func, *args):
Copy link
Contributor

Choose a reason for hiding this comment

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

get_ray_result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am deeply ashamed.

@@ -27,6 +29,39 @@
"""


def get_signature_params(func):
"""Get signature parameters
Probably the hackiest thing imaginable to support Cython built-ins. Create
Copy link
Contributor

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 ;)

Copy link
Contributor Author

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.

Copy link
Contributor

@pcmoritz pcmoritz left a 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.

@AmplabJenkins
Copy link

Merged build finished. 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/2297/
Test FAILed.

@pcmoritz
Copy link
Contributor

pcmoritz commented Nov 8, 2017

The Jenkins test failure is unrelated cc @richardliaw @ericl

@danielsuo
Copy link
Contributor Author

@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)?

@AmplabJenkins
Copy link

Merged build finished. 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/2309/
Test FAILed.

@pcmoritz
Copy link
Contributor

pcmoritz commented Nov 8, 2017

@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.


@cli.command()
def example1():
"Cython def function"
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 a particular reason for 1 quote commenting (as opposed to three from above?)

Copy link
Contributor Author

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.

raise TypeError('{0!r} is not a Python function we can process'
.format(func))

return [(k, v) for k, v
Copy link
Contributor

@richardliaw richardliaw Nov 8, 2017

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?

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Done.

Copy link
Contributor

@richardliaw richardliaw left a comment

Choose a reason for hiding this comment

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

Few comments above :)

@danielsuo
Copy link
Contributor Author

@pcmoritz got it, thanks for the repeated explanation.

Separately, related to #1191 and #1185, how should I prepare the branch for merging? It seems like a rebase to the main branch at the end of discussion is what typically happens.

@AmplabJenkins
Copy link

Merged build finished. 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/2311/
Test FAILed.

@pcmoritz
Copy link
Contributor

pcmoritz commented Nov 8, 2017

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.

Copy link
Collaborator

@robertnishihara robertnishihara left a 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
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@@ -0,0 +1,6 @@
build
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@danielsuo danielsuo Nov 9, 2017

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
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@@ -0,0 +1,28 @@
# Cython in Ray
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

- 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.
Copy link
Collaborator

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"""
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@robertnishihara
Copy link
Collaborator

@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.

@danielsuo
Copy link
Contributor Author

danielsuo commented Nov 9, 2017

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 stdout in 10mins for MacOS).

@danielsuo
Copy link
Contributor Author

@robertnishihara appreciate the offer to help, but it seems that you have more than enough on your plate!

@AmplabJenkins
Copy link

Merged build finished. 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/2326/
Test PASSed.

@AmplabJenkins
Copy link

Merged build finished. 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/2327/
Test PASSed.

@AmplabJenkins
Copy link

Merged build finished. 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/2330/
Test PASSed.

@robertnishihara
Copy link
Collaborator

I'm not really sure what's going on with Travis, so I duplicated the PR and am running tests in #1202.

@pcmoritz
Copy link
Contributor

Tests passed on #1202

@pcmoritz pcmoritz merged commit 4f0da6f into ray-project:master Nov 10, 2017
@danielsuo
Copy link
Contributor Author

Very easy PR process, much appreciated!

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.

5 participants