
    h                        S SK r S SKJrJrJrJr  S SKrS SKJ	r	  S SK
Jr  S SKJrJrJr  S SKJr  S\R$                  S\\R(                     S	\\R(                     4S
 jrS\R$                  S\\R(                     S	\4S jr          SS\\\S\R$                  4   4   S\S\\   S\S\\   S\\\R$                  /\R$                  4      S\\\\4      S\\\\\4         S\\\\4      S\\\\4      S\\\\4      S	\4S jjr         SS\\\S\R$                  4   4   S\S\\   S\S\\   S\\\\4      S\\\\4      S\\\\   \\   4      S\\\\4      S\\\\4      S	\4S jjrg)    N)AnyCallableOptionalUnion)AtariWrapper)Monitor)DummyVecEnvSubprocVecEnvVecEnv)
_patch_envenvwrapper_classreturnc                     U n[        U[        R                  5      (       a?  [        X!5      (       a  U$ UR                  n[        U[        R                  5      (       a  M?  g)z
Retrieve a ``VecEnvWrapper`` object by recursively searching.

:param env: Environment to unwrap
:param wrapper_class: Wrapper to look for
:return: Environment unwrapped till ``wrapper_class`` if it has been wrapped with it
N)
isinstancegymWrapperr   )r   r   env_tmps      [/home/james-whalen/.local/lib/python3.13/site-packages/stable_baselines3/common/env_util.pyunwrap_wrapperr      sK     G
Wckk
*
*g--N++ Wckk
*
*     c                     [        X5      SL$ )z
Check if a given environment has been wrapped with a given wrapper.

:param env: Environment to check
:param wrapper_class: Wrapper class to look for
:return: True if environment has been wrapped with ``wrapper_class``.
N)r   )r   r   s     r   
is_wrappedr      s     #-T99r   env_id.n_envsseedstart_indexmonitor_dir
env_kwargsvec_env_clsvec_env_kwargsmonitor_kwargswrapper_kwargsc           	      b  ^ ^^^^^	^
 T=(       d    0 mU=(       d    0 nT	=(       d    0 m	T
=(       d    0 m
Uc   eS[         S[        / [        R                  4   4U UUU	UUU
4S jjnUc  [        nU" [        U5       Vs/ s H  o" X-   5      PM     sn40 UD6nUR                  T5        U$ s  snf )a  
Create a wrapped, monitored ``VecEnv``.
By default it uses a ``DummyVecEnv`` which is usually faster
than a ``SubprocVecEnv``.

:param env_id: either the env ID, the env class or a callable returning an env
:param n_envs: the number of environments you wish to have in parallel
:param seed: the initial seed for the random number generator
:param start_index: start rank index
:param monitor_dir: Path to a folder where the monitor files will be saved.
    If None, no file will be written, however, the env will still be wrapped
    in a Monitor wrapper to provide additional information about training.
:param wrapper_class: Additional wrapper to use on the environment.
    This can also be a function with single argument that wraps the environment in many things.
    Note: the wrapper specified by this parameter will be applied after the ``Monitor`` wrapper.
    if some cases (e.g. with TimeLimit wrapper) this can lead to undesired behavior.
    See here for more details: https://github.com/DLR-RM/stable-baselines3/issues/894
:param env_kwargs: Optional keyword argument to pass to the env constructor
:param vec_env_cls: A custom ``VecEnv`` class constructor. Default: None.
:param vec_env_kwargs: Keyword arguments to pass to the ``VecEnv`` class constructor.
:param monitor_kwargs: Keyword arguments to pass to the ``Monitor`` class constructor.
:param wrapper_kwargs: Keyword arguments to pass to the ``Wrapper`` class constructor.
:return: The wrapped environment
rankr   c           	      H   >^  S[         R                  4UUUUU UUU4S jjnU$ )Nr   c                  (  > Tc   eT
c   eTc   e[        T[        5      (       a.  SS0n U R                  T5         [        R                  " T40 U D6nOT" S0 TD6n[        U5      nTb  UR                  R                  TT-   5        Tb)  [        R                  R                  T[        T5      5      OS nUb  Tb  [        R                  " TSS9  [        U4SU0TD6nT	b	  T	" U40 T
D6nU$ ! [
         a    [        R                  " T40 TD6n Nf = f)Nrender_mode	rgb_arrayT)exist_okfilename )r   strupdater   make	TypeErrorr   action_spacer   ospathjoinmakedirsr   )kwargsr   monitor_pathr   r   r   r"   r%   r   r   r#   s      r   _init-make_vec_env.<locals>.make_env.<locals>._initS   s)   !---!---)))&#&&'5j)9((64V4C *z* o   %%dTk2 DOCZ277<<SY?`dL'K,CK$7#GGGC(#C:>:J+ ! 9((68Z8C9s   C- -!DD)r   Env)	r%   r8   r   r   r   r"   r   r   r#   s	   ` r   make_envmake_vec_env.<locals>.make_envR   s     !	sww !	 !	F r   )intr   r   r:   r	   ranger   )r   r   r   r   r   r   r   r    r!   r"   r#   r;   ivec_envs   ` ` ```  ``   r   make_vec_envrA   '   s    J !rJ#)rN#)rN#)rN%%%$s $xCGG4 $ $N !eFmLm8AO4mL_P^_GLLN Ms   >B,c
                 0    [        U UUUU[        UUUU	US9$ )a  
Create a wrapped, monitored VecEnv for Atari.
It is a wrapper around ``make_vec_env`` that includes common preprocessing for Atari games.

:param env_id: either the env ID, the env class or a callable returning an env
:param n_envs: the number of environments you wish to have in parallel
:param seed: the initial seed for the random number generator
:param start_index: start rank index
:param monitor_dir: Path to a folder where the monitor files will be saved.
    If None, no file will be written, however, the env will still be wrapped
    in a Monitor wrapper to provide additional information about training.
:param wrapper_kwargs: Optional keyword argument to pass to the ``AtariWrapper``
:param env_kwargs: Optional keyword argument to pass to the env constructor
:param vec_env_cls: A custom ``VecEnv`` class constructor. Default: None.
:param vec_env_kwargs: Keyword arguments to pass to the ``VecEnv`` class constructor.
:param monitor_kwargs: Keyword arguments to pass to the ``Monitor`` class constructor.
:return: The wrapped environment
)
r   r   r   r   r   r   r    r!   r"   r#   )rA   r   )
r   r   r   r   r   r#   r   r    r!   r"   s
             r   make_atari_envrC      s2    < "%%% r   )
   Nr   NNNNNNN)	rD   Nr   NNNNNN)r2   typingr   r   r   r   	gymnasiumr   'stable_baselines3.common.atari_wrappersr    stable_baselines3.common.monitorr    stable_baselines3.common.vec_envr	   r
   r   *stable_baselines3.common.vec_env.patch_gymr   r:   typer   r   boolr   r-   r=   dictrA   rC   r,   r   r   <module>rN      s   	 1 1  @ 4 O O A S[[0A hs{{F[  :CGG :D,= :$ : !%<@+/EI/3/3/3Y#xSWW--.YY 3-Y 	Y
 #Y HcggY%789Y c3h(Y $u[-%?@ABY T#s(^,Y T#s(^,Y T#s(^,Y Y| !%/3+/KO/3/3*#xSWW--.** 3-* 	*
 #* T#s(^,* c3h(* %[ 143F FGH* T#s(^,* T#s(^,* *r   