qgym.templates package
This package contains templates used from building custom environments.
All Environment
s should inherit from Environment
and should contain a rewarder,
state and visualiser which inherit from the base classes Rewarder
, State
and
Visualiser
respectively.
- class qgym.templates.Environment[source]
Bases:
Env
[ObservationT
,ActionT
]RL Environment containing the current state of the problem.
Each subclass should set at least the following attributes:
- action_space: Space[Any]
The action space of this environment.
- observation_space: Space[Any]
The observation space of this environment.
- abstract reset(*, seed=None, options=None)[source]
Reset the environment and load a new random initial state.
To be used after an episode is finished. Optionally, one can provide additional options to configure the reset.
- Parameters:
- Return type:
- Returns:
Initial observation and a dictionary containing debugging information.
- property rewarder: Rewarder
Return the rewarder that is set for this environment.
Used to compute rewards after each step.
- property rng: Generator
Return the random number generator of this environment.
If none is set yet, this will generate a new one using
numpy.random.default_rng
.
- step(action)[source]
Update the state based on the input action.
Return observation, reward, done-indicator, terminated-indicator and debugging info based on the updated state.
- Parameters:
action (
TypeVar
(ActionT
)) – Action to be performed.- Return type:
tuple
[TypeVar
(ObservationT
),float
,bool
,bool
,dict
[Any
,Any
]]- Returns:
A tuple containing five entries
The updated state;
Reward for the given action;
Boolean value stating whether the new state is a final state (i.e., if we are done);
Boolean value stating whether the episode is truncated.
Additional (debugging) information.
- class qgym.templates.Rewarder[source]
Bases:
object
RL Rewarder, for computing rewards on a state.
- __eq__(other)[source]
Checks whether an object ‘other’ is equal to self.
This check is performed by checking of the self and other are of exactly the same type. Afterwards, all slots (if any) are equal and if all attributes are equal.
- Return type:
- Returns:
Boolean stating wether other is equal to self.
- class qgym.templates.State[source]
Bases:
Generic
[ObservationT
,ActionT
]RL State containing the current state of the problem.
- abstract obtain_observation()[source]
Observation based on the current state.
- Return type:
TypeVar
(ObservationT
)
- property rng: Generator
Return the random number generator of this environment. If none is set yet, this will generate a new one using
numpy.random.default_rng
.- Returns:
Random number generator used by this
Environment
.