§
    qŠtjK  ã                   ól   — d dl Z d dlmZ d dlmZmZ d dlmZ  G d„ d¦  «        Zed„ ¦   «         Z	d„ Z
dS )	é    N)Úcontextmanager)ÚAutoPropagatedCallbackÚFitCallback)ÚCallbackContextc                   ó"   — e Zd ZdZd„ Z	 dd„ZdS )	ÚCallbackSupportMixinzˆMixin class to add callback support to an estimator.

    .. document the private method
    .. automethod:: _init_callback_context
    c                 óº   — t          d„ |D ¦   «         ¦  «        st          d¦  «        ‚|rt          |¦  «        | _        n| j                             dd¦  «         | S )a  Set callbacks for the estimator.

        Parameters
        ----------
        *callbacks : callback instances
            The callbacks to set.

        Returns
        -------
        self : estimator instance
            The estimator instance itself.
        c              3   ól   K  — | ]/}t          |t          ¦  «        ot          |t          ¦  «         V — Œ0d S ©N)Ú
isinstancer   Útype)Ú.0Úcallbacks     ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/callback/_callback_support.pyú	<genexpr>z5CallbackSupportMixin.set_callbacks.<locals>.<genexpr>   sT   è è € ð 
ð 
ð õ �x¥Ñ-Ô-ÐPµjÀÍ4Ñ6PÔ6PÐ2Pð
ð 
ð 
ð 
ð 
ð 
ó    z?callbacks must be instances following the FitCallback protocol.Ú_skl_callbacksN)ÚallÚ	TypeErrorÚlistr   Ú__dict__Úpop)ÚselfÚ	callbackss     r   Úset_callbacksz"CallbackSupportMixin.set_callbacks   s„   € õ ð 
ð 
ð &ð	
ñ 
ô 
ñ 
ô 
ð 	õ ØQñô ð ð ð 	6Ý"& y¡/¤/ˆDÔÐàŒM×ÒÐ.°Ñ5Ô5Ð5àˆr   Úfitr   Tc                 ó8  — t          j        | ||||¬¦  «        | _        g | _        t	          | dg ¦  «        D ]]}t          |t          ¦  «        rt          | d¦  «        s6| j                             |¦  «         | 	                    | | j        ¬¦  «         Œ^| j        S )aP  Initialize the callback context for the estimator and setup its callbacks.

        This method should be called once, at the beginning of the fit method.

        It will only setup callbacks that are not propagated from a meta-estimator.

        Parameters
        ----------
        task_name : str, default="fit"
            The name of the root task.

        task_id : int, default=0
            Identifier for the root task.

        max_subtasks : int or None, default=0
            The maximum number of subtasks that can be children of the root task. None
            means the maximum number of subtasks is not known in advance. 0 means it's a
            leaf.

        sequential_subtasks : bool, default=True
            Whether the root context has sequential subtasks. If True, children contexts
            of the root context, created via `subcontext`, will have automatically
            assigned consecutive integer task_ids starting from 0.

        Returns
        -------
        callback_fit_ctx : CallbackContext
            The root callback context for the estimator.
        )Ú	estimatorÚ	task_nameÚtask_idÚmax_subtasksÚsequential_subtasksr   Ú_parent_callback_ctx©r   Úcontext)
