
    &`iK                     ^    d dl Z d dlmZ d dlmZ d dlmZ e G d de                      ZdS )    N)Optional)EnvConfigDict)DeveloperAPIc                        e Zd ZdZ	 	 	 	 ddedededed	ee         d
efdZ	 	 	 	 	 	 ddee         dee         dee         dee         d	ee         d
ee         dd fdZ	de
ddfdZ fdZ xZS )
EnvContextaK  Wraps env configurations to include extra rllib metadata.

    These attributes can be used to parameterize environments per process.
    For example, one might use `worker_index` to control which data file an
    environment reads in on initialization.

    RLlib auto-sets these attributes when constructing registered envs.
    r   FN
env_configworker_indexvector_indexremotenum_workersrecreated_workerc                     t                               | |           || _        || _        || _        || _        || _        dS )a  Initializes an EnvContext instance.

        Args:
            env_config: The env's configuration defined under the
                "env_config" key in the Algorithm's config.
            worker_index: When there are multiple workers created, this
                uniquely identifies the worker the env is created in.
                0 for local worker, >0 for remote workers.
            vector_index: When there are multiple envs per worker, this
                uniquely identifies the env index within the worker.
                Starts from 0.
            remote: Whether individual sub-environments (in a vectorized
                env) should be @ray.remote actors or not.
            num_workers: The total number of (remote) workers in the set.
                0 if only a local worker exists.
            recreated_worker: Whether the worker that holds this env is a recreated one.
                This means that it replaced a previous (failed) worker when
                `restart_failed_env_runners=True` in the Algorithm's config.
        N)dict__init__r	   r
   r   r   r   selfr   r	   r
   r   r   r   s          m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/env/env_context.pyr   zEnvContext.__init__   sG    : 	dJ''' )(& 0    returnc                     t          |t          j        |          n| ||n| j        ||n| j        ||n| j        ||n| j        ||n| j                  S )a]  Returns a copy of this EnvContext with some attributes overridden.

        Args:
            env_config: Optional env config to use. None for not overriding
                the one from the source (self).
            worker_index: Optional worker index to use. None for not
                overriding the one from the source (self).
            vector_index: Optional vector index to use. None for not
                overriding the one from the source (self).
            remote: Optional remote setting to use. None for not overriding
                the one from the source (self).
            num_workers: Optional num_workers to use. None for not overriding
                the one from the source (self).
            recreated_worker: Optional flag, indicating, whether the worker that holds
                the env is a recreated one. This means that it replaced a previous
                (failed) worker when `restart_failed_env_runners=True` in the
                Algorithm's config.

        Returns:
            A new EnvContext object as a copy of self plus the provided
            overrides.
        )r   copydeepcopyr	   r
   r   r   r   r   s          r   copy_with_overrideszEnvContext.copy_with_overrides9   sy    > )3)?DM*%%%T(4LL$:K(4LL$:K(FFdk&2KK8H 0 <$BW
 
 	
r   defaultsc                 L    |                                 D ]\  }}|| vr|| |<   dS )a  Sets missing keys of self to the values given in `defaults`.

        If `defaults` contains keys that already exist in self, don't override
        the values with these defaults.

        Args:
            defaults: The key/value pairs to add to self, but only for those
                keys in `defaults` that don't exist yet in self.

        .. testcode::
            :skipif: True

            from ray.rllib.env.env_context import EnvContext
            env_ctx = EnvContext({"a": 1, "b": 2}, worker_index=0)
            env_ctx.set_defaults({"a": -42, "c": 3})
            print(env_ctx)

        .. testoutput::

            {"a": 1, "b": 2, "c": 3}
        N)items)r   r   keyvalues       r   set_defaultszEnvContext.set_defaultsa   s>    , #..** 	" 	"JC$!S		" 	"r   c           	          t                                                      d d         d| j         d| j         d| j         d| j         z   dz   S )Nz	, worker=/z, vector_idx=z	, remote=})super__str__r	   r   r
   r   )r   	__class__s    r   r%   zEnvContext.__str__{   s|    GGOOcrc"D$+ D Dd.> D D+D D6:kD DDFIJ	
r   )r   FNF)NNNNNN)__name__
__module____qualname____doc__r   intboolr   r   r   r   r   r%   __classcell__)r&   s   @r   r   r      sU         %)!&$1 $1!$1 $1 	$1
 $1 c]$1 $1 $1 $1 $1P /3&*&*!%%)+/&
 &
]+&
 sm&
 sm	&

 &
 c]&
 #4.&
 
&
 &
 &
 &
P"T "d " " " "4
 
 
 
 
 
 
 
 
r   r   )	r   typingr   ray.rllib.utils.typingr   ray.util.annotationsr   r   r    r   r   <module>r2      s           0 0 0 0 0 0 - - - - - - w
 w
 w
 w
 w
 w
 w
 w
 w
 w
r   