Skip to content

Cross-language invocation Part 1: Java calling Python functions and actors - #4166

Merged
raulchen merged 12 commits into
ray-project:masterfrom
antgroup:xlang
Mar 21, 2019
Merged

raulchen merged 12 commits into
ray-project:masterfrom
antgroup:xlang

Conversation

@raulchen

@raulchen raulchen commented Feb 26, 2019 •

Copy link
Copy Markdown
Contributor

What do these changes do?

Implements Java calling Python functions and actors.

Usage:

  • Call a Python function:
RayObject res = Ray.callPy("module_name", "function_name", arg1, arg2, ...);
  • Call a Python actor:
RayPyActor actor = Ray.createPyActor("module_name", "ClassName", arg1, arg2, ...);
RayObject res = Ray.callPy(actor, "function_name", arg1, arg2);

Note, currently arguments can only be raw binaries. And when putting a binary in object store, we use special metadata to indicate that the object is raw binary and doesn't need serialization/deserialization.

Not implemented in this PR:

  • Python calling Java.
  • Passing actor handle as parameter.

Related issue number

#2576

@raulchen raulchen changed the title [wip] Cross-language invocation: part 1 Cross-language invocation: part 1 Feb 26, 2019
@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/12321/
Test FAILed.

@pcmoritz

pcmoritz commented Feb 27, 2019 •

Copy link
Copy Markdown
Contributor

If we got the eternal bug https://issues.apache.org/jira/browse/ARROW-1692 resolved, we could pass data natively between Java arrow and python arrow :D

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.

Since these args are all untyped, why not use Java varargs? The only caveat is that you'll have to move the creation options a bit earlier.

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.

yeah, varargs would look nicer. But I wanted to make the order aligned with the regular createActor.

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.

What's the random arg for?

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.

Oops, that's an internal hack. I'll remove it.

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.

I found the nullability of functionDescriptor / pyFuncDescriptor confusing. Consider having one type for both, and methods task.functionDescriptor.getLanguage() instead.

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.

sounds good.

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.

Consider merging these two fields to avoid nulls.

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.

Nice.

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.

Too many newlines?

Comment thread java/pom.xml Outdated

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.

What's gson for?

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.

It's actually needed for the next PR (serializing handle with json and pass it to Python), forgot to remove it.

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

Left a few comments.

@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

1 similar comment
@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@ericl

ericl commented Mar 16, 2019 •

Copy link
Copy Markdown
Contributor

@raulchen any follow-up here? Looks like there are some merge conflicts now.

@raulchen

Copy link
Copy Markdown
Contributor Author

@ericl I rebased the PR and addressed your comments.

@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/13036/
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/13046/
Test PASSed.

@raulchen raulchen changed the title Cross-language invocation: part 1 Cross-language invocation Part 1: Java calling Python functions and actors Mar 20, 2019
@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/13070/
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/13089/
Test PASSed.

@raulchen

Copy link
Copy Markdown
Contributor Author

CI failure is related, but I cannot reproduce it on my machine. Will check tomorrow.

/**
* Represents metadata of a Python function.
*/
public class PyFunctionDescriptor {

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.

For the sake of a little more type safety, how about having both this and FunctionDescriptor extend the same interface or base class?

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.

Thanks, will change.

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

Looks good -- just one comment on having a common base class for a bit more type safety.

It would also be nice to add an example of Python->Java calls, if there is a use case for that.

@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/13100/
Test FAILed.

@raulchen

raulchen commented Mar 21, 2019 •

Copy link
Copy Markdown
Contributor Author

@ericl Python calling Java will be implemented in next PR. Although it's already doable with low-level api, I'd like to create a higher-level API for convenience in next PR. I haven't thought thoroughly about the API, it may be something like the following. Suggestions are welcome!

java_func = ray.experimental.java_task("package.name", "ClassName", "staticMethodName", "typeDescriptor")
java_func.remote(args)

java_actor = ray.experimental.create_java_actor("package.name", "ClassName")
java_actor.method("methodName", "typeDescriptor").remote(args)

@ericl

ericl commented Mar 21, 2019

Copy link
Copy Markdown
Contributor

Sounds good. I think the experimental syntax looks fine for an initial release; you could also try to wrap the actors to provide a bit more of a pythonic API.

@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/13126/
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/13123/
Test FAILed.

@raulchen
raulchen merged commit d03999d into ray-project:master Mar 21, 2019
@raulchen
raulchen deleted the xlang branch March 21, 2019 05:34
@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/13127/
Test PASSed.

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.

4 participants