Multiverse Analysis
This class orchestrates a multiverse analysis.
Attributes:
Name | Type | Description |
---|---|---|
dimensions |
A dictionary containing the dimensions of the multiverse. |
|
notebook |
The Path to the notebook to run. |
|
config_file |
A Path to a JSON file containing the dimensions. |
|
output_dir |
The directory to store the output in. |
|
run_no |
The number of the current run. |
|
new_run |
Whether this is a new run or not. |
|
seed |
The seed to use for the analysis. |
|
stop_on_error |
Whether to stop the analysis if an error occurs. |
|
cell_timeout |
A timeout (in seconds) for each cell in the notebook. |
Source code in multiversum/multiverse.py
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 168 169 170 171 172 173 174 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 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 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 295 296 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 333 334 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 378 379 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 427 428 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 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
__init__(dimensions=None, notebook=Path('./universe.ipynb'), config_file=None, output_dir=Path('./output'), run_no=None, new_run=True, seed=DEFAULT_SEED, stop_on_error=True, cell_timeout=None)
Initializes a new MultiverseAnalysis instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dimensions
|
Optional[Dict]
|
A dictionary containing the dimensions of the multiverse. Each dimension corresponds to a decision. Alternatively a Path to a JSON file containing the dimensions. |
None
|
notebook
|
Path
|
The Path to the notebook to run. |
Path('./universe.ipynb')
|
config_file
|
Optional[Path]
|
A Path to a JSON file containing the dimensions. |
None
|
output_dir
|
Path
|
The directory to store the output in. |
Path('./output')
|
run_no
|
Optional[int]
|
The number of the current run. Defaults to an automatically incrementing integer number if new_run is True or the last run if new_run is False. |
None
|
new_run
|
bool
|
Whether this is a new run or not. Defaults to True. |
True
|
seed
|
Optional[int]
|
The seed to use for the analysis. |
DEFAULT_SEED
|
stop_on_error
|
bool
|
Whether to stop the analysis if an error occurs. |
True
|
cell_timeout
|
Optional[int]
|
A timeout (in seconds) for each cell in the notebook. |
None
|
Source code in multiversum/multiverse.py
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
aggregate_data(include_errors=True, save=True)
Aggregate the data from all universes into a single DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_errors
|
bool
|
Whether to include error information. |
True
|
save
|
bool
|
Whether to save the aggregated data to a file. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
A pandas DataFrame containing the aggregated data from all universes. |
Source code in multiversum/multiverse.py
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 269 270 271 |
|
check_missing_universes()
Check if any universes from the multiverse have not yet been visited.
Returns:
Type | Description |
---|---|
MissingUniverseInfo
|
A dictionary containing the missing universe ids, additional universe ids (i.e. not in the current multiverse_grid) and the dictionaries for the missing universes. |
Source code in multiversum/multiverse.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
examine_multiverse(multiverse_grid=None, n_jobs=-2)
Run the analysis for all universes in the multiverse.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
multiverse_grid
|
List[Dict[str, Any]]
|
A list of dictionaries containing the settings for different universes. |
None
|
n_jobs
|
int
|
The number of jobs to run in parallel. Defaults to -2 (all CPUs but one). |
-2
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in multiversum/multiverse.py
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 333 334 335 336 337 |
|
execute_notebook_via_api(input_path, output_path, parameters)
Executes a notebook via the papermill python API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path
|
str
|
The path to the input notebook. |
required |
output_path
|
str
|
The path to the output notebook. |
required |
parameters
|
Dict[str, str]
|
A dictionary containing the parameters for the notebook. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in multiversum/multiverse.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
execute_notebook_via_cli(input_path, output_path, parameters)
Executes a notebook via the papermill command line interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path
|
str
|
The path to the input notebook. |
required |
output_path
|
str
|
The path to the output notebook. |
required |
parameters
|
Dict[str, str]
|
A dictionary containing the parameters for the notebook. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in multiversum/multiverse.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
generate_grid(save=True)
Generate the multiverse grid from the stored dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save
|
bool
|
Whether to save the multiverse grid to a JSON file. |
True
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
A list of dicts containing the settings for different universes. |
Source code in multiversum/multiverse.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
get_run_dir(sub_directory=None)
Get the directory for the current run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sub_directory
|
Optional[str]
|
An optional sub-directory to append to the run directory. |
None
|
Returns:
Type | Description |
---|---|
Path
|
A Path object for the current run directory. |
Source code in multiversum/multiverse.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
read_counter(increment)
Read the counter from the output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
increment
|
bool
|
Whether to increment the counter after reading. |
required |
Returns:
Type | Description |
---|---|
int
|
The current value of the counter. |
Source code in multiversum/multiverse.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
save_error(universe_id, dimensions, error)
Save an error to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
universe_id
|
str
|
The ID of the universe that caused the error. |
required |
error
|
Exception
|
The exception that was raised. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in multiversum/multiverse.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
visit_universe(universe_dimensions)
Run the complete analysis for a single universe.
Output from the analysis will be saved to a file in the run's output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
universe_dimensions
|
Dict[str, str]
|
A dictionary containing the parameters for the universe. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in multiversum/multiverse.py
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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|