
    niG                     ~    S r SSKJr  SSKJr  SSKJr  SSKr SSKJs  Jr	   " S S\5      rg! \
 a    SSKr	 Nf = f)z8Put an OpenAI Gym environment into the TensorFlow graph.    )absolute_import)division)print_functionNc                       \ rS rSrSrS rS rS rS r\	S 5       r
\	S 5       r\	S	 5       r\	S
 5       r\	S 5       rS rS rSrg)
InGraphEnv   zPut an OpenAI Gym environment into the TensorFlow graph.

The environment will be stepped and reset inside of the graph using
tf.py_func(). The current observation, action, reward, and done flag are held
in according variables.
c                 P   Xl         U R                  U R                   R                  5      nU R                  U R                   R                  5      nU R                  U R                   R                  5      nU R                  U R                   R                  5      n[
        R                  " S5         [
        R                  " [
        R                  " X#5      SSS9U l	        [
        R                  " [
        R                  " XE5      SSS9U l
        [
        R                  " S[
        R                  SSS9U l        [
        R                  " S	[
        R                  S
SS9U l        [
        R                  " S[
        R                  SSS9U l        SSS5        g! , (       d  f       g= f)z_Put an OpenAI Gym environment into the TensorFlow graph.

Args:
  env: OpenAI Gym environment.
environmentobservF)name	trainableactiong        reward)dtyper   r   Tdoner   stepN)_env_parse_shapeobservation_space_parse_dtypeaction_spacetf
name_scopeVariablezeros_observ_actionfloat32_rewardbool_doneint32_step)selfenvobserv_shapeobserv_dtypeaction_shapeaction_dtypes         a/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/agents/tools/in_graph_env.py__init__InGraphEnv.__init__#   s    I$$TYY%@%@AL$$TYY%@%@AL$$TYY%;%;<L$$TYY%;%;<L	}	%[[,!E&.+02dl [[,!E&.+02dl [[BJJXQVWdl;;t2775Qdj;;qvOdj 
&	%	%s   1CF
F%c                 .    [        U R                  U5      $ )zForward unimplemented attributes to the original environment.

Args:
  name: Attribute that was accessed.

Returns:
  Value behind the attribute name in the wrapped environment.
)getattrr   )r$   r   s     r*   __getattr__InGraphEnv.__getattr__9   s     499d##    c           
      ^  ^  [         R                  " S5         UR                  [         R                  [         R                  [         R
                  4;   a  [         R                  " US5      nT R                  T R                  R                  5      n[         R                  " U 4S jU/U[         R                  [         R                  /SS9u  p4n[         R                  " US5      n[         R                  " US5      n[         R                  " T R                  R                  U5      T R                  R                  U5      T R                   R                  U5      T R"                  R                  U5      T R$                  R'                  S5      5      sS	S	S	5        $ ! , (       d  f       g	= f)
zStep the environment.

The result of the step can be accessed from the variables defined below.

Args:
  action: Tensor holding the action to apply.

Returns:
  Operation.
zenvironment/simulater   c                 @   > TR                   R                  U 5      S S $ )N   )r   r   )ar$   s    r*   <lambda>%InGraphEnv.simulate.<locals>.<lambda>S   s    $))..2CBQ2Gr1   r   r   r   r      N)r   r   r   float16r   float64check_numericsr   r   r   py_funcr    groupr   assignr   r   r!   r#   
assign_add)r$   r   r'   r   r   r   s   `     r*   simulateInGraphEnv.simulateD   s!    
-	.	"**bjj"**=	=""684&&tyy'B'BClZZ(G&)5rzz277(K-35fd   2f  2fXXdll))&14<<3F3Fv3Nll))&14::3D3DT3Jjj++A.0 
/	.	.s   E<F
F,c                    U R                  U R                  R                  5      n[        R                  " U R                  R
                  / USS9n[        R                  " US5      n[        R                  " U R                  R                  U5      U R                  R                  S5      U R                  R                  S5      /5         [        R                  " U5      sSSS5        $ ! , (       d  f       g= f)zFReset the environment.

Returns:
  Tensor of the current observation.
resetr8   r   r   FN)r   r   r   r   r=   rD   r<   control_dependenciesr   r?   r   r!   identity)r$   r'   r   s      r*   rD   InGraphEnv.reset\   s     $$TYY%@%@ALZZ		\HFvx0F		 	 			V	$			Q				5	!	#
$ [[ 	
$ 
$ 
$s   C,,
C:c                     U R                   $ )z4Access the variable holding the current observation.)r   r$   s    r*   r   InGraphEnv.observk        <<r1   c                     U R                   $ )z5Access the variable holding the last recieved action.)r   rI   s    r*   r   InGraphEnv.actionp   rK   r1   c                     U R                   $ )z/Access the variable holding the current reward.)r   rI   s    r*   r   InGraphEnv.rewardu   rK   r1   c                     U R                   $ )z;Access the variable indicating whether the episode is done.)r!   rI   s    r*   r   InGraphEnv.donez        ::r1   c                     U R                   $ )z=Access the variable containg total steps of this environment.)r#   rI   s    r*   r   InGraphEnv.step   rR   r1   c                     [        U[        R                  R                  5      (       a  g[        U[        R                  R                  5      (       a  UR
                  $ [        5       e)z`Get a tensor shape from a OpenAI Gym space.

Args:
  space: Gym space.

Returns:
  Shape tuple.
 )
isinstancegymspacesDiscreteBoxshapeNotImplementedErrorr$   spaces     r*   r   InGraphEnv._parse_shape   sF     %,,--%(([[

r1   c                     [        U[        R                  R                  5      (       a  [        R
                  $ [        U[        R                  R                  5      (       a  [        R                  $ [        5       e)ziGet a tensor dtype from a OpenAI Gym space.

Args:
  space: Gym space.

Returns:
  TensorFlow data type.
)	rW   rX   rY   rZ   r   r"   r[   r   r]   r^   s     r*   r   InGraphEnv._parse_dtype   sL     %,,--XXo%((ZZ

r1   )r   r!   r   r   r   r#   N)__name__
__module____qualname____firstlineno____doc__r+   r/   rA   rD   propertyr   r   r   r   r   r   r   __static_attributes__rV   r1   r*   r   r      s    P,	$00!            r1   r   )rg   
__future__r   r   r   rX   tensorflow.compat.v1compatv1r   	Exception
tensorflowobjectr   rV   r1   r*   <module>rq      sC    ? &  % 
##
E  E 	  s   	/ 
<<