viberl.utils.mock_env
Mock environment for testing RL algorithms.
Provides a gymnasium-compatible environment that returns random valid values for all methods, useful for testing agents without complex environment setup.
Classes:
Name | Description |
---|---|
MockEnv |
A mock environment that returns random valid values for testing. |
MockEnv
MockEnv(state_size: int = 4, action_size: int = 2, max_episode_steps: int = 100)
Bases: Env
A mock environment that returns random valid values for testing.
This environment provides: - Random observations within observation space - Random rewards within reward range - Random terminal states - Random info dictionaries
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_size
|
int
|
Size of the observation space |
4
|
action_size
|
int
|
Number of discrete actions |
2
|
max_episode_steps
|
int
|
Maximum steps before truncation |
100
|
Methods:
Name | Description |
---|---|
reset |
Reset the environment with random initial state. |
step |
Take a step with random outcomes. |
render |
Mock render - does nothing. |
close |
Mock close - does nothing. |
seed |
Set random seed for reproducibility. |
Attributes:
Name | Type | Description |
---|---|---|
state_size |
|
|
action_size |
|
|
max_episode_steps |
|
|
observation_space |
|
|
action_space |
|
|
current_step |
|
Source code in viberl/utils/mock_env.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
state_size
instance-attribute
state_size = state_size
action_size
instance-attribute
action_size = action_size
max_episode_steps
instance-attribute
max_episode_steps = max_episode_steps
observation_space
instance-attribute
observation_space = Box(low=-1.0, high=1.0, shape=(state_size,), dtype=float32)
action_space
instance-attribute
action_space = Discrete(action_size)
current_step
instance-attribute
current_step = 0
reset
reset(seed: int | None = None, options: dict | None = None) -> tuple[ndarray, dict]
Reset the environment with random initial state.
Source code in viberl/utils/mock_env.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
step
step(action: int) -> tuple[ndarray, float, bool, bool, dict]
Take a step with random outcomes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
int
|
The action to take |
required |
Returns:
Type | Description |
---|---|
tuple[ndarray, float, bool, bool, dict]
|
observation, reward, terminated, truncated, info |
Source code in viberl/utils/mock_env.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
render
render() -> None
Mock render - does nothing.
Source code in viberl/utils/mock_env.py
128 129 |
|
close
close() -> None
Mock close - does nothing.
Source code in viberl/utils/mock_env.py
131 132 |
|
seed
seed(seed: int | None = None) -> None
Set random seed for reproducibility.
Source code in viberl/utils/mock_env.py
134 135 136 |
|