
    rii                         d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZmZmZ dedefd	Z G d
 d          ZdS )zTracker for XGBoost collective.    N)IntEnumunique)DictOptionalUnion   )_LIB_check_call_deprecate_positional_argsmake_jcargsaddrreturnc                 D    t          j        | d          d         d         S )z Get network family from address.Nr   )socketgetaddrinfo)r   s    U/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/xgboost/tracker.py
get_familyr      s    dD))!,Q//    c                       e Zd ZdZe G d de                      Ze	 dddddede	e
         d	ed
e
deddfd            ZddZddZddZdde	e         ddfdZdee
ee
ef         f         fdZdS )RabitTrackeraY  Tracker for the collective used in XGBoost, acting as a coordinator between
    workers.

    Parameters
    ----------

    n_workers:

        The total number of workers in the communication group.

    host_ip:

        The IP address of the tracker node. XGBoost can try to guess one by probing with
        sockets. But it's best to explicitly pass an address.

    port:

        The port this tracker should listen to. XGBoost can query an available port from
        the OS, this configuration is useful for restricted network environments.

    sortby:

        How to sort the workers for rank assignment. The default is host, but users can
        set the `DMLC_TASK_ID` via arguments of :py:meth:`~xgboost.collective.init` and
        obtain deterministic rank assignment through sorting by task name. Available
        options are:

          - host
          - task

    timeout :

        Timeout for constructing (bootstrap) and shutting down the communication group,
        doesn't apply to communication when the group is up and running.

        The timeout value should take the time of data loading and pre-processing into
        account, due to potential lazy execution. By default the Tracker doesn't have
        any timeout to avoid pre-mature aborting.

        The :py:meth:`.wait_for` method has a different timeout parameter that can stop
        the tracker even if the tracker is still being used. A value error is raised
        when timeout is reached.

    Examples
    --------

    .. code-block:: python

        from xgboost.tracker import RabitTracker
        from xgboost import collective as coll

        tracker = RabitTracker(host_ip="127.0.0.1", n_workers=2)
        tracker.start()

        with coll.CommunicatorContext(**tracker.worker_args()):
            ret = coll.broadcast("msg", 0)
            assert str(ret) == "msg"

    c                       e Zd ZdZdZdS )RabitTracker._SortByr   r   N)__name__
__module____qualname__HOSTTASK r   r   _SortByr   N   s        r   r   r   host)sortbytimeout	n_workershost_ipportr!   r"   r   Nc          
      f   t          j                    }|dvrt          d          |t          |           t	          |||d|dk    r| j        j        n| j        j        t          |                    }t          t          j        |t          j        |                               || _        d S )N)r    taskz-Expecting either 'host' or 'task' for sortby.rabitr    )r    r#   r%   dmlc_communicatorr!   r"   )ctypesc_void_p
ValueErrorr   r   r   r   r   intr
   r	   XGTrackerCreatebyrefhandle)selfr#   r$   r%   r!   r"   r0   argss           r   __init__zRabitTracker.__init__S   s     "")))LMMMw%(.&(8(84<$$dl>OLL
 
 
 	D(v|F/C/CDDEEEr   c                 ~    t          | d          r,| j        }| `t          t          j        |                     dS dS )zInternal function for testing.r0   N)hasattrr0   r
   r	   XGTrackerFree)r1   r0   s     r   freezRabitTracker.freen   sI    4"" 	4[F*62233333	4 	4r   c                 .    |                                   d S N)r7   r1   s    r   __del__zRabitTracker.__del__u   s    		r   c                 l    t          t          j        | j        t	                                           dS )zStart the tracker. Once started, the client still need to call the
        :py:meth:`wait_for` method in order to wait for it to finish (think of it as a
        thread).

        N)r
   r	   XGTrackerRunr0   r   r:   s    r   startzRabitTracker.startx   s+     	D%dk;==AABBBBBr   c                 p    t          t          j        | j        t	          |                               dS )zWait for the tracker to finish all the work and shutdown. When timeout is
        reached, a value error is raised. By default we don't have timeout since we
        don't know how long it takes for the model to finish training.

        )r"   N)r
   r	   XGTrackerWaitForr0   r   )r1   r"   s     r   wait_forzRabitTracker.wait_for   s2     	D)$+{77S7S7STTUUUUUr   c                     t          j                    }t          t          j        | j        t          j        |                               |j        J t          j	        |j                  }|S )zGet arguments for workers.)
r*   c_char_pr
   r	   XGTrackerWorkerArgsr0   r/   valuejsonloads)r1   c_envenvs      r   worker_argszRabitTracker.worker_args   sZ    !!D,T[&,u:M:MNNOOO{&&&j%%
r   )r   )r   Nr9   )r   r   r   __doc__r   r   r   r   r-   r   strr3   r7   r;   r>   rA   r   r   rJ   r   r   r   r   r      so       : :x     '   V  
 	    # 	   
    44 4 4 4   C C C CV V V V V V VT#uS#X"67      r   r   )rK   r*   rF   r   enumr   r   typingr   r   r   corer	   r
   r   r   rL   r-   r   r   r   r   r   <module>rP      s    % %                    ( ( ( ( ( ( ( ( ( ( L L L L L L L L L L L L0S 0S 0 0 0 0
} } } } } } } } } }r   