
    h@                     (   S r SSKrSSKJr  SSKJr  SSKrSSKJ	r	J
r
JrJr  / SQrS\R                  4S jrS	\R                  4S
 jrS\	S\S\\R                  /S4   4S jr\" \S\S9r\" \S\S9rS\R                  S\4S jrS rS rS rS rg)zFA set of functions for passively checking environment implementations.    N)Callable)partial)Spaceerrorloggerspaces)env_render_passive_checkerenv_reset_passive_checkerenv_step_passive_checkercheck_action_spacecheck_observation_spaceobservation_spacec                 d   U R                   R                  U R                  :X  d+   SU R                   R                   SU R                   35       eU R                  R                  U R                  :X  d+   SU R                  R                   SU R                   35       e[        R                  " U R                   U R                  :H  5      (       a  [
        R                  " S5        g[        R                  " U R                  U R                   :  5      (       a  [
        R                  " S5        gg)zChecks that a :class:`Box` observation space is defined in a sensible way.

Args:
    observation_space: A box observation space
zPThe Box observation space shape and low shape have different shapes, low shape: , box shape: zWThe Box observation space shape and high shape have have different shapes, high shape: z=A Box observation space maximum and minimum values are equal.z?A Box observation space low value is greater than a high value.Nlowshapehighnpanyr   warn)r   s    ]/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/utils/passive_env_checker.py_check_box_observation_spacer      s<    	##'8'>'>>^	YZkZoZoZuZuYv  wD  EV  E\  E\  D]  ^^> 	$$(9(?(??f	`arawawa}a}`~  L  M^  Md  Md  Le  ff? 
vv##'8'='==>>ST	!&&):)>)>>	?	?UV 
@    action_spacec                    U R                   R                  U R                  :X  d+   SU R                   R                   SU R                   35       eU R                  R                  U R                  :X  d+   SU R                  R                   SU R                   35       e[        R                  " U R                   U R                  :H  5      (       a  [
        R                  " S5        gg)zrChecks that a :class:`Box` action space is defined in a sensible way.

Args:
    action_space: A box action space
zPThe Box action space shape and low shape have have different shapes, low shape: r   zMThe Box action space shape and high shape have different shapes, high shape: z8A Box action space maximum and minimum values are equal.Nr   )r   s    r   _check_box_action_spacer   (   s     	,"4"44T	YZfZjZjZpZpYqq~  @L  @R  @R  S  TT4 	<#5#55R	VWcWhWhWnWnVoo|  ~J  ~P  ~P  }Q  RR5 
vvl,"3"3344NO 5r   space
space_typecheck_box_space_fnc           	      \   [        U [        R                  5      (       d{  [        U R                  R
                  5      S:X  a?  [        SU S[        U R                  R
                  5      R                  SS5       S35      e[        U S[        U 5       35      e[        U [        R                  5      (       a	  U" U 5        g[        U [        R                  5      (       aO  SU R                  :  d   S	U S
U R                   35       eU R                  S:X  d   S	U SU R                   35       eg[        U [        R                  5      (       a  U R                  U R                  R                  :X  d.   SU SU R                   SU R                  R                   35       e[        R                   " SU R                  :  5      (       d   SU SU R                   35       eg[        U [        R"                  5      (       aT  [        R                   " S[        R$                  " U R                  5      :  5      (       d   SU SU R                   35       eg[        U [        R&                  5      (       aD  S[)        U R                  5      :  d   SU S35       eU R                   H  n[+        X1U5        M     g[        U [        R,                  5      (       aV  S[)        U R                  R/                  5       5      :  d   SU S35       eU R1                  5        H  n[+        X1U5        M     gg)zWA passive check of the environment action space that should not affect the environment.z <class 'gym.spaces.space.Space'>zBGym is incompatible with Gymnasium, please update the environment z_space to `gym	gymnasiumz`.zD space does not inherit from `gymnasium.spaces.Space`, actual type: r   z	Discrete zI space's number of elements must be positive, actual number of elements:  z. space's shape should be empty, actual shape: zMulti-discrete z= space's shape must be equal to the nvec shape, space shape: z, nvec shape: z@ space's all nvec elements must be greater than 0, actual nvec: zMulti-binary zB space's all shape elements must be greater than 0, actual shape: zAn empty Tuple z space is not allowed.zAn empty Dict N)
isinstancer   r   str	__class____base__	TypeErrorreplacetypeBoxDiscretenr   MultiDiscretenvecr   allMultiBinaryasarrayTuplelencheck_spaceDictkeysvalues)r   r   r    subspaces       r   r6   r6   9   sY    eV\\**u''(,NNTU_T``klopupp  qI  qI  mJ  mR  mR  SX  Ze  mf  lg  gi  j  ,bcghmcnbop  
E6::	&	&5!	E6??	+	+K	vzl"klqlslsktu	v KK2	_zl"PQVQ\Q\P]^	_	E6//	0	0KK5::+++	TZL(efkfqfqer  sA  BG  BL  BL  BR  BR  AS  T	T+vv

N
 
 	vZL(hinisishtu	v 
 
E6--	.	.vv

5;;''
 
 	w:,&hinitithuv	w 
 
E6<<	(	(3LL
 
 	@ZL(>?	@ 
 H.@A %	E6;;	'	'3LL
 
 	?J<'=>	? 
 H.@A '	 
(r   observation)r   r    actionmethod_namec           	      p   SU S3n[        U[        R                  5      (       aK  [        U [        R                  [
        45      (       d$  [        R                  " U S[        U 5       35        GO[        U[        R                  5      (       a  UR                  S:w  a  [        U [        R                  5      (       d&  [        R                  " U S[        U 5       35        GOU R                  UR                  :w  a2  [        R                  " U SUR                   SU R                   35        GO2[        U[        R                  [        R                  45      (       aE  [        U [        R                  5      (       d$  [        R                  " U S[        U 5       35        GO[        U[        R                  5      (       a  [        U [         5      (       d$  [        R                  " U S[        U 5       35        [#        U 5      [#        UR                  5      :X  d+   U S	[#        U 5       S
[#        UR                  5       35       e[%        XR                  5       H  u  pE['        XEU5        M     O[        U[        R(                  5      (       a  [        U [*        5      (       d   U S[        U 5       35       eU R-                  5       UR                  R-                  5       :X  dG   U S[/        U R-                  5       5       S[/        UR                  R-                  5       5       35       eUR                  R-                  5        H  n['        X   X   U5        M      X;  a  [        R                  " U S35        gg! [0         a%  n[        R                  " U SU 35         SnAgSnAff = f)a   Check that the observation returned by the environment correspond to the declared one.

Args:
    obs: The observation to check
    observation_space: The observation space of the observation
    method_name: The method name that generated the observation
zThe obs returned by the `z
()` methodz, should be an int or np.int64, actual type: r$   z+ was expecting a numpy array, actual type: z' was expecting numpy array dtype to be z, actual type: z% was expecting a tuple, actual type: zA length is not same as the observation space length, obs length: z, space length: z must be a dict, actual type: zG observation keys is not same as the observation space keys, obs keys: z, space keys: z% is not within the observation space.z5 is not within the observation space with exception: N)r%   r   r-   r   int64intr   r   r+   r,   r   ndarraydtyper2   r/   r4   tupler5   zip	check_obsr7   dictr8   list	Exception)obsr   r=   presub_obs	sub_space	space_keyes           r   rE   rE   s   sW    &k]*
=C#V__55##//KK3%KDQTI;WX	%vzz	2	2""b(c2::..eFtCykR /555eBCTCZCZB[[jknktktjuv 
%(:(:F<P<P'Q	R	R#rzz**KK3%J4PS9+VW	%v||	4	4#u%%KK3%DT#YKPQ3x3$$
 
 	NUSTWX[T\S]]mnq  sD  sK  sK  oL  nM  N	N 
 #&c+C+C"DGg+6 #E	%v{{	3	3#t$$W-KDQTI;&WW$HHJ+227799	bUYZ^_b_g_g_iZjYkkyz~  @Q  @X  @X  @]  @]  @_  {`  za  b	b9*11668Icn&7&BKP 9V'KK3%DEF ( VsePQRPSTUUVs   &N 
N5N00N5c                    [         R                  " U R                  5      nSUR                  ;  a'  SUR                  ;  a  [        R
                  " S5        ODUR                  R                  S5      nUb&  UR                  b  [        R                  " SU 35        SUR                  ;  a&  SUR                  ;  a  [        R
                  " S5        U R                  " S0 UD6n[        U[        5      (       d%  [        R                  " S[        U5       S35        U$ [        U5      S	:w  a  [        R                  " S
5        U$ Uu  pV[        XPR                  S5        [        U[        5      (       d   S[        U5       35       eU$ )z{A passive check of the `Env.reset` function investigating the returning reset information and returning the data unchanged.seedkwargszCurrent gymnasium version requires that `Env.reset` can be passed a `seed` instead of using `Env.seed` for resetting the environment random number generator.zThe default seed argument in `Env.reset` should be `None`, otherwise the environment will by default always be deterministic. Actual default: optionszCurrent gymnasium version requires that `Env.reset` can be passed `options` to allow the environment initialisation to be passed additional information.zThe result returned by `env.reset()` was not a tuple of the form `(obs, info)`, where `obs` is a observation and `info` is a dictionary containing additional information. Actual type: ``   zThe result returned by `env.reset()` should be `(obs, info)` by default, , where `obs` is a observation and `info` is a dictionary containing additional information.resetzPThe second element returned by `env.reset()` was not a dictionary, actual type: r$   )inspect	signaturerU   
parametersr   deprecationgetdefaultr   r%   rC   r+   r5   rE   r   rF   )envrQ   rW   
seed_paramresultrI   infos          r   r
   r
      s   !!#)),IY)))hi>R>R.R l	
 ))--f5
!j&8&8&DKK##-,0
 	,,,AUAU1U g	

 YY  Ffe$$ H  IM  NT  IU  HV  VW  X	
 M 
V	 t	
 M 	#,,g6$
 
 	k]^bcg^h]ij	k 
 Mr   c                 <   U R                  U5      n[        U[        5      (       d   S[        U5       35       e[	        U5      S:X  ac  [
        R                  " S5        Uu  p4pV[        U[        [        R                  45      (       d"  [
        R                  " S[        U5       35        O[	        U5      S:X  a  Uu  p4pxn[        U[        [        R                  45      (       d"  [
        R                  " S[        U5       35        [        U[        [        R                  45      (       d"  [
        R                  " S[        U5       35        O#[        R                  " S[	        U5       S	35      e[        X0R                  S
5        [        R                  " [        U5      [        R                   5      (       dV  [        R                  " [        U5      [        R"                  5      (       d#  [
        R                  " S[        U5       35        Ob[        R$                  " U5      (       a  [
        R                  " S5        [        R&                  " U5      (       a  [
        R                  " S5        [        U[(        5      (       d   S[        U5       35       eU$ )zmA passive check for the environment step, investigating the returning data then returning the data unchanged.z0Expects step result to be a tuple, actual type:    zCore environment is written in old step API which returns one bool instead of two. It is recommended to rewrite the environment with new step API. z4Expects `done` signal to be a boolean, actual type:    z:Expects `terminated` signal to be a boolean, actual type: z9Expects `truncated` signal to be a boolean, actual type: z`Expected `Env.step` to return a four or five element tuple, actual number of elements returned: .stepz^The reward returned by `step()` must be a float, int, np.integer or np.floating, actual type: zThe reward is a NaN value.zThe reward is an inf value.zJThe `info` returned by `step()` must be a python dictionary, actual type: )rd   r%   rC   r+   r5   r   rY   boolr   bool_r   r   ErrorrE   r   
issubdtypeintegerfloatingisnanisinfrF   )	r\   r<   r^   rI   rewarddoner_   
terminated	truncateds	            r   r   r      s(    XXfF  I	9$v,HI  6{aO	
 #)T$rxx 011KKFtDzlS 
V	390ZD *tRXX&677KKLTR\M]L^_ )dBHH%566KKKDQZOK\] kknorsyozn{{|}
 	
 c((&1 	d6lBJJ//==fr{{33lmqrxmylz{	
 88FKK4588FKK56d  a	STXY]T^S_`a  Mr   c                    U S:X  a'  Ub#  [         R                  " S[        U5       35        ggU S:X  Ga  [        U[        R
                  5      (       d#  [         R                  " S[        U5       35        gUR                  [        R                  :w  a#  [         R                  " SUR                   35        UR                  S:w  a#  [         R                  " SUR                   35        UR                  S:X  a;  UR                  S	   S:w  a'  [         R                  " S
UR                  S	    35        gggU S:X  aw  [        U[        R
                  5      (       d#  [         R                  " S[        U5       35        gUR                  S	:w  a$  [         R                  " SUR                   35        ggU S;   a9  [        U[        5      (       d#  [         R                  " S[        U5       35        ggU R                  S5      (       a_  [        U[        5      (       d&  [         R                  " SU  S[        U5       35        gU S[        S5      *  nU H  n[        X#5        M     gg)z@Produces warning if `render_return` doesn't match `render_mode`.humanNz*Human rendering should return `None`, got 	rgb_arrayz5RGB-array rendering should return a numpy array, got zFRGB-array rendering should return a numpy array with dtype uint8, got    zERGB-array rendering should return a numpy array with three axes, got rT   zaRGB-array rendering should return a numpy array in which the last axis has three dimensions, got depth_arrayz7Depth-array rendering should return a numpy array, got zEDepth-array rendering should return a numpy array with two axes, got )ansiasciiz2ANSI/ASCII rendering should produce a string, got _listzRender mode `z` should produce a list, got )r   r   r+   r%   r   rA   rB   uint8ndimr   r&   endswithrG   r5   _check_render_return)render_moderender_returnbase_render_modeitems       r   r|   r|     sG   g$KK<T-=P<QR % 
	#-44KKG]H[G\] ""bhh.\]j]p]p\qr !!Q&[\i\n\n[op !!Q&=+>+>q+AQ+Fw  yF  yL  yL  MN  yO  xP  Q ,G& 
	%-44KKI$}J]I^_ 1$KKWXeXjXjWkl % 
)	)---KKDT-EXDYZ . 
		g	&	&-..KK},I$}J]I^_  +?c'l];%$$ & 
'r   c           	      v   U R                   R                  S5      nUc  [        R                  " S5        GO[	        U[
        [        45      (       d#  [        R                  " S[        U5       35        OJ[        S U 5       5      (       d3  [        R                  " SU Vs/ s H  n[        U5      PM     sn 35        U R                   R                  S5      n[        U5      S:  a  Uc  [        R                  " S5        O[        R                  " [        U5      [        R                  5      (       dV  [        R                  " [        U5      [        R                  5      (       d#  [        R                  " S	[        U5       35        OUS:  d
   S
U 35       e[        U5      S:X  a"  U R                  b   SU R                   35       eO4U R                  b'  U R                  U;   d   SU R                   SU 35       eU R                  5       nU R                  b  [!        U R                  U5        U$ s  snf )zvA passive check of the `Env.render` that the declared render modes/fps in the metadata of the environment is declared.render_modeszNo render modes was declared in the environment (env.metadata['render_modes'] is None or not defined), you may have trouble when calling `.render()`.zKExpects the render_modes to be a sequence (i.e. list, tuple), actual type: c              3   B   #    U  H  n[        U[        5      v   M     g 7f)N)r%   r&   ).0modes     r   	<genexpr>-env_render_passive_checker.<locals>.<genexpr>E  s     D|tZc**|s   z6Expects all render modes to be strings, actual types: 
render_fpsr   zNo render fps was declared in the environment (env.metadata['render_fps'] is None or not defined), rendering may occur at inconsistent fps.zSExpects the `env.metadata['render_fps']` to be an integer or a float, actual type: zPExpects the `env.metadata['render_fps']` to be greater than zero, actual value: zLWith no render_modes, expects the Env.render_mode to be None, actual value: zcThe environment was initialized successfully however with an unsupported render mode. Render mode: z	, modes: )metadatarZ   r   r   r%   rG   rC   r+   r1   r5   r   rh   ri   rj   r}   renderr|   )r\   r   r   r   r^   s        r   r	   r	   9  s   <<##N3L d	
 ,u66KK]^bco^p]qr D|DDDKKHamInamY]$t*amInHop \\%%l3
|q ! b
 MM$z"2BJJ??}}T*%5r{{CCKKmnrs}n~m  A
 #Qwijtiuvw& |!'p]^a^m^m]nop' ??*coo.M   #0	,IM
 ZZ\F
"S__f5MM Jos   !H6
)__doc__rV   collections.abcr   	functoolsr   numpyr   r#   r   r   r   r   __all__r,   r   r   r&   r6   r   r   rE   r
   r   r|   r	   r$   r   r   <module>r      s    L  $   2 2WFJJ W&P&** P"-B-B!-B7?d@R7S-B` "3 
 H9P 
-Vfll -V -V`&R6r1h4r   