
    &`i
                         d dl Z d dlmZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 erd dlmZ  e
d           G d	 d
e                      ZdS )    N)Path)TYPE_CHECKINGOptional)FrameworkCheckpoint)	PublicAPI)Preprocessorbeta)	stabilityc            
       ~    e Zd ZdZdZeddddej        ded         dee	         d	d fd
            Z
d	ej        fdZdS )XGBoostCheckpointzHA :py:class:`~ray.train.Checkpoint` with XGBoost-specific functionality.z
model.jsonN)preprocessorpathboosterr   r   r   returnc                   t          |pt          j                              }|                                st	          d|           |                    |                    | j                                                             | 	                    |                                          }|r|
                    |           |S )aV  Create a :py:class:`~ray.train.Checkpoint` that stores an XGBoost
        model.

        Args:
            booster: The XGBoost model to store in the checkpoint.
            preprocessor: A fitted preprocessor to be applied before inference.
            path: The path to the directory where the checkpoint file will be saved.
                This should start as an empty directory, since the *entire*
                directory will be treated as the checkpoint when reported.
                By default, a temporary directory will be created.

        Returns:
            An :py:class:`XGBoostCheckpoint` containing the specified ``Estimator``.

        Examples:

            ... testcode::

                import numpy as np
                import ray
                from ray.train.xgboost import XGBoostCheckpoint
                import xgboost

                train_X = np.array([[1, 2], [3, 4]])
                train_y = np.array([0, 1])

                model = xgboost.XGBClassifier().fit(train_X, train_y)
                checkpoint = XGBoostCheckpoint.from_model(model.get_booster())

        z%`path` must be a directory, but got: )r   tempfilemkdtempis_dir
ValueError
save_modeljoinpathMODEL_FILENAMEas_posixfrom_directoryset_preprocessor)clsr   r   r   checkpoint_path
checkpoints         x/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/train/xgboost/xgboost_checkpoint.py
from_modelzXGBoostCheckpoint.from_model   s    L t9x'7'9'9::%%'' 	XV_VVWWW?33C4FGGPPRRSSS''(@(@(B(BCC
 	6''555    c                     |                                  5 }t          j                    }|                    t	          || j                                                             |cddd           S # 1 swxY w Y   dS )z5Retrieve the XGBoost model stored in this checkpoint.N)as_directoryxgboostBooster
load_modelr   r   r   )selfr   r   s      r   	get_modelzXGBoostCheckpoint.get_modelF   s       	Oo''GtOT5HIIRRTTUUU	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA11A58A5)__name__
__module____qualname____doc__r   classmethodr$   r%   r   strr    r(    r!   r   r   r      s        RR!N
 26"/ / // ~.	/
 sm/ 
/ / / [/b7?      r!   r   )r   pathlibr   typingr   r   r$   (ray.train._internal.framework_checkpointr   ray.util.annotationsr   ray.data.preprocessorr   r   r/   r!   r   <module>r5      s           * * * * * * * *  H H H H H H * * * * * * 3222222 V< < < < <+ < < < < <r!   