stormvogel.gym_env¶
Gymnasium-compliant environment wrapping a stormvogel MDP, DTMC, POMDP, or HMM.
Exceptions¶
Raised when the chosen action is not available in the current state. |
Classes¶
Gymnasium environment wrapping a stormvogel MDP, DTMC, POMDP, or HMM. |
Functions¶
|
|
|
Encode a single domain value as a non-negative integer for gymnasium. |
Module Contents¶
Bases:
ExceptionRaised when the chosen action is not available in the current state.
- stormvogel.gym_env._domain_size(domain: stormvogel.model.variable.VariableDomain) int¶
- stormvogel.gym_env._encode_value(domain: stormvogel.model.variable.VariableDomain, value: Any) int¶
Encode a single domain value as a non-negative integer for gymnasium.
- class stormvogel.gym_env.ModelEnv(model: stormvogel.model.Model, reward_model_name: str | None = None, obs_type: Literal['index', 'valuations'] = 'index')¶
Bases:
gymnasium.EnvGymnasium environment wrapping a stormvogel MDP, DTMC, POMDP, or HMM.
Two observation modes are supported, selected by
obs_type:"index"(default): - MDP/DTMC:Discrete(n_states)— integer index of the current state. - POMDP/HMM:Discrete(n_observations)— integer index of theobservation associated with the current state.
"valuations": - MDP/DTMC:Dictspace built from state variables that carry adeclared domain (
Variable.domain is not None).POMDP/HMM:
Dictspace built from observation variables that carry a declared domain (Variable.domain is not None).
Each variable becomes a
Discretecomponent; values are encoded as non-negative integers.IntDomain(lo, hi): valuev→v - lo;BoolDomain:False→0,True→1;CategoricalDomain: index intodomain.values.Nonemaps to the last index whenallow_noneis set. Missing variable values are raised asValueErrorat step time.
For MDP/POMDP models the action space is
Discrete(n_actions)where actions are indexed in the order returned bymodel.actions.For DTMC/HMM models the action space is
Discrete(1); the single legal action index is 0 (mapped internally toEmptyAction).Stochastic observations (
Distributionover observations) are not supported and raiseNotImplementedErrorat step time.- Parameters:
model – A stormvogel model of type MDP, DTMC, POMDP, or HMM.
reward_model_name – Name of the reward model to use for the step reward. If
Noneand exactly one reward model exists it is used automatically. IfNoneand multiple reward models exist aValueErroris raised. No reward models → reward is always 0.obs_type –
"index"for a flat observation space,"valuations"for aDictspace built from variable domains.
- Raises:
ValueError – If
obs_type="valuations"but no domain-bearing variables are found.
- model¶
- _obs_type = 'index'¶
- _is_obs_model¶
- _index_to_state: list[stormvogel.model.State]¶
- _state_to_index: dict[stormvogel.model.State, int]¶
- _current_state: stormvogel.model.State¶
- _collect_obs_vars() list[stormvogel.model.variable.Variable]¶
Return domain-bearing variables in sorted label order.
- _encode_obs(state: stormvogel.model.State) int | dict[str, int]¶
- reset(*, seed: int | None = None, options: dict[str, Any] | None = None) tuple[int | dict[str, int], dict[str, Any]]¶
Reset the environment to the model’s initial state.
- Returns:
(observation, info)whereinfo["state"]is the initial stormvogelState.
- step(action: int) tuple[int | dict[str, int], float, bool, bool, dict[str, Any]]¶
Take one step in the environment.
- Parameters:
action – Integer action index. For MDPs this selects from
_index_to_action; for DTMCs only0is valid.- Returns:
(observation, reward, terminated, truncated, info)whereinfo["state"]is the next stormvogelStateandinfo["labels"]are its labels.- Raises:
ActionUnavailableError – If the chosen action is not available in the current state, or if
action != 0for a DTMC.