
    &`iP                         d dl Z d dlmZmZ d dlmZ d dlmZmZ d dl	m
Z
  ed           G d d	e                      Zedd
eeeef                  fd            ZdS )    N)DictOptional)ResourceRequest)DeveloperAPI	PublicAPI)placement_groupbeta)	stabilityc                       e Zd ZdZd ZdS )PlacementGroupFactorya
  Wrapper class that creates placement groups for trials.

    This function should be used to define resource requests for Ray Tune
    trials. It holds the parameters to create
    :ref:`placement groups <ray-placement-group-doc-ref>`.
    At a minimum, this will hold at least one bundle specifying the
    resource requirements for each trial:

    .. code-block:: python

        from ray import tune

        tuner = tune.Tuner(
            tune.with_resources(
                train,
                resources=tune.PlacementGroupFactory([
                    {"CPU": 1, "GPU": 0.5, "custom_resource": 2}
                ])
            )
        )
        tuner.fit()

    If the trial itself schedules further remote workers, the resource
    requirements should be specified in additional bundles. You can also
    pass the placement strategy for these bundles, e.g. to enforce
    co-located placement:

    .. code-block:: python

        from ray import tune

        tuner = tune.Tuner(
            tune.with_resources(
                train,
                resources=tune.PlacementGroupFactory([
                    {"CPU": 1, "GPU": 0.5, "custom_resource": 2},
                    {"CPU": 2},
                    {"CPU": 2},
                ], strategy="PACK")
            )
        )
        tuner.fit()

    The example above will reserve 1 CPU, 0.5 GPUs and 2 custom_resources
    for the trainable itself, and reserve another 2 bundles of 2 CPUs each.
    The trial will only start when all these resources are available. This
    could be used e.g. if you had one learner running in the main trainable
    that schedules two remote workers that need access to 2 CPUs each.

    If the trainable itself doesn't require resources.
    You can specify it as:

    .. code-block:: python

        from ray import tune

        tuner = tune.Tuner(
            tune.with_resources(
                train,
                resources=tune.PlacementGroupFactory([
                    {},
                    {"CPU": 2},
                    {"CPU": 2},
                ], strategy="PACK")
            )
        )
        tuner.fit()

    Args:
        bundles: A list of bundles which
            represent the resources requirements.
        strategy: The strategy to create the placement group.

         - "PACK": Packs Bundles into as few nodes as possible.
         - "SPREAD": Places Bundles across distinct nodes as even as possible.
         - "STRICT_PACK": Packs Bundles into one node. The group is
           not allowed to span multiple nodes.
         - "STRICT_SPREAD": Packs Bundles across distinct nodes.
        *args: Passed to the call of ``placement_group()``
        **kwargs: Passed to the call of ``placement_group()``

    c                     t          j        dt                     |                    | j        j                   t          | j        j        i |S )NzXCalling PlacementGroupFactory objects is deprecated. Use `to_placement_group()` instead.)warningswarnDeprecationWarningupdate_boundkwargsr   args)selfr   r   s      w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/execution/placement_groups.py__call__zPlacementGroupFactory.__call__^   sO    .	
 	
 	

 	dk())) 0;F;;;    N)__name__
__module____qualname____doc__r    r   r   r   r   	   s0        Q Qf< < < < <r   r   specc                    | pddi} |                                  } |                     d|                     dd                    }|                     d|                     dd                    }|                     dd          }t          |                     di                     }|s| }|                    |||d	           t	          |g          S )
z4Translates resource dict into PlacementGroupFactory.cpu   CPUg        gpuGPUmemorycustom_resources)r"   r$   r%   )copypopdictr   r   )r   cpusgpusr%   bundles        r   resource_dict_to_pg_factoryr-   i   s     E1:D99;;D88E488E3//00D88E488E3//00DXXh$$F $((-r2233F  
MM	
 	
   !&***r   )N)r   typingr   r   #ray.air.execution.resources.requestr   ray.util.annotationsr   r   ray.util.placement_groupr   r   strfloatr-   r   r   r   <module>r4      s     ! ! ! ! ! ! ! ! ? ? ? ? ? ? 8 8 8 8 8 8 8 8 4 4 4 4 4 4 V\< \< \< \< \<O \< \< \<~ + +htCJ/?&@ + + + + + +r   