imitation_datasets
controller
Controller for running experiments.
Source code in src/imitation_datasets/controller.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
__init__(enjoy, collate, amount, threads=1, path='./dataset/')
Initialize the controller.
Parameters: |
|
---|
src/imitation_datasets/controller.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
collate_closure(opt)
Create a closure for the collate function.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/controller.py
83 84 85 86 87 88 89 90 91 92 93 94 |
|
create_folder(path)
Create a folder if it does not exist.
Parameters: |
|
---|
src/imitation_datasets/controller.py
47 48 49 50 51 52 53 54 |
|
enjoy_closure(opt)
Create a closure for the enjoy function.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/controller.py
70 71 72 73 74 75 76 77 78 79 80 81 |
|
enjoy_sequence(future, executor)
async
summary
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/controller.py
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 |
|
run(opt)
async
Run the experiments.
Parameters: |
|
---|
src/imitation_datasets/controller.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
set_cpu(cpu)
async
Set the cpu affinity for the current process.
Parameters: |
|
---|
src/imitation_datasets/controller.py
56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
start(opt)
Start the experiments.
Parameters: |
|
---|
Raises: |
|
---|
src/imitation_datasets/controller.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
experts
Policy
Policy dataclass to load and use expert policies.
Source code in src/imitation_datasets/experts.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
get_environment()
Return environment name.
Returns: |
|
---|
src/imitation_datasets/experts.py
87 88 89 90 91 92 93 94 95 |
|
load()
Load policy from HuggingFace hub. It uses a custom_object to replicate stable_baselines behaviour.
custom_objects = { "learning_rate": 0.0, "lr_schedule": lambda : 0.0, "clip_range": lambda : 0.0 }
Returns: |
|
---|
src/imitation_datasets/experts.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
predict(obs, deterministic=True)
Predict action given observation.
Parameters: |
|
---|
Returns: |
|
---|
Note: typing depends on the environment.
src/imitation_datasets/experts.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
Experts
Helper class to register and get expert policies.
Source code in src/imitation_datasets/experts.py
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 127 128 129 130 |
|
get_expert(identifier)
classmethod
Return expert policy.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/experts.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
get_register()
classmethod
Print entire register of expert policies.
src/imitation_datasets/experts.py
127 128 129 130 |
|
register(identifier, policy)
classmethod
Register a new policy.
src/imitation_datasets/experts.py
104 105 106 107 108 109 110 |
|
functions
enjoy
This is a simple enjoy function example. It has three arguments and should return a boolean.
src/imitation_datasets/functions.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
baseline_enjoy
Enjoy following StableBaseline output.
src/imitation_datasets/functions.py
74 75 76 77 78 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 |
|
collate
This function is a simple collate function.
src/imitation_datasets/functions.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
baseline_collate
Collate that outputs the same as StableBaseline.
src/imitation_datasets/functions.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
utils
Experiment
Experiment dataclass to keep track of the experiments.
Source code in src/imitation_datasets/utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 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 |
|
__post_init__()
Write in log file that the dataset creation has started.
src/imitation_datasets/utils.py
53 54 55 56 57 58 59 60 |
|
add_log(experiment, log)
Add a log to the experiment.
Parameters: |
|
---|
src/imitation_datasets/utils.py
102 103 104 105 106 107 108 109 |
|
is_done()
Check if the experiment is done.
Returns: |
|
---|
src/imitation_datasets/utils.py
62 63 64 65 66 67 68 |
|
start(amount=1)
async
Start an experiment.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
stop(status, amount=1)
async
Stop an experiment.
Parameters: |
|
---|
src/imitation_datasets/utils.py
90 91 92 93 94 95 96 97 98 99 100 |
|
write_log()
Write the logs in the log file.
src/imitation_datasets/utils.py
111 112 113 114 115 116 117 |
|
Context
Context dataclass to keep track of the context of the experiment.
Source code in src/imitation_datasets/utils.py
120 121 122 123 124 125 126 127 128 |
|
add_log(log)
Add a log to the experiment.
src/imitation_datasets/utils.py
126 127 128 |
|
CPUS
CPUS dataclass to keep track of the available CPUs.
Source code in src/imitation_datasets/utils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
__post_init__()
Initialize the cpu_semaphore.
src/imitation_datasets/utils.py
139 140 141 142 143 |
|
cpu_allock()
async
Acquire a CPU.
Returns: |
|
---|
src/imitation_datasets/utils.py
145 146 147 148 149 150 151 152 153 154 155 |
|
cpu_release(cpu_idx)
Release a CPU.
Parameters: |
|
---|
src/imitation_datasets/utils.py
157 158 159 160 161 162 163 164 165 166 167 |
|
GymWrapper
Wrapper for gym environment. Since Gymnasium and Gym version 0.26 there are some environments that were working under Gym-v.0.21 stopped working. This wrapper just makes sure that the output for the environment will always work with the version the user wants.
Source code in src/imitation_datasets/utils.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
action_space
property
Map gym action_space attribute to wrapper.
observation_space
property
Map gym env_space attribute to wrapper.
__init__(environment, version='newest')
Parameters: |
|
---|
In this case, "newest" is 0.26 and "older" is 0.21.
src/imitation_datasets/utils.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
close()
Close the environment.
src/imitation_datasets/utils.py
266 267 268 |
|
render(mode='rgb_array')
Return the render for the environment.
src/imitation_datasets/utils.py
256 257 258 259 260 261 262 263 264 |
|
reset()
Resets the framework and return the appropriate return.
src/imitation_datasets/utils.py
231 232 233 234 235 236 |
|
set_seed(seed)
Set seed for all packages (Pytorch, Numpy and Python).
Parameters: |
|
---|
src/imitation_datasets/utils.py
221 222 223 224 225 226 227 228 229 |
|
step(action)
Perform an action in the environment and return the appropriate return according to version.
src/imitation_datasets/utils.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
WrapperException
Bases: Exception
Wrapper exception for all exceptions related to the wrapper.
Source code in src/imitation_datasets/utils.py
174 175 176 177 178 179 |
|
dataset
BaselineDataset
Bases: Dataset
Teacher dataset for IL methods.
Source code in src/imitation_datasets/dataset/dataset.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 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 |
|
__getitem__(index)
Get item from dataset.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/dataset/dataset.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
__init__(path, source='local', hf_split='train', split='train', n_episodes=None, transform=None)
Initialize dataset.
Parameters: |
|
---|
Raises: |
|
---|
src/imitation_datasets/dataset/dataset.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
__len__()
Dataset length.
Returns: |
|
---|
src/imitation_datasets/dataset/dataset.py
96 97 98 99 100 101 102 |
|
huggingface
baseline_to_huggingface
Loads baseline dataset from NpzFile, converts into a dict and save it into a JSONL file for upload.
Parameters: |
|
---|
Raises: |
|
---|
src/imitation_datasets/dataset/huggingface.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
baseline_to_huggingface
Loads baseline dataset from NpzFile, converts into a dict and save it into a JSONL file for upload.
Parameters: |
|
---|
Raises: |
|
---|
src/imitation_datasets/dataset/huggingface.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
metrics
performance
Compute the performance for the agent. Performance normalises between random and expert policies rewards, where performance 0 corresponds to random policy performance, and 1 are for expert policy performance.
performance = (X - X_min) / (X_max - X_min),
where X_min is the random_reward, and X_max is the teacher_reward.
Parameters: |
|
---|
Raises: |
|
---|
Returns: |
|
---|
src/imitation_datasets/dataset/metrics.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
average_episodic_reward
Compute the average episodic reward for the agent. AER is the average of 'n' episodes for each agent in each environment.
Parameters: |
|
---|
Returns: |
|
---|
src/imitation_datasets/dataset/metrics.py
52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
accuracy
Compute the accuracy for a model. The accuracy returned is the percentage from 0 to 100.
Parameters: |
|
---|
Raises: |
|
---|
Returns: |
|
---|
src/imitation_datasets/dataset/metrics.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|