
    h                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
rSSKrSSKrSSKJr  SSKJrJrJr  SSKJrJr  SSKJr  SSKJr  SS	KJrJr  SSKrSS
KJrJrJ r J!r!  SSK"J#r#  SSK$J%r%  \RL                  " S5      r'/ SQr( " S S\5      r) " S S\5      r*\ " S S5      5       r+\ " S S5      5       r, " S S\5      r-0 r.S\/S'   Sq0S\/S'   S1S jr1S2S jr2S3S jr3S4S  jr4S5S! jr5S6S" jr6S7S# jr7S8S$ jr8S9S% jr9S:S& jr:S;S' jr;\Rx                  S<S( j5       r=         S=                   S>S* jjr>  S?         S@S+ jjr?    SA           SBS, jjr@S9S- jrA\.4S.SS)S/.         SCS0 jjjrBg)DzsFunctions for registering environments within gymnasium using public functions ``make``, ``register`` and ``spec``.    )annotationsN)defaultdict)CallableIterableSequence)	dataclassfield)Enum)
ModuleType)AnyProtocol)EnvWrappererrorlogger)warn)AutoresetModezM^(?:(?P<namespace>[\w:-]+)\/)?(?:(?P<name>[\w:.-]+?))(?:-v(?P<version>\d+))?$)registrycurrent_namespaceEnvSpecWrapperSpecVectorizeModeregistermakemake_vecspecpprint_registryregister_envsc                  "    \ rS rSrSrSS jrSrg)
EnvCreator0   *Function type expected for an environment.c                    g N selfkwargss     U/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/envs/registration.py__call__EnvCreator.__call__3   s    c    r%   Nr(   r   returnr   __name__
__module____qualname____firstlineno____doc__r*   __static_attributes__r%   r,   r)   r    r    0   s    41r,   r    c                  "    \ rS rSrSrSS jrSrg)VectorEnvCreator6   r"   c                    g r$   r%   r&   s     r)   r*   VectorEnvCreator.__call__9   s    sr,   r%   N)r(   r   r.   gym.vector.VectorEnvr/   r%   r,   r)   r7   r7   6   s    4Br,   r7   c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg	)
r   <   a  A specification for recording wrapper configs.

* name: The name of the wrapper.
* entry_point: The location of the wrapper to create from.
* kwargs: Additional keyword arguments passed to the wrapper. If the wrapper doesn't inherit from EzPickle then this is ``None``
strnameentry_pointdict[str, Any] | Noner(   r%   N)r0   r1   r2   r3   r4   __annotations__r5   r%   r,   r)   r   r   <   s     I!!r,   r   c                     \ rS rSr% SrS\S'   \" SS9rS\S'   \" SS9rS	\S
'   \" SS9r	S\S'   \" SS9r
S\S'   \" SS9rS\S'   \" SS9rS\S'   \" \S9rS\S'   \" SS9rS\S'   \" SS9rS\S'   \" SS9rS\S'   \" \S9rS\S'   \" SS9rS\S'   S rS&S  jrS'S! jr\S(S" j5       r\S)S# j5       r   S*       S+S$ jjrS%rg),r   J   a  A specification for creating environments with :meth:`gymnasium.make`.

* **id**: The string used to create the environment with :meth:`gymnasium.make`
* **entry_point**: A string for the environment location, ``(import path):(environment name)`` or a function that creates the environment.
* **reward_threshold**: The reward threshold for completing the environment.
* **nondeterministic**: If the observation of an environment cannot be repeated with the same initial state, random number generator state and actions.
* **max_episode_steps**: The max number of steps that the environment can take before truncation
* **order_enforce**: If to enforce the order of :meth:`gymnasium.Env.reset` before :meth:`gymnasium.Env.step` and :meth:`gymnasium.Env.render` functions
* **disable_env_checker**: If to disable the environment checker wrapper in :meth:`gymnasium.make`, by default False (runs the environment checker)
* **kwargs**: Additional keyword arguments passed to the environment during initialisation
* **additional_wrappers**: A tuple of additional wrappers applied to the environment (WrapperSpec)
* **vector_entry_point**: The location of the vectorized environment to create from

Changelogs:
    v1.0.0 - Autoreset attribute removed
r>   idNdefaultEnvCreator | str | Noner@   float | Nonereward_thresholdFboolnondeterministic
int | Nonemax_episode_stepsTorder_enforcedisable_env_checker)default_factorydictr(   )init
str | None	namespacer?   versiontuple[WrapperSpec, ...]additional_wrappersVectorEnvCreator | str | Nonevector_entry_pointc                T    [        U R                  5      u  U l        U l        U l        g)zcCalls after the spec is created to extract the namespace, name and version from the environment id.N)parse_env_idrE   rU   r?   rV   )r'   s    r)   __post_init__EnvSpec.__post_init__w   s    2>tww2G/	4<r,   c                    [        U 40 UD6$ )zDCalls ``make`` using the environment spec and any keyword arguments.)r   r&   s     r)   r   EnvSpec.make{   s    D#F##r,   c                    [         R                  " U 5      nUR                  S5        UR                  S5        UR                  S5        U R                  U5        [        R
                  " U5      $ )zxConverts the environment spec into a json compatible string.