r   Ú_from_estimatorÚ_callback_fit_ctxÚ_skl_callbacks_to_teardownÚgetattrr   r   ÚhasattrÚappendÚsetup)r   r   r    r!   r"   r   s         r   Ú_init_callback_contextz+CallbackSupportMixin._init_callback_context0   s¼   € õ@ "1Ô!@ØØØØ%Ø 3ð"
ñ "
ô "
ˆÔð +-ˆÔ'Ý Ð&6¸Ñ;Ô;ð 	Oð 	OˆHõ ˜8Õ%;Ñ<Ô<ðOå˜DÐ"8Ñ9Ô9ðOð Ô/×6Ò6°xÑ@Ô@Ð@Ø—’¨°tÔ7M�ÑNÔNÐNøàÔ%Ð%r   N)r   r   r   T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r-   © r   r   r   r      sH   € € € € € ðð ðð ð ð> OSð5&ð 5&ð 5&ð 5&ð 5&ð 5&r   r   c              #   óz  K  — 	 dV — t          | d¦  «        r†g }| j        D ]K}	 |                     | | j        ¬¦  «         Œ # t          $ r}|                     |¦  «         Y d}~ŒDd}~ww xY w| `| `t          |¦  «        dk    r|d         ‚|rt          d|¦  «        ‚dS dS # t          | d¦  «        r†g }| j        D ]K}	 |                     | | j        ¬¦  «         Œ # t          $ r}|                     |¦  «         Y d}~ŒDd}~ww xY w| `| `t          |¦  «        dk    r|d         ‚|rt          d|¦  «        ‚w xY w)a¹  Context manager to manage callback lifecycle around estimator fit.

    The context manager is responsible for calling the callbacks `teardown` hook in a
    `try finally` block, which guarantees that callbacks teardown will always be called,
    whether the estimator's fit exits successfully or not.

    Parameters
    ----------
    estimator : estimator instance
        The estimator being fitted.

    Yields
    ------
    None.
    Nr'   r$   é   r   z/The following callback teardown errors occurred)r*   r(   Úteardownr'   Ú	Exceptionr+   ÚlenÚExceptionGroup)r   Úteardown_errorsr   Úexcs       r   Úcallback_management_contextr;   h   s  è è € ð"Øˆˆˆå�9Ð1Ñ2Ô2ð 	Ø ˆOØ%Ô@ð 0ð 0�ð0Ø×%Ò%Ø"+°YÔ5Pð &ñ ô ð ð øõ !ð 0ð 0ð 0Ø#×*Ò*¨3Ñ/Ô/Ð/Ð/Ð/Ð/Ð/Ð/øøøøð0øøøð Ð4ØÐ+Ý�?Ñ#Ô# qÒ(Ð(Ø% aÔ(Ð(Øð Ý$ØEØ#ñô ð ð	ð 	ðð øõ �9Ð1Ñ2Ô2ð 	Ø ˆOØ%Ô@ð 0ð 0�ð0Ø×%Ò%Ø"+°YÔ5Pð &ñ ô ð ð øõ !ð 0ð 0ð 0Ø#×*Ò*¨3Ñ/Ô/Ð/Ð/Ð/Ð/Ð/Ð/øøøøð0øøøð Ð4ØÐ+Ý�?Ñ#Ô# qÒ(Ð(Ø% aÔ(Ð(Øð Ý$ØEØ#ñô ð ð ð ð ð sL   „B" ¤AÁ
A*ÁA%Á%A*Â"D:Â?CÃD:Ã
D	Ã&D 	Ã;D:Ä D	Ä5D:c                 óF   ‡ — t          j        ‰ ¦  «        ˆ fd„¦   «         }|S )a6  Decorator to run the method within a callback context manager.

    This decorator is responsible for calling the callbacks `teardown` hooks of
    callbacks in a `try finally` block, which guarantees that callbacks teardown will
    always be called, whether the estimator's method exits successfully or not.

    It will only teardown callbacks that are not propagated from a meta-estimator.

    Parameters
    ----------
    method : method
        The method to decorate.

    Returns
    -------
    decorated_method : method
        The decorated method.
    c                 ón   •— t          | ¦  «        5   ‰| g|¢R i |¤Žcd d d ¦  «         S # 1 swxY w Y   d S r   )r;   )r   ÚargsÚkwargsÚmethods      €r   Úcallback_managed_methodz/with_callbacks.<locals>.callback_managed_method¥   s’   ø€ å(¨Ñ3Ô3ð 	6ð 	6Ø�6˜)Ð5 dÐ5Ð5Ð5¨fÐ5Ð5ð	6ð 	6ð 	6ð 	6ñ 	6ô 	6ð 	6ð 	6ð 	6ð 	6ð 	6ð 	6øøøð 	6ð 	6ð 	6ð 	6ð 	6ð 	6s   ‘*ª.±.)Ú	functoolsÚwraps)r@   rA   s   ` r   Úwith_callbacksrD   ‘   s;   ø€ õ( „_�VÑÔð6ð 6ð 6ð 6ñ Ôð6ð #Ð"r   )rB   Ú
contextlibr   Úsklearn.callback._baser   r   Ú"sklearn.callback._callback_contextr   r   r;   rD   r2   r   r   ú<module>rH      sµ   ðð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ >Ð >Ð >Ð >Ð >Ð >ðZ&ð Z&ð Z&ð Z&ð Z&ñ Z&ô Z&ð Z&ðz ð%ð %ñ „ð%ðP#ð #ð #ð #ð #r   