wrapper#
Source code: armscan_env/wrapper.py
- class AddObservationsWrapper(env: ArmscanEnv | Env)[source]#
When implementing it, make sure that additional_obs_space is available before super().__init__(env) is called.
- abstract property additional_obs_space: <module 'gymnasium.spaces' from '/home/runner/work/armscan_env/armscan_env/gymnasium/gymnasium/spaces/__init__.py'>#
- class ArmscanEnvFactory(name2volume: dict[str, ~SimpleITK.SimpleITK.Image], observation: ~armscan_env.envs.base.Observation[~armscan_env.envs.state_action.LabelmapStateAction, ~typing.Any], reward_metric: ~armscan_env.envs.base.RewardMetric[~armscan_env.envs.state_action.LabelmapStateAction] = <armscan_env.envs.rewards.LabelmapClusteringBasedReward object>, termination_criterion: ~armscan_env.envs.base.TerminationCriterion | None = <armscan_env.envs.labelmaps_navigation.LabelmapEnvTerminationCriterion object>, slice_shape: tuple[int, int] | None = None, max_episode_len: int | None = None, rotation_bounds: tuple[float, float] = (180, 180), translation_bounds: tuple[float | None, float | None] = (None, None), render_mode_train: ~typing.Literal['plt', 'animation'] | None = None, render_mode_test: ~typing.Literal['plt', 'animation'] | None = None, render_mode_watch: ~typing.Literal['plt', 'animation'] | None = 'animation', venv_type: ~tianshou.highlevel.env.VectorEnvType = VectorEnvType.SUBPROC_SHARED_MEM_AUTO, seed: int | None = None, n_stack: int = 1, project_actions_to: ~typing.Literal['x', 'y', 'xy', 'zy'] | None = None, apply_volume_transformation: bool = False, best_reward_memory: int = 0, exclude_keys_from_framestack: ~collections.abc.Sequence[str] = (), **make_kwargs: ~typing.Any)[source]#
Factory for creating ArmscanEnv environments, making use of various wrappers.
- create_env(mode: EnvMode) ArmscanEnv [source]#
Creates a single environment for the given mode.
- Returns:
ArmscanEnv environment
- class BestActionRewardMemory(env: ArmscanEnv, n_best: int)[source]#
Adds the action that would lead to the highest image variance to the observation. In focus-stigmation agents, this helps in the initial exploratory phase of episodes, as it allows wandering around the state space without worrying about losing track of the best image found so far.
- Parameters:
env -- The environment to wrap.
n_best -- Number of best states to keep track of.
- property additional_obs_space: <module 'gymnasium.spaces' from '/home/runner/work/armscan_env/armscan_env/gymnasium/gymnasium/spaces/__init__.py'>#
- class ObsHeap(max_size: int, padding_value: float | None = None, padding_item: ObsType | None = None)[source]#
Heap of the best rewards and their corresponding observations. The size of the heap is fixed and the best n rewards are kept. When the first reward-observation pair is inserted, the heap is initialized with the padding value and item. By default, padding is done with the first inserted value and item.
- Parameters:
max_size -- the maximum size of the heap
padding_value -- the value to use for padding
padding_item -- the item to use for padding
- class ObsRewardHeapItem(obs: ObsType, reward: float)[source]#
Heap of the best rewards and their corresponding observations.
- class PatchedFlattenObservation(env: Env[ObsType, ActType])[source]#
Flattens the environment's observation space and each observation from
reset
andstep
functions. Had to copy-paste and adjust.
- class PatchedFrameStackObservation(env: Env[ObsType, ActType], stack_size: int, *, padding_type: str | ObsType = 'reset', excluded_observation_keys: Sequence[str] = ())[source]#
Had to copy-paste and adjust.
The inheriting from RecordConstructorArgs in original FrameStack is not possible together with overridden getattr, which we however need in order to not become crazy. So there is no way of fixing this after inheriting from original FrameStackObservation, wherefore we copy-paste the whole class and adjust it.
- Adjustments:
reset takes **kwargs
render takes **kwargs
__getattr__ is overridden to pass the attribute to the wrapped environment (like in pre-1.0 wrappers)
No inheritance from RecordConstructorArgs
Observation space is converted to MultiBoxSpace if it is a DictSpace
Excluded observation keys are supported for Dict observation spaces
- Parameters:
env -- the environment to wrap
stack_size -- the number of observations to stack
padding_type -- the type of padding to use
excluded_observation_keys -- the keys of the observations to exclude from stacking. The observations with these keys will be passed through without stacking. Can only be used with Dict observation spaces.