Returns:
    A jsonifyied string for the environment spec
rU   r?   rV   )dataclassesasdictpop_check_can_jsonifyjsondumps)r'   env_spec_dicts     r)   to_jsonEnvSpec.to_json   s]     $**40+&&!)$ 	.zz-((r,   c           
         SU ;   a  U S   OU S   nU R                  5        H*  u  p#[        U5      (       d  M  [        SU SU SU S35      e   g)zWarns the user about serialisation failing if the spec contains a callable.

Args:
    env_spec: An environment or wrapper specification.

Returns: The specification with lambda functions converted to strings.

r?   rE   zCallable found in z for z attribute with value=z>. Currently, Gymnasium does not support serialising callables.N)itemscallable
ValueError)env_spec	spec_namekeyvalues       r)   re   EnvSpec._check_can_jsonify   sg     )/((:HV$	"..*JC (5=STYSZ  [Y  Z  +r,   c                \   [         R                  " U 5      n/ nUR                  S5       H  n UR                  [	        S0 UD65        M       [        S0 UD6n[        U5      Ul	        U$ ! [
         a  n[        SU S35      UeSnAff = f! [
         a  n[        SU S35      UeSnAff = f)zConverts a JSON string into a specification stack.

Args:
    json_env_spec: A JSON string representing the env specification.

Returns:
    An environment spec
rX   z&An issue occurred when trying to make z a WrapperSpecNz an EnvSpecr%   )
rf   loadsrd   appendr   	Exceptionrn   r   tuplerX   )json_env_specparsed_env_specapplied_wrapper_specswrapper_spec_jsonero   s         r)   	from_jsonEnvSpec.from_json   s     **]335!0!4!45J!K%,,[-M;L-MN "L	11H+01F+GH(    <=N<O~^  	88IU	s/   A*B *
B	4BB	
B+B&&B+c           	        SU R                    3nU(       d  U(       a  USU R                   3-  nU(       d  U R                  b  USU R                   3-  nU(       d  U R                  SLa  USU R                   3-  nU(       d  U R                  b  USU R                   3-  nU(       d  U R
                  SLa  US	U R
                   3-  nU(       d  U R                  SLa  US
U R                   3-  nU(       d  U R                  (       a  / nU R                   Ho  nU(       a:  UR                  SUR                   SUR                   SUR                   35        MD  UR                  SUR                   SUR                   35        Mq     [        U5      S:X  a  US-  nOUSSR                  U5       S3-  nU(       a  U$ [        U5        g)aJ  Pretty prints the environment spec.

Args:
    disable_print: If to disable print and return the output
    include_entry_points: If to include the entry_points in the output
    print_all: If to print all information, including variables with default values

Returns:
    If ``disable_print is True`` a string otherwise ``None``
zid=z
entry_point=Nz
reward_threshold=Fz
nondeterministic=z
max_episode_steps=Tz
order_enforce=z
disable_env_checker=z
	name=z, entry_point=z	, kwargs=r   z
additional_wrappers=[]z
additional_wrappers=[,z
])rE   r@   rJ   rL   rN   rO   rP   rX   rv   r?   r(   lenjoinprint)r'   disable_printinclude_entry_points	print_alloutputwrapper_outputwrapper_specs          r)   pprintEnvSpec.pprint   s     twwi,t'7'7&899F--9+D,A,A+BCCF--U:+D,A,A+BCCF..:,T-C-C,DEEF**$6(););(<==F00=.t/G/G.HIIF00(*N $ 8 8'"))#L$5$5#6n\E]E]D^^ghth{h{g|} #))#L$5$5#6i@S@S?TU !9 >"a'443CHH^4L3MSQQM&Mr,   )r?   rU   rV   r-   )r.   r>   )ro   dict[str, Any])ry   r>   r.   r   )FFF)r   rK   r   rK   r   rK   r.   rT   )r0   r1   r2   r3   r4   rB   r	   r@   rJ   rL   rN   rO   rP   rR   r(   rU   r?   rV   rx   rX   rZ   r]   r   ri   staticmethodre   r~   r   r5   r%   r,   r)   r   r   J   sK   " 	G+0+>K(> &+4%8l8"51d1 %*$$7z7-M4- %e 44 .FD. "u-Iz-5!D#!U+GZ+ 493O0O 9>d8K5KH$)"  "  @ $%*	44 #4 	4
 
4 4r,   r   c                  $    \ rS rSrSrSrSrSrSrg)r      z4All possible vectorization modes used in `make_vec`.asyncsyncrZ   r%   N)	r0   r1   r2   r3   r4   ASYNCSYNCVECTOR_ENTRY_POINTr5   r%   r,   r)   r   r      s    >ED-r,   r   dict[str, EnvSpec]r   rT   r   c                    [         R                  U 5      nU(       d  [        R                  " SU  S35      eUR	                  SSS5      u  p#nUb  [        U5      nX#U4$ )aG  Parse environment ID string format - ``[namespace/](env-name)[-v(version)]`` where the namespace and version are optional.

Args:
    env_id: The environment id to parse

Returns:
    A tuple of environment namespace, environment name and version number

Raises:
    Error: If the environment id is not valid environment regex
zMalformed environment ID: zd. (Currently all IDs must be of the form [namespace/](env-name)-v(version). (namespace is optional))rU   r?   rV   )	ENV_ID_RE	fullmatchr   Errorgroupint)env_idmatchnsr?   rV   s        r)   r\   r\     sn     'Ekk(  1U  V
 	
 KCBgg,Wr,   c                2    UnU b  U  SU 3nUb  U SU 3nU$ )zGet the full env ID given a name and (optional) version and namespace. Inverse of :meth:`parse_env_id`.

Args:
    ns: The environment namespace
    name: The environment name
    version: The environment version

Returns:
    The environment id
/z-vr%   )r   r?   rV   	full_names       r)   
get_env_idr     s9     I	~d!D6N	 kG9-	r,   c                    [         R                  5        Vs/ s HB  nUR                  U :X  d  M  UR                  U:X  d  M'  UR                  c  M6  UR                  PMD     nn[        USS9$ s  snf )a)  Finds the highest registered version of the environment given the namespace and name in the registry.

Args:
    ns: The environment namespace
    name: The environment name (id)

Returns:
    The highest version of an environment with matching namespace and name, otherwise ``None`` is returned.
NrF   )r   valuesrU   r?   rV   max)r   r?   ro   rV   s       r)   find_highest_versionr   1  sx     !))H# 	 MMT! 	 	 	)   w%%s   A,A,A,A,c                L   U c  g[         R                  5        Vs1 s H  nUR                  c  M  UR                  iM      nnX;   a  g[        U5      S:  a  [        R
                  " XSS9OSnU(       a
  SUS    S3nOSU  S3n[        R                  " S	U  S
U 35      es  snf )zJCheck if a namespace exists. If it doesn't, print a helpful error message.Nr      nzDid you mean: ``?z*Have you installed the proper package for ?z
Namespace z not found. )r   r   rU   r   difflibget_close_matchesr   NamespaceNotFound)r   ro   
namespaces
suggestionsuggestion_msgs        r)   _check_namespace_existsr   E  s     
z
 !))H 	)  
 
 ;>j/A:M!!"A6SW  *:a=/<EbTK

