
    h@                        S r SSKJr  SSKJr  SSKJrJrJr  SSK	r
SSKJr  \" S5      r\" S5      r\" S	5      r\" S
5      r\" S5      r\" S5      r\" S5      r " S S\\\\\\\\4   5      rg)zBase class and definitions for an alternative, functional backend for gym envs, particularly suitable for hardware accelerated and otherwise transformed environments.    )annotations)Callable)AnyGenericTypeVarN)Space	StateTypeActTypeObsType
RewardTypeTerminalTypeRenderStateTypeParamsc                  L   \ rS rSr% SrS\S'   S\S'   SSS jjrSSS jjr S         SS	 jjr S       SS
 jjr	 S           SS jjr
 S       SS jjrSSS jjr S         SS jjrSS jr S       SS jjrSS S jjrSS!S jjrS"S jrSrg)#FuncEnv   a  Base class (template) for functional envs.

This API is meant to be used in a stateless manner, with the environment state being passed around explicitly.
That being said, nothing here prevents users from using the environment statefully, it's just not recommended.
A functional env consists of the following functions (in this case, instance methods):

 * initial: returns the initial state of the POMDP
 * observation: returns the observation in a given state
 * transition: returns the next state after taking an action in a given state
 * reward: returns the reward for a given (state, action, next_state) tuple
 * terminal: returns whether a given state is terminal
 * state_info: optional, returns a dict of info about a given state
 * step_info: optional, returns a dict of info about a given (state, action, next_state) tuple

The class-based structure serves the purpose of allowing environment constants to be defined in the class,
and then using them by name in the code itself.

For the moment, this is predominantly for internal use. This API is likely to change, but in the future
we intend to flesh it out and officially expose it to end users.
r   observation_spaceaction_spaceNc                v    U R                   R                  U=(       d    0 5        U R                  5       U l        g)z%Initialize the environment constants.N)__dict__updateget_default_paramsdefault_params)selfoptionss     [/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/experimental/functional.py__init__FuncEnv.__init__3   s)    W]+"557    c                    [         e)zNGenerates the initial state of the environment with a random number generator.NotImplementedError)r   rngparamss      r   initialFuncEnv.initial8       !!r   c                    [         e)zKUpdates (transitions) the state with an action and random number generator.r!   )r   stateactionr#   r$   s        r   
transitionFuncEnv.transition<   
     "!r   c                    [         e)z=Generates an observation for a given state of an environment.r!   r   r)   r#   r$   s       r   observationFuncEnv.observationB   r-   r   c                    [         e)zUComputes the reward for a given transition between `state`, `action` to `next_state`.r!   )r   r)   r*   
next_stater#   r$   s         r   rewardFuncEnv.rewardH   s
     "!r   c                    [         e)z/Returns if the state is a final terminal state.r!   r/   s       r   terminalFuncEnv.terminalS   r-   r   c                    0 $ )zInfo dict about a single state. )r   r)   r$   s      r   
state_infoFuncEnv.state_infoY   s    	r   c                    0 $ )z"Info dict about a full transition.r:   )r   r)   r*   r3   r$   s        r   transition_infoFuncEnv.transition_info]   s	     	r   c                F   U" U R                   5      U l         U" U R                  5      U l        U" U R                  5      U l        U" U R                  5      U l        U" U R                  5      U l        U" U R
                  5      U l        U" U R                  5      U l        g)zFunctional transformations.N)r%   r+   r0   r4   r7   r;   r>   	step_info)r   funcs     r   	transformFuncEnv.transformg   sw    DLL)t/ 0 014;;'T]]+t/d223r   c                    [         e)zShow the state.r!   )r   r)   render_stater$   s       r   render_imageFuncEnv.render_imageq   s
     "!r   c                    [         e)zInitialize the render state.r!   )r   r$   kwargss      r   render_initFuncEnv.render_initz   r'   r   c                    [         e)zClose the render state.r!   )r   rF   r$   s      r   render_closeFuncEnv.render_close~   r'   r   c                    g)zGet the default params.Nr:   )r   rJ   s     r   r   FuncEnv.get_default_params   s    r   )r   r%   r0   r4   r;   rA   r7   r+   )N)r   zdict[str, Any] | None)r#   r   r$   Params | Nonereturnr	   )
r)   r	   r*   r
   r#   r   r$   rR   rS   r	   )r)   r	   r#   r   r$   rR   rS   r   )r)   r	   r*   r
   r3   r	   r#   r   r$   rR   rS   r   )r)   r	   r#   r   r$   rR   rS   r   )r)   r	   r$   rR   rS   dict)
r)   r	   r*   r
   r3   r	   r$   rR   rS   rT   )rB   zCallable[[Callable], Callable])r)   r	   rF   r   r$   rR   rS   z"tuple[RenderStateType, np.ndarray])r$   rR   rS   r   )rF   r   r$   rR   )rS   rR   )__name__
__module____qualname____firstlineno____doc____annotations__r   r%   r+   r0   r4   r7   r;   r>   rC   rG   rK   rN   r   __static_attributes__r:   r   r   r   r      sr   
* 8
"
 TX""(/"69"CP"	" CG""%("2?"	" !%	"	" 	" 		"
 	" 	" 
	" CG""%("2?"	" !%  	
  
4 !%	"" &" 	"
 
,"""r   r   )rY   
__future__r   collections.abcr   typingr   r   r   numpynp	gymnasiumr   r	   r
   r   r   r   r   r   r   r:   r   r   <module>rb      s    m " $ ( (   K 	
)

)
\"
~&+,		n7GZPVVnr   