
    Pi                         d dl Z d dlmZmZmZmZmZ  e j        e          Z	 edd          Z
 G d dee
                   ZdS )    N)AnyDictIteratorOptionalTypeVarTT)	covariantc                       e Zd ZdZd Zd Zddee         fdZde	e
ef         fdZdefd	Zd
 Zde	e
ef         fdZdS )BaseNodea  BaseNodes are the base class for creating composable dataloading DAGs in ``torchdata.nodes``.

    Most end-users will not iterate over a BaseNode instance directly, but instead
    wrap it in a :class:`torchdata.nodes.Loader` which converts the DAG into a more familiar Iterable.

    .. code-block:: python

        node = MyBaseNodeImpl()
        loader = Loader(node)
        # loader supports state_dict() and load_state_dict()

        for epoch in range(5):
            for idx, batch in enumerate(loader):
                ...

        # or if using node directly:
        node = MyBaseNodeImpl()
        for epoch in range(5):
            node.reset()
            for idx, batch in enumerate(loader):
                ...
    c                     d| _         dS )zPSubclasses must implement this method and call super().__init__(*args, **kwargs)FN_BaseNode__initialized)selfargskwargss      m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchdata/nodes/base_node.py__init__zBaseNode.__init__(   s    "    c                     | S N r   s    r   __iter__zBaseNode.__iter__,   s    r   Ninitial_statec                     d| _         dS )a  Resets the iterator to the beginning, or to the state passed in by initial_state.

        Reset is a good place to put expensive initialization, as it will be lazily called when ``next()`` or ``state_dict()`` is called.
        Subclasses must call ``super().reset(initial_state)``.

        Args:
            initial_state: Optional[dict] - a state dict to pass to the node. If None, reset to the beginning.
        TNr   )r   r   s     r   resetzBaseNode.reset/   s     "r   returnc                 :    t          t          |                     )zSubclasses must implement this method, instead of ``state_dict()``. Should only be called by BaseNode.

        Returns:
            Dict[str, Any] - a state dict that may be passed to ``reset()`` at some point in the future
        NotImplementedErrortyper   s    r   	get_statezBaseNode.get_state;        "$t**---r   c                 :    t          t          |                     )zSubclasses must implement this method, instead of ``__next__``. Should only be called by BaseNode.

        Returns:
            T - the next value in the sequence, or throw StopIteration
        r   r   s    r   nextzBaseNode.nextC   r#   r   c                    	 | j          n-# t          $ r  t          dt          |                     w xY w| j         s;|                     d            | j         st          dt          |                     |                                 S )NJself.__initialized not found, did you call super().__init__()? type(self)=fFailed to initialize after .reset(), did you call super().reset() in your .reset() method? type(self)=)r   AttributeErrorr    r!   r   r%   r   s    r   __next__zBaseNode.__next__K   s    	w 	w 	w 	w%&uhlmqhrhr&u&uvvv	w! 	JJt% )rvw{r|r|   yy{{   
 *4c                    	 | j          n-# t          $ r  t          dt          |                     w xY w| j         s;|                     d           | j         st          dt          |                     |                                 S )zGet a state_dict for this BaseNode.

        Returns:
            Dict[str, Any] - a state dict that may be passed to ``reset()`` at some point in the future.
        r'   Nr(   )r   r)   r    r!   r   r"   r   s    r   
state_dictzBaseNode.state_dictX   s    	w 	w 	w 	w%&uhlmqhrhr&u&uvvv	w ! 	JJt% )rvw{r|r|   ~~r+   r   )__name__
__module____qualname____doc__r   r   r   dictr   r   strr   r"   r   r%   r*   r-   r   r   r   r   r      s         .# # #  
" 
"8D> 
" 
" 
" 
".4S> . . . ..a . . . .   DcN            r   r   )loggingtypingr   r   r   r   r   	getLoggerr.   loggerr   r   r   r   r   <module>r8      s     9 9 9 9 9 9 9 9 9 9 9 9 9 9		8	$	$ GC4   Y  Y  Y  Y  Y x{ Y  Y  Y  Y  Y r   