!
!Jrd,~>N"O
PP#s
   B!B!c                T   [        U 5        [        R                  5        Vs1 s H   o"R                  U :X  d  M  UR                  iM"     nnX;   a  g[
        R                  " XSS9nU (       a  SU  3OSnU(       a	  SUS    S3OSn[        R                  " S	U S
U SU 35      es  snf )zTCheck if an env exists in a namespace. If it doesn't, print a helpful error message.Nr   r   z in namespace  z Did you mean: `r   r   zEnvironment `z` doesn't exist.)	r   r   r   rU   r?   r   r   r   NameNotFound)r   r?   ro   namesr   namespace_msgr   s          r)   _check_name_existsr   `  s     B '/oo&7&7(;M;MQS;S&7 
  } **4!<J-/nRD)RM=G'
1b9RN



v_]O1^<LM s
   B%B%c           
     r   [        XU5      [        ;   a  g[        X5        Uc  gSU S[        XS5       S3n[        R                  5        Vs/ s H)  nUR                  U :X  d  M  UR
                  U:X  d  M'  UPM+     nn[        US S9nU Vs/ s H  oDR                  b  M  UPM     nnU(       a;  USUS   R                   S	3-  n[        U5      S
:X  a  [        R                  " U5      eU Vs/ s H  oDR                  c  M  UPM     nn[        US SS9nUbF  X(R                  :  a7  SR                  S U 5       5      n	USU	 S3-  n[        R                  " U5      eUbD  X(R                  :  a4  [        R                  " SU S[        XS5       SUR                   S35      eggs  snf s  snf s  snf )a  Check if an env version exists in a namespace. If it doesn't, print a helpful error message.

This is a complete test whether an environment identifier is valid, and will provide the best available hints.

Args:
    ns: The environment namespace
    name: The environment space
    version: The environment version

Raises:
    DeprecatedEnv: The environment doesn't exist but a default version does
    VersionNotFound: The ``version`` used doesn't exist
    DeprecatedEnv: Environment version is deprecated
NzEnvironment version `vz` for environment `z` doesn't exist.c                >    [        U R                  =(       d    S5      $ )Nr   rV   ro   s    r)   <lambda>'_check_version_exists.<locals>.<lambda>  s    s8;K;K;Qr7Rr,   )rq   z" It provides the default version `r   `.r   c                    U R                   $ r$   rV   r   s    r)   r   r     s
    H<L<Lr,   rq   rG   z, c              3  B   #    U  H  nS UR                    S3v   M     g7f)z`v`Nr   ).0ro   s     r)   	<genexpr>(_check_version_exists.<locals>.<genexpr>  s      $Xi(r(*:*:);1%=is   z' It provides versioned environments: [ z ].zEnvironment version vz for `z` is deprecated. Please use `z
