ray-project / ray

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
33.15k stars 5.61k forks source link

[Core][Feature request] Promote `actor_handle._actor_id` to public API #32638

Open cadedaniel opened 1 year ago

cadedaniel commented 1 year ago

We should promote _actor_id to public API and also make it a usable string, e.g. repr does not add anything except the ID.

>>> a._actor_id
ActorID(811a6143d62d08e4d6e447c21c000000)
# This should change to just return '811a6143d62d08e4d6e447c21c000000'

Example use case is in combination with the State API:

import ray

ray.init()

@ray.remote
class A:
    pass

a = A.remote()

# Use here instead of this hack
obj_ref = str(a).replace('Actor(A, ', '').replace(')', '')

from ray.experimental.state.api import get_actor
print(get_actor(id=obj_ref))
pcmoritz commented 1 year ago

Yeah, exposing actor_handle.actor_id() seems like a no-brainer here. I think it should actually be actor_handle.get_actor_id() and return a string to be consistent with the APIs in https://docs.ray.io/en/master/ray-core/api/doc/ray.runtime_context.RuntimeContext.html

Any thoughts @ericl or @scv119 ?

ericl commented 1 year ago

Wouldn't this conflict with a method called 'get_actor_id' on the actual actor?

pcmoritz commented 1 year ago

Great point! So maybe be consistent with the other "hidden" methods then, call it actor_handle.__ray_actor_id__() then and still make it public? Or keep it like it is and make it public?

ericl commented 1 year ago

__ray_terminate__ launches a remote method, so we should probably make this syntactically different. I'd vote to make the current thing public.

jovany-wang commented 1 year ago

I'd vote to make the current thing public.

vote +1

pcmoritz commented 1 year ago

Alright, sounds good to me! This has the advantage that it doesn't need migrations. We can just say in the docs even though this starts with an underscore to not clash with actor methods, this is a public interface or something like that :)

pcmoritz commented 1 year ago

I think the main action item of this issue will be to add ActorHandle to https://docs.ray.io/en/latest/ray-core/package-ref.html and make sure this is documented.

scv119 commented 1 year ago

Would an alternative is to add an helper method ray.get_actor_id(actor_handle)?

stale[bot] commented 1 year ago

Hi, I'm a bot from the Ray team :)

To help human contributors to focus on more relevant issues, I will automatically add the stale label to issues that have had no activity for more than 4 months.

If there is no further activity in the 14 days, the issue will be closed!

You can always ask for help on our discussion forum or Ray's public slack channel.

stale[bot] commented 11 months ago

Hi again! The issue will be closed because there has been no more activity in the 14 days since the last message.

Please feel free to reopen or open a new issue if you'd still like it to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for opening the issue!

krtkvrm commented 3 months ago

can I take this up ?