Gym🏋️
pamiq_core.gym.GymEnvironment ¶
Bases: Environment[GymObs[O], GymAction[A]]
Wrapper for Gymnasium environments to work with PAMIQ Core.
This class adapts Gymnasium environments to the PAMIQ Core Environment interface, handling observation and action conversions between the two frameworks.
Example
Initialize the GymEnvironment wrapper.
PARAMETER | DESCRIPTION |
---|---|
env
|
Either a Gymnasium environment instance or a string ID to create one
TYPE:
|
**gym_make_kwds
|
Additional keyword arguments passed to gym.make() if env is a string
TYPE:
|
Source code in src/pamiq_core/gym/env.py
setup ¶
Set up the environment by resetting it to initial state.
This method is called during environment initialization and stores the initial observation from the reset.
Source code in src/pamiq_core/gym/env.py
observe ¶
Get the current observation from the environment.
RETURNS | DESCRIPTION |
---|---|
GymObs[O]
|
The current observation, which can be: |
GymObs[O]
|
|
GymObs[O]
|
|
GymObs[O]
|
|
Source code in src/pamiq_core/gym/env.py
affect ¶
Apply an action to the environment and update the observation.
PARAMETER | DESCRIPTION |
---|---|
action
|
The action to apply, containing the actual action value and a flag indicating if reset is needed
TYPE:
|
The observation is updated based on the step result and whether the episode has ended or a reset was requested.
Source code in src/pamiq_core/gym/env.py
pamiq_core.gym.GymAgent ¶
Bases: Agent[GymObs[O], GymAction[A]]
Base class for agents that interact with Gymnasium environments.
This abstract class provides the interface for agents to handle Gymnasium environment observations and produce actions.
Set self.need_reset=True
to reset the environment after current step.
Example
Source code in src/pamiq_core/interaction/agent.py
setup ¶
on_reset
abstractmethod
¶
Handle environment reset and return initial action.
PARAMETER | DESCRIPTION |
---|---|
obs
|
Initial observation from the environment
TYPE:
|
info
|
Additional information from the environment
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A
|
The initial action to take |
Source code in src/pamiq_core/gym/agent.py
on_step
abstractmethod
¶
Process a step observation and return next action.
PARAMETER | DESCRIPTION |
---|---|
obs
|
Current observation from the environment
TYPE:
|
reward
|
Reward received from the previous action
TYPE:
|
truncated
|
Whether the episode was truncated
TYPE:
|
truncated
|
Whether the episode was truncated before completion
TYPE:
|
terminated
|
Whether the episode terminated successfully
TYPE:
|
info
|
Additional information from the environment
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A
|
The next action to take |
Source code in src/pamiq_core/gym/agent.py
step ¶
Process observation and return action wrapped with reset flag.
Handles different observation types: - EnvReset: Initial observation after reset - EnvStep: Regular step observation - tuple: Combined step and reset (episode end)
PARAMETER | DESCRIPTION |
---|---|
observation
|
Current observation from the environment
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GymAction[A]
|
Action wrapped with need_reset flag |