` instead.)r   r   r   r   rU   r?   sortedrV   rE   r   r   DeprecatedEnvr   r   VersionNotFound)
r   r?   rV   messagero   	env_specsdefault_specversioned_specslatest_specversion_list_msgs
             r)   _check_version_existsr   v  s    "G$0r &wi/B:bX\C]B^^noG !))H# 	(0(= 	)  
 y&RSI-6SY:J:JHYLS7Q8J8J7K2NNy>Q%%g..
 "+!*X.>.>   o+LVZ[K7-@-@#@99$Xi$XX<=M<NcRR##G,,7-@-@#@!!#G9F:b3M2N O&>>**6
 	
 $A7 Ts*   F*&F*8F*F/#F/1F4F4c                  ^  [        U 4S j[        R                  5        5       S SS9n[        U 4S j[        R                  5        5       S5      nUb>  T R                  b1  [
        R                  " ST R                   SUR                   S35      eUb?  T R                  c1  [
        R                  " S	T R                   S
UR                   S35      egg)zRChecks whether the spec is valid to be registered. Helper function for `register`.c              3     >#    U  HN  nUR                   TR                   :X  d  M  UR                  TR                  :X  d  M;  UR                  c  MJ  Uv   MP     g 7fr$   rU   r?   rV   r   ro   testing_specs     r)   r   '_check_spec_register.<locals>.<genexpr>  W      	
-!!\%;%;;  !2!22    	 H-   AAA	Ac                ,    [        U R                  5      $ r$   r   )spec_s    r)   r   &_check_spec_register.<locals>.<lambda>  s    #emm,r,   Nr   c              3     >#    U  HN  nUR                   TR                   :X  d  M  UR                  TR                  :X  d  M;  UR                  b  MJ  Uv   MP     g 7fr$   r   r   s     r)   r   r     r   r   z*Can't register the versioned environment `z$` when the unversioned environment `z"` of the same name already exists.z,Can't register the unversioned environment `z"` when the versioned environment `z` of the same name already exists. Note: the default behavior is that `gym.make` with the unversioned environment will return the latest versioned environment)r   r   r   nextrV   r   RegistrationErrorrE   )r   latest_versioned_specunversioned_specs   `  r)   _check_spec_registerr     s    	
$OO-	
 -
 	
