swarmrl.utils.utils Module API Reference¶
Utils for the SwarmRL package.
calc_ellipsoid_friction_factors_rotation(axial_semiaxis, equatorial_semiaxis, dynamic_viscosity)
¶
https://en.wikipedia.org/wiki/Perrin_friction_factors
Returns¶
gamma_ax, gamma_eq: The friction factors for rotation around the axial (symmetry) axis and for rotation around one of the equatorial axes
Source code in swarmrl/utils/utils.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
calc_ellipsoid_friction_factors_translation(axial_semiaxis, equatorial_semiaxis, dynamic_viscosity)
¶
https://link.springer.com/article/10.1007/BF02838005
Returns¶
gamma_ax, gamma_eq The friction coefficient for dragging the ellipsoid along its symmetry axis and along one of the equatorial axes
Source code in swarmrl/utils/utils.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
calc_signed_angle_between_directors(my_director, other_director)
¶
In 2D compare two different normalized directors to determine the angle between them
Parameters¶
my_director : np.ndarray Normalized director in 3D. other_director : np.ndarray Normalized director in 3D. Returns
signed_angle : float signed float which represents the signed angle of my_director to other_director with the mathematical sign convention.
Source code in swarmrl/utils/utils.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
create_colloids(n_cols, type_=0, center=np.array([500, 500, 0]), dist=200.0, face_middle=False)
¶
Create a number of colloids in a circle around the center of the box. This method is primarily used for writing tests. It is not used in the actual simulation. The colloids are created in a circle around the center of the box.
Parameters¶
n_cols : int Number of colloids to create. type_ : int, optional Type of the colloids to create. center : np.ndarray, optional Center of the circle in which the colloids are created. dist : float, optional Distance of the colloids to the center. face_middle : bool, optional If True, the colloids face the center of the circle.
Returns¶
colloids : list(Colloid) List of colloid.
Source code in swarmrl/utils/utils.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
gather_n_dim_indices(reference_array, indices)
¶
Gather entries from an n_dim array using an n_dim index array
Parameters¶
reference_array : np.ndarray Array that you want to gather the indices of. indices : np.ndarray Indices in the same shape as the array without the last dimension.
Returns¶
reduced_array : np.ndarray Shape is the reference array with the last dimension reduced to 1. This array is the initial reference array with the desired indices chosen out.
Source code in swarmrl/utils/utils.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
record_trajectory(particle_type, features, actions, log_probs, rewards)
¶
Record trajectory if required.
Parameters¶
particle_type : str Type of the particle saved. Important for the multi-species training. rewards : np.ndarray (n_timesteps, n_particles, 1) Rewards collected during the simulation to be used in training. log_probs : np.ndarray (n_timesteps, n_particles, 1) log_probs used for debugging. features : np.ndarray (n_timesteps, n_particles, n_dimensions) Features to store in the array. actions : np.ndarray (n_timesteps, n_particles, 1) A numpy array of actions
Returns¶
Dumps a hidden file to disc which is often removed after reading.
Source code in swarmrl/utils/utils.py
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 |
|
save_memory(memory)
¶
Records the training data if required.
Parameters:¶
memory : a dictionary containing the data from the method where it is called from. The data is specified in the method. It has to contain a key "file_name" which is the name of the file to be saved. To handle multiple particle types: one can specify the file name in the initialisation of the method.
Returns¶
Dumps a file to disc to evaluate training.
Source code in swarmrl/utils/utils.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
setup_sim_folder(outfolder_base, name, ask_if_exists=True, delete_existing=True)
¶
Create a simulation folder. Depending on flags, delete previous folders of the same name Parameters
outfolder_base Folder in which to create the new simulation folder name Name of the new folder ask_if_exists Flag to determine if the program stops to await user input on how to handle if the folder already exists (true, default) or to just delete it (false) delete_existing Whether to delete the existing folder
Returns¶
Source code in swarmrl/utils/utils.py
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 |
|
setup_swarmrl_logger(filename, loglevel_terminal=logging.INFO, loglevel_file=logging.DEBUG)
¶
Configure the swarmrl logger. This logger is used internally for logging, but you can also use it for your own log messages. Parameters
filename Name of the file where logs get written to loglevel_terminal Loglevel of the terminal output. The values correspond to https://docs.python.org/3/library/logging.html#logging-levels. You can pass an integer (or logging predefined values such as logging.INFO) or a string that corresponds to the loglevels of the link above. loglevel_file Loglevel of the file output. Returns
The logger
Source code in swarmrl/utils/utils.py
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 168 169 170 171 172 |
|
write_params(folder_name, sim_name, params, write_espresso_version=False)
¶
Writes parameters human-readable and to pickle
Parameters¶
folder_name Folder to save to sim_name Name of the simulation, used to create the two file names params : dict The parameters to be saved. Should have a string representation for txt output and be serializable by pickle write_espresso_version : bool If True, the espresso version will be printed to the txt file
Source code in swarmrl/utils/utils.py
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 |
|