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() and reset() methods.

Parameters:

env – The environment to wrap

Methods

__init__(*args,Ā **kwargs)

Wraps an environment to allow a modular transformation of the step() and reset() 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 the env that 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_space

Return the Env action_space unless overwritten then the wrapper action_space is used.

logger

metadata

Returns the Env metadata.

np_random

Returns the Env np_random attribute.

np_random_seed

Returns the base environment's np_random_seed.

observation_space

Return the Env observation_space unless overwritten then the wrapper observation_space is used.

render_mode

Returns the Env render_mode.

spec

Returns the Env spec attribute with the WrapperSpec if the wrapper inherits from EzPickle.

unwrapped

Returns 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]]