sinergym.utils.wrappers.ProbabilisticContextWrapperļ
- class sinergym.utils.wrappers.ProbabilisticContextWrapper(*args, **kwargs)ļ
Wrapper that probabilistically updates context variables at each step.
This wrapper provides a unified approach to context updates with multiple modes:
Probabilistic updates: Each step has a probability of triggering a context update
Multiple update modes: Same value for all variables, independent values, or probabilistic per-variable updates
Support for both absolute values and delta-based increments to current context values
- __init__(*args, **kwargs)ļ
Wraps an environment to allow a modular transformation of the
step()andreset()methods.- Parameters:
env ā The environment to wrap
Methods
__init__(*args,Ā **kwargs)Wraps an environment to allow a modular transformation of the
step()andreset()methods.class_name()Returns the class name of the wrapper.
close()Closes the wrapper and
env.get_obs_dict(obs)Convert observation array to dictionary with variable names as keys.
get_wrapper_attr(name)Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.
has_wrapper_attr(name)Checks if the given attribute is within the wrapper or its environment.
render()Uses the
render()of theenvthat can be overwritten to change the returned data.reset(**kwargs)Resets the environment and reinitializes current context.
set_wrapper_attr(name,Ā value,Ā *[,Ā force])Sets an attribute on this wrapper or lower environment if name is already defined.
step(action)Executes an action and probabilistically updates context if triggered.
wrapper_spec(**kwargs)Generates a WrapperSpec for the wrappers.
Attributes
action_spaceReturn the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.metadataReturns the
Envmetadata.np_randomReturns the
Envnp_randomattribute.np_random_seedReturns the base environment's
np_random_seed.observation_spaceReturn the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.render_modeReturns the
Envrender_mode.specReturns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.unwrappedReturns the base environment of the wrapper.
- logger = <Logger WRAPPER ProbabilisticContextWrapper (INFO)>ļ
- reset(**kwargs) Tuple[ndarray, Dict[str, Any]]ļ
Resets the environment and reinitializes current context.
- Parameters:
**kwargs ā Additional arguments passed to the underlying environmentās reset method.
- Returns:
- Standard Gymnasium reset return containing:
Initial observation
Info dictionary
- Return type:
Tuple[np.ndarray, Dict[str, Any]]
- step(action: ndarray) Tuple[ndarray, SupportsFloat, bool, bool, Dict[str, Any]]ļ
Executes an action and probabilistically updates context if triggered.
The update behavior depends on the type of update_probability:
If update_probability is a float: At each step, thereās a probability that a context update event occurs. When it does, all context variables are updated together according to the configured mode and type.
If update_probability is a list: In each step, each context variable is independently evaluated according to its probability. Variables that pass their probability check are updated according to the configured mode and type.
- Parameters:
action (np.ndarray) ā Action selected by the agent.
- Returns:
- Standard Gymnasium step
return containing:
Observation for next timestep
Reward obtained
Whether the episode has ended (terminated)
Whether episode has been truncated
Dictionary with extra information
- Return type:
Tuple[np.ndarray, SupportsFloat, bool, bool, Dict[str, Any]]