$OO-	
 		 #(<(<(H%%  ! ##$$FH
 	

 
	*|/C/C/K%%:<??:K L%(() *ll
 	
 0L	*r,   c                t   [        U [        5      (       d&  [        R                  " S[	        [
        5       35      eU R                  S5      nUc1  [        R                  " S[        U R                  5       5       35        g[        U[        5      (       d#  [        R                  " S[	        U5       35        gg)z%Check the metadata of an environment.z9Expect the environment metadata to be dict, actual type: render_modesNzKThe environment creator metadata doesn't include `render_modes`, contains: zMExpects the environment metadata render_modes to be a Iterable, actual type: )
isinstancerR   r   InvalidMetadatatypemetadatagetr   r   listkeysr   )testing_metadatar   s     r)   _check_metadatar     s    &--##GXGWX
 	
 $''7LYZ^_o_t_t_vZwYxy	
 h//[\`am\n[op	
 0r,   c                t   [        U [        5      (       d   eSU ;  a  S U 4OU R                  S5      u  pUb   [        R                  " U5        [        R                  U5      n[        U5      u  pVn[        XV5      nUb%  Ub"  X:  a  [        R                  " SU SU S35        UcC  Ub@  Un[        XVU5      n	[        R                  U	5      n[        R                  " SU	 SU S35        Uc&  [        XVU5        [        R                   " S	U S
35      eU$ ! [
         a  n[        U SU S35      UeS nAff = f)N:zI. Environment registration via importing a module failed. Check whether 'z0' contains env registration and can be imported.zThe environment z< is out of date. You should consider upgrading to version `vr   z(Using the latest versioned environment `z*` instead of the unversioned environment `No registered env with id: z. Did you register it, or import the package that registers it? Use `gymnasium.pprint_registry()` to see all of the registered environments.)r   r>   split	importlibimport_moduleModuleNotFoundErrorr   r   r\   r   r   deprecationr   r   r   r   r   )
r   moduleenv_namer}   ro   r   r?   rV   latest_version
new_env_ids
             r)   
_find_specr     s{   fc"""" *-F):f~S@QF	##F+ ||H%H %X.Bg)"3N~9n>Vxj )&&4%5R9	
 >5 '2
<<
+6zl C77?jD	

 b0kk)(  4@  A
 	
 OC # 	%# ""()Y[ 	s   D 
D7 D22D7c                n    U R                  S5      u  p[        R                  " U5      n[        X25      nU$ )a  Loads an environment with name of style ``"(import path):(environment name)"`` and returns the environment creation function, normally the environment class type.

Args:
    name: The environment name

Returns:
    The environment constructor for the given environment name.
r   )r   r   r   getattr)r?   mod_name	attr_namemodfns        r)   load_env_creatorr    s3     **S/H

!
!(
+C		 BIr,   c                    g)zGA No-op function such that it can appear to IDEs that a module is used.Nr%   )
env_modules    r)   r   r   %  s    r,   c              #  (   #    [         nU q Sv   Uq g7f)z4Context manager for modifying the current namespace.N)r   )r   old_namespaces     r)   rU   rU   *  s      &M	%s   Fc
                   Uc
  Uc   S5       e[        U 5      u  pnU	c
  [        5       n	[        bb  U	R                  S5      bI  U	R                  S5      [        :w  a0  [        R
                  " SU	R                  S5       S[         S35        [        nOU
n[        XU5      n[        UUUUUUUU	UUS9
n[        U5        UR                  [        ;   a$  [        R
                  " SUR                   S	35        U[        UR                  '   g)
a\  Registers an environment in gymnasium with an ``id`` to use with :meth:`gymnasium.make` with the ``entry_point`` being a string or callable for creating the environment.

The ``id`` parameter corresponds to the name of the environment, with the syntax as follows:
``[namespace/](env_name)[-v(version)]`` where ``namespace`` and ``-v(version)`` is optional.

It takes arbitrary keyword arguments, which are passed to the :class:`EnvSpec` ``kwargs`` parameter.

Args:
    id: The environment id
    entry_point: The entry point for creating the environment
    reward_threshold: The reward threshold considered for an agent to have learnt the environment
    nondeterministic: If the environment is nondeterministic (even with knowledge of the initial seed and all actions, the same state cannot be reached)
    max_episode_steps: The maximum number of episodes steps before truncation. Used by the :class:`gymnasium.wrappers.TimeLimit` wrapper if not ``None``.
    order_enforce: If to enable the order enforcer wrapper to ensure users run functions in the correct order.
        If ``True``, then the :class:`gymnasium.wrappers.OrderEnforcing` is applied to the environment.
    disable_env_checker: If to disable the :class:`gymnasium.wrappers.PassiveEnvChecker` to the environment.
    additional_wrappers: Additional wrappers to apply the environment.
    vector_entry_point: The entry point for creating the vector environment
    kwargs: arbitrary keyword arguments which are passed to the environment constructor on initialisation.

Changelogs:
    v1.0.0 - `autoreset` and `apply_api_compatibility` parameter was removed
NzGEither `entry_point` or `vector_entry_point` (or both) must be providedrU   zCustom namespace `z$` is being overridden by namespace `z`. If you are developing a plugin you shouldn't specify a namespace in `register` calls. The namespace is specified through the entry point package metadata.
rE   r@   rJ   rL   rN   rO   rP   r(   rX   rZ   zOverriding environment z already in registry.)r\   rR   r   r   r   r   r   r   r   rE   r   )rE   r@   rJ   rL   rN   rO   rP   rX   rZ   r(   r   r?   rV   ns_idfull_env_idnew_specs                   r)   r   r   4  s   H 	#5#AQPQA$R(Bg~$JJ{#/

;'+<<KK$VZZ%<$==absat uW W
 "U'2K))+#//-H "{{h-hkk]:OPQ$HX[[r,   c                L   [        U [        5      (       a4  U n[        US5      (       d   [        R                  " SU 35        SUl        O"[        U [        5      (       d   e[        U 5      n[        U[        5      (       d   e[        R                  " UR                  5      nUR                  U5        UR                  c#  [        R                  " UR                   S35      e[!        UR                  5      (       a  UR                  nO[#        UR                  5      nSn[        US5      (       a0  [%        UR&                  5        UR&                  R)                  S5      nUR)                  S5      nS	n	S	n
Ub  Ub  X;  a  S
S1R+                  U5      nUS:X  a;  [-        U5      S:  a,  [        R                  " S5        UR/                  5       US'   Sn	O\UR1                  S5      (       a(  US[-        S5      *  U;   a  US[-        S5      *  US'   Sn
O[        R                  " SU< SU S35         U" S0 UD6n[        U[8        R:                  5      (       di  [        UR<                  R>                  5      S:X  d#  [        UR<                  R>                  5      S:X  a  [3        S5      e[3        S[7        U5       S35      e[        UR                  UR                  UR@                  URB                  SS	SUSURD                  S9
URF                  l$        URH                  c   e[-        URH                  R
                  5      nUR
                  SU URH                  R
                  :w  aC  [K        UR
                  URH                  R
                  5       H  u  nn[M        S U S!U 35      e   US	L d  Uc.  URN                  S	L a  [8        RP                  RS                  U5      nURT                  (       a  [8        RP                  RW                  U5      nUS":w  aY  Ub   [8        RP                  RY                  X5      nO6URZ                  b)  [8        RP                  RY                  XRZ                  5      nUR
                  US  HO  nUR                  c  [M        UR\                   S#35      e[#        UR                  5      " SS$U0UR                  D6nMQ     U	(       a!  [8        RP                  R_                  U5      nU$ U
(       a  [8        RP                  Ra                  U5      nU$ ! [2         as  n[        U5      R5                  S5      S:  a,  U	(       a%  [        R                  " SUR                   S35      Ue[7        U5      " U SUR                   SU S35      eSnAff = f)%a  Creates an environment previously registered with :meth:`gymnasium.register` or a :class:`EnvSpec`.

To find all available environments use ``gymnasium.envs.registry.keys()`` for all valid ids.

Args:
    id: A string for the environment id or a :class:`EnvSpec`. Optionally if using a string, a module to import can be included, e.g. ``'module:Env-v0'``.
        This is equivalent to importing the module first to register the environment followed by making the environment.
    max_episode_steps: Maximum length of an episode, can override the registered :class:`EnvSpec` ``max_episode_steps``
        with the value being passed to :class:`gymnasium.wrappers.TimeLimit`.
        Using ``max_episode_steps=-1`` will not apply the wrapper to the environment.
    disable_env_checker: If to add :class:`gymnasium.wrappers.PassiveEnvChecker`, ``None`` will default to the
        :class:`EnvSpec` ``disable_env_checker`` value otherwise use this value will be used.
    kwargs: Additional arguments to pass to the environment constructor.

Returns:
    An instance of the environment with wrappers applied.

Raises:
    Error: If the ``id`` doesn't exist in the :attr:`registry`

Changelogs:
    v1.0.0 - `autoreset` and `apply_api_compatibility` was removed
rX   zhThe env spec passed to `make` does not have a `additional_wrappers`, set it to an empty tuple. Env_spec=r%   Nz, registered but entry_point is not specifiedr   r   render_modeF	rgb_arrayrgb_array_listhumanr   zYou are trying to use 'human' rendering for an environment that doesn't natively support it. The HumanRendering wrapper is being applied to your environment.T_listz6The environment is being initialised with render_mode=z+ that is not in the possible render_modes ().z0got an unexpected keyword argument 'render_mode'z(You passed render_mode='human' although z doesn't implement human-rendering natively. Gym tried to apply the HumanRendering wrapper but it looks like your environment is using the old rendering API, which is not supported by the HumanRendering wrapper.z- was raised from the environment creator for z with kwargs ()z<class 'gym.core.Env'>z<class 'gym.core.Wrapper'>zGym is incompatible with Gymnasium, please update the environment class to `gymnasium.Env`. See https://gymnasium.farama.org/introduction/create_custom_env/ for more info.zIThe environment must inherit from the gymnasium.Env class, actual class: zQ. See https://gymnasium.farama.org/introduction/create_custom_env/ for more info.r  zThe environment's wrapper spec z: is different from the saved `EnvSpec` additional wrapper r   zs wrapper does not inherit from `gymnasium.utils.RecordConstructorArgs`, therefore, the wrapper cannot be recreated.env)1r   r   hasattrr   r   rX   r>   r   copydeepcopyr(   updater@   r   r   rE   rm   r  r   r   r   intersectionr   rd   endswith	TypeErrorfindr   gymr   	__class____base__rJ   rL   rZ   	unwrappedr   ziprn   rP   wrappersPassiveEnvCheckerrO   OrderEnforcing	TimeLimitrN   r?   HumanRenderingRenderCollection)rE   rN   rP   r(   ro   env_spec_kwargsenv_creatorr   r  apply_human_renderingapply_render_collectiondisplayable_modesr  r}   num_prior_wrappersenv_spec_wrapper_specrecreated_wrapper_specr   s                     r)   r   r     s   : "gx!677KKz  |D  {E  F ,.H( "c"""" b>h(((( mmHOO4O6" #kkX[[M)UVWW	(&&	'	'** 'x';';< &*L{J'',,-"++//?!%%m4K!# 	$+(*:;HHV'!c*;&<q&@KKS .?-B-B-DOM*$(!  ))Os7|m,<-8CL=-IOM*&*#KKH X==IN"N
,O,  c377##&&'+CC3==))*.JJb 
 [\`ad\e[f gb b  !;;((!22!22 #66CMM 88SXX99:$$%8&8988''	( >A((#((*F*F>
9!#9 12H1I  JD  EZ  D[  \ >
 e##(D(D(Mll,,S1 ll))#. B(,,((@C''3,,((.H.HIC 445G5HI&$$%  &Y  Z  |778XSXLDWDWX J ll))#. J 
!ll++C0Js  FKKJKqP%++:8;;- HW W 	 q'#B8;;-~^m]nnop s   4T& &
V#0A.VV#c           
     	  ^^^^ Uc  0 nTc  / m[        U [        5      (       a  U mOD[        U [        5      (       a  [        U 5      mO#[        R
                  " S[        U 5       S35      e[        R                  " T5      mTR                  m[        5       Tl	        TR                  SU5      nTR                  SU5      nTR                  SU5      nTR                  ST5      mTR                  U5        Uc/  TR                  b  [        R                  nO[        R                   nO [        U5      n[        U[        5      (       d   eSUUU4S	 jjmU[        R                   :X  ah  TR&                  c$  [        R
                  " S
TR(                   S35      e[*        R,                  R.                  " SSU4S j[1        U5       5       0UD6nGOU[        R2                  :X  ao  TR&                  c$  [        R
                  " S
TR(                   S35      e[*        R,                  R4                  " SS[1        U5       Vs/ s H  nTPM     sn0UD6nGO1U[        R                  :X  Ga  [7        U5      S:  a  [        R
                  " SU S35      e[7        T5      S:  a  [        R
                  " ST S35      e[7        TR8                  5      S:  a$  [        R
                  " STR8                   S35      eTR                  n	U	c  [        R
                  " S
U  S35      e[;        U	5      (       a  U	n
O[=        U	5      n
TR>                  b  ST;  a  TR>                  TS'   U
" SSU0TD6nO[        R
                  " SU 35      e[        R                  " T5      nTR                  5       Ul	        US:w  a  XR                  S'   UR$                  UR                  S'   [7        U5      S:  a  X;R                  S'   [7        T5      S:  a  TUR                  S'   XR@                  l!        SURD                  ;  a  [G        SU SURD                   35        U$ [        URD                  S   [H        5      (       d(  [G        SU S[        URD                  S   5       S35        U$ ! ["         a7    [#        SU< S[         Vs/ s H  ofR$                  PM     Os  snf sn 35      ef = fs  snf )a^  Create a vector environment according to the given ID.

To find all available environments use :func:`gymnasium.pprint_registry` or ``gymnasium.registry.keys()`` for all valid ids.
We refer to the Vector environment as the vectorizor while the environment being vectorized is the base or vectorized environment (``vectorizor(vectorized env)``).

Args:
    id: Name of the environment. Optionally, a module to import can be included, e.g. 'module:Env-v0'
    num_envs: Number of environments to create
    vectorization_mode: The vectorization method used, defaults to ``None`` such that if env id' spec has a ``vector_entry_point`` (not ``None``),
        this is first used otherwise defaults to ``sync`` to use the :class:`gymnasium.vector.SyncVectorEnv`.
        Valid modes are ``"async"``, ``"sync"`` or ``"vector_entry_point"``. Recommended to use the :class:`VectorizeMode` enum rather than strings.
    vector_kwargs: Additional arguments to pass to the vectorizor environment constructor, i.e., ``SyncVectorEnv(..., **vector_kwargs)``.
    wrappers: A sequence of wrapper functions to apply to the base environment. Can only be used in ``"sync"`` or ``"async"`` mode.
    **kwargs: Additional arguments passed to the base environment constructor.

Returns:
    An instance of the environment.

Raises:
    Error: If the ``id`` doesn't exist then an error is raised
zInvalid id type: z. Expected `str` or `EnvSpec`num_envsvectorization_modevector_kwargsr%  zInvalid vectorization mode: z, valid modes: c                 h   > [        T40 TR                  5       D6n Tc  U $ T H  nU" U 5      n M     U $ r$   )r   r  )
single_envwrapperro   r+  r%  s     r)   create_single_env#make_vec.<locals>.create_single_env  sA    (=o&:&:&<=
G ,J  r,   z)Cannot create vectorized environment for z0 because it doesn't have an entry point defined.env_fnsc              3  (   >#    U  H  nTv   M	     g 7fr$   r%   )r   _r:  s     r)   r   make_vec.<locals>.<genexpr>  s     @1&s   r   zhCustom vector environment can be passed arguments only through kwargs and `vector_kwargs` is not empty (r  zOCannot use `vector_entry_point` vectorization mode with the wrappers argument (r  zsCannot use `vector_entry_point` vectorization mode with the additional_wrappers parameter in spec being not empty (z6 because it doesn't have a vector entry point defined.rN   zUnknown vectorization mode: r   autoreset_modezThe VectorEnv (z.) is missing AutoresetMode metadata, metadata=zB) metadata['autoreset_mode'] is not an instance of AutoresetMode, r   )r.   r   r%   )%r   r   r>   r   r   r   r   r  r  r(   rR   rd   r  rZ   r   r   r   rn   rr   r@   rE   r   vectorSyncVectorEnvranger   AsyncVectorEnvr   rX   rm   r  rN   r#  r   r   r   r   )rE   r4  r5  r6  r%  r(   moder  r>  r@   r,  copied_id_specr:  ro   r+  s       `       @@@r)   r   r   ;  s   : "g	B		b>kk-d2hZ7TUVV}}X&HooOfHO"":x8H(,,-ACUV#''GM"":x8H6" !&&2!.!A!A!.!3!3	!./A!B (-8888  ]///'++;HKK=Hxy  jj&& 
@h@

 
}22	2'++;HKK=Hxy  jj'' 
05h@1&@


 
}??	?}!++z  |I  {J  JK  L  ]Q++abjakkmn  --.2++ F  GO  Gc  Gc  Fd  df  g  11++;B4?uv  k""%K*;7K &&2#?:3;3M3MO/0?8??kk89K8LMNN ]]8,N+002N1},4j)2D2J2JN./
=A1>o.
8}q,4j)'MMs||+cU"PQTQ]Q]P^_	
 J %56FFcU"deijmjvjv  xH  kI  fJ  eK  KL  M	
 J{  	./A.D E 8E F FGI 	D As   (R  >S$ S!<SS!c                    [         R                  U 5      nUc3  [        U 5      u  p#n[        X#U5        [        R
                  " SU  35      e[        U[        5      (       d   SU  S[        U5       35       eU$ )a  Retrieve the :class:`EnvSpec` for the environment id from the :attr:`registry`.

Args:
    env_id: The environment id with the expected format of ``[(namespace)/]id[-v(version)]``

Returns:
    The environment spec if it exists

Raises:
    Error: If the environment id doesn't exist
r   zExpected the registry for z$ to be an `EnvSpec`, actual type is )	r   r   r\   r   r   r   r   r   r   )r   ro   r   r?   rV   s        r)   r   r     s     ||F#H(0'b0kk7x@AAg
 
 	e'x/STXYaTbScd	e 
 r,      )num_colsexclude_namespacesr   c                  [        [        5      n[        S5      nU R                  5        H  nUR                  nUc  [        UR                  [        5      (       ai  [        R                  " SSUR                  5      nUR                  S5      n	[        U	5      S:  a  U	S   nO![        U	5      S:  a  U	S   nOUR                  nXG   R                  UR                  5        [        U[        UR                  5      5      nM     / n
UR!                  5        H  u  p{Ub  Xr;   a  M  S	 S
U S
S	 S3n[#        [%        U5      S5       HL  u  pXR'                  U5      S
-   -  nX-  S:X  d  M%  UR)                  S
5      nU[        U5      :w  d  MG  US-  nMN     U
R                  UR)                  S
5      5        M     U(       a  SR+                  U
5      $ [-        SR+                  U
5      5        g)a  Pretty prints all environments in the :attr:`registry`.

Note:
    All arguments are keyword only

Args:
    print_registry: Environment registry to be printed. By default, :attr:`registry`
    num_cols: Number of columns to arrange environments in, for display.
    exclude_namespaces: A list of namespaces to be excluded from printing. Helpful if only ALE environments are wanted.
    disable_print: Whether to return a string of all the namespaces and environment IDs
        or to print the string to console.
z-infNz:\w+r   r   rH     r   z===== 
r   )r   r   floatr   rU   r   r@   r>   resubr   r   r?   rv   rE   r   rl   	enumerater   ljustrstripr   r   )print_registryrI  rJ  r   namespace_envsmax_justifyro   r   env_entry_pointsplit_entry_pointr   env_idsnamespace_outputcountr   s                  r)   r   r     s   ( ,7t+<N-K #))+:*X%9%93?? ffWb(2F2FGO / 5 5c :$%* 'q)&'!+&q) ]]!!(++.+s8=='9:+ ,0 F%++-)b.F &Yat1WIR8 'vg:ME[ 9C ?? 1$#3#:#:3#? CL($,$ ; 	&--c23) ., yy  dii r,   )r   r>   r.   z"tuple[str | None, str, int | None])r   rT   r?   r>   rV   rM   r.   r>   )r   rT   r?   r>   r.   rM   )r   rT   )r   rT   r?   r>   )r   rT   r?   r>   rV   rM   )r   r   )r   r   )r   r>   r.   r   )r?   r>   r.   zEnvCreator | VectorEnvCreator)r  r   )r   r>   )	NNFNTFr%   NN)rE   r>   r@   rH   rJ   rI   rL   rK   rN   rM   rO   rK   rP   rK   rX   rW   rZ   rY   r(   zdict | None)NN)
rE   str | EnvSpecrN   rM   rP   zbool | Noner(   r   r.   r   )r   NNN)rE   r]  r4  r   r5  zVectorizeMode | str | Noner6  rA   r%  z)Sequence[Callable[[Env], Wrapper]] | Noner.   r;   )
rU  r   rI  r   rJ  zlist[str] | Noner   rK   r.   rT   )Cr4   
__future__r   
contextlibr  rb   r   r   importlib.metadatar   importlib.utilrf   rP  collectionsr   collections.abcr   r   r   r   r	   enumr
   typesr   typingr   r   	gymnasiumr   r   r   r   r   gymnasium.loggerr   gymnasium.vectorr   compiler   __all__r    r7   r   r   r   r   rB   r   r\   r   r   r   r   r   r   r   r   r  r   contextmanagerrU   r   r   r   r   r   r%   r,   r)   <module>rm     s   y "      %   	 # 8 8 (      1 1 ! * JJT	
 2 2Cx C 
" 
" 
" j j jZ.D .  "
 ! $ : $0(&(Q6,7
t$
N
$*Z	
 & & ,0%)"$( %358<I%I%(I% #I% 	I%
 "I% I% I% 1I% 6I% I%\ %)'+xx!x %x 	x
 	xz 59+/:>[[[ 3[ )	[
 8[ [|2 *2J! +/J!&J! J! )	J!
 J! J!r,   