Skip to content

Add basic functionality for Cython functions and actors - #1193

Merged
pcmoritz merged 6 commits into
ray-project:masterfrom
danielsuo:cython
Nov 10, 2017
Merged

pcmoritz merged 6 commits into
ray-project:masterfrom
danielsuo:cython

Conversation

@danielsuo

@danielsuo danielsuo commented Nov 8, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Can one of the admins verify this patch?

@pcmoritz

pcmoritz commented Nov 8, 2017

Copy link
Copy Markdown
Contributor

ok to test

Comment thread 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.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread python/ray/utils.py Outdated
import ray.local_scheduler


def iscython(obj):

@pcmoritz pcmoritz Nov 8, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread test/cython_test.py Outdated
import cython_examples as cyth


def getRayResult(cython_func, *args):

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

Comment thread python/ray/signature.py Outdated

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

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

@pcmoritz pcmoritz left a comment •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

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

pcmoritz commented Nov 8, 2017

Copy link
Copy Markdown
Contributor

The Jenkins test failure is unrelated cc @richardliaw @ericl

@danielsuo

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

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

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

pcmoritz commented Nov 8, 2017

Copy link
Copy Markdown
Contributor

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

Comment thread examples/cython/cython_main.py Outdated

@cli.command()
def example1():
"Cython def function"

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

Comment thread 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

@richardliaw richardliaw Nov 8, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

@richardliaw richardliaw left a comment •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

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

pcmoritz commented Nov 8, 2017

Copy link
Copy Markdown
Contributor

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.

@robertnishihara robertnishihara left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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.

Comment thread examples/cython/.gitignore Outdated
@@ -0,0 +1,6 @@
build

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

@danielsuo danielsuo Nov 9, 2017 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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.

Comment thread examples/cython/README.md Outdated
@@ -0,0 +1,28 @@
# Cython in Ray

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread 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.

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

danielsuo commented Nov 9, 2017 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor Author

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

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

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
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

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
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor

Tests passed on #1202

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

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