ray.util.get_current_placement_group#

ray.util.get_current_placement_group() PlacementGroup | None[source]#

Get the current placement group which a task or actor is using.

It returns None if there’s no current placement group for the worker. For example, if you call this method in your driver, it returns None (because drivers never belong to any placement group).

Examples

import ray
from ray.util.placement_group import get_current_placement_group
from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy

@ray.remote
def f():
    # This returns the placement group the task f belongs to.
    # It means this pg is identical to the pg created below.
    return get_current_placement_group()

pg = ray.util.placement_group([{"CPU": 2}])
assert ray.get(f.options(
        scheduling_strategy=PlacementGroupSchedulingStrategy(
            placement_group=pg)).remote()) == pg

# Driver doesn't belong to any placement group,
# so it returns None.
assert get_current_placement_group() is None
Returns:

Placement group object.

None if the current task or actor wasn’t created with any placement group.

Return type:

PlacementGroup