generate_scan
This class is used to generate a study (along with the corresponding tree) from a parameter file, and potentially a set of template files.
This class makes use of "eval", which is known to be a security risk. ast.literal_eval can't be used here because variables from a specified namespace are being passed to the eval function. The use of eval is justified here because the input is controlled by the user only through the configuration file. If the user wants to write an unsafe expression, it's their responsibility.
GenerateScan
A class to generate a study (along with the corresponding tree) from a parameter file, and potentially a set of template files.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
dict
|
The configuration dictionary. |
ryaml |
YAML
|
The YAML parser. |
dic_common_parameters |
dict
|
Dictionary of common parameters across generations. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the generation scan with a configuration file or dictionary. |
render |
Renders the study file using a template. |
write |
Writes the study file to disk. |
generate_render_write |
Generates, renders, and writes the study file. |
get_dic_parametric_scans |
Retrieves dictionaries of parametric scan values. |
parse_parameter_space |
Parses the parameter space for a given parameter. |
browse_and_collect_parameter_space |
Browses and collects the parameter space for a given generation. |
postprocess_parameter_lists |
Postprocesses the parameter lists. |
create_scans |
Creates study files for parametric scans. |
complete_tree |
Completes the tree structure of the study dictionary. |
write_tree |
Writes the study tree structure to a YAML file. |
create_study_for_current_gen |
Creates study files for the current generation. |
create_study |
Creates study files for the entire study. |
eval_conditions |
Evaluates the conditions to filter out some parameter values. |
filter_for_concomitant_parameters |
Filters the conditions for concomitant parameters. |
Source code in study_da/generate/generate_scan.py
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 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 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
__init__(path_config=None, dic_scan=None)
Initialize the generation scan with a configuration file or dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_config
|
Optional[str]
|
Path to the configuration file for the scan. Default is None. |
None
|
dic_scan
|
Optional[dict[str, Any]]
|
Dictionary containing the scan configuration. Default is None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither or both of |
Source code in study_da/generate/generate_scan.py
browse_and_collect_parameter_space(generation)
Browses and collects the parameter space for a given generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation
|
str
|
The generation name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], dict[str, Any], dict[str, Any], list[list[str]], list[str]]
|
tuple[dict[str, Any], dict[str, Any], dict[str, Any], list[list[str]]]: The updated dictionaries of parameter lists. |
Source code in study_da/generate/generate_scan.py
complete_tree(dictionary_tree, l_study_path_next_gen, gen)
Completes the tree structure of the study dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary_tree
|
dict
|
The dictionary representing the study tree structure. |
required |
l_study_path_next_gen
|
list[str]
|
The list of study paths for the next gen. |
required |
gen
|
str
|
The generation name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The updated dictionary representing the study tree structure. |
Source code in study_da/generate/generate_scan.py
create_scans(generation, generation_path, template_path, depth_gen, dic_parameter_lists=None, dic_parameter_lists_for_naming=None, add_prefix_to_folder_names=False)
Creates study files for parametric scans. If a dictionary of parameter lists is provided, the scan will be done on the parameter lists (no cartesian product). Otherwise, the scan will be done on the cartesian product of the parameters defined in the scan configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation
|
str
|
The generation name. |
required |
generation_path
|
str
|
The (relative) path to the generation folder. |
required |
template_path
|
str
|
The path to the template folder. |
required |
depth_gen
|
int
|
The depth of the generation in the tree. |
required |
dic_parameter_lists
|
Optional[dict[str, Any]]
|
The dictionary of parameter lists. Defaults to None. |
None
|
dic_parameter_lists_for_naming
|
Optional[dict[str, Any]]
|
The dictionary of parameter lists for naming. Defaults to None. |
None
|
add_prefix_to_folder_names
|
bool
|
Whether to add a prefix to the folder names. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
tuple[list[str], list[str]]: The list of study file strings and the list of study paths. |
Source code in study_da/generate/generate_scan.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
create_study(tree_file=True, force_overwrite=False, dic_parameter_all_gen=None, dic_parameter_all_gen_naming=None, add_prefix_to_folder_names=False)
Creates study files for the entire study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree_file
|
bool
|
Whether to write the study tree structure to a YAML file. Defaults to True. |
True
|
force_overwrite
|
bool
|
Whether to overwrite existing study files. Defaults to False. |
False
|
dic_parameter_all_gen
|
Optional[dict[str, dict[str, Any]]]
|
The dictionary of parameter lists for all generations. Defaults to None. |
None
|
dic_parameter_all_gen_naming
|
Optional[dict[str, dict[str, Any]]]
|
The dictionary of parameter lists for all generations for naming. Defaults to None. |
None
|
add_prefix_to_folder_names
|
bool
|
Whether to add a prefix to the folder names. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
list[str]: The list of study file strings. |
Source code in study_da/generate/generate_scan.py
create_study_for_current_gen(generation, generation_path, depth_gen, dic_parameter_lists=None, dic_parameter_lists_for_naming=None, add_prefix_to_folder_names=False)
Creates study files for the current generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation
|
str
|
The name of the current generation. |
required |
directory_path
|
str
|
The (relative) path to the directory folder for the current generation. |
required |
depth_gen
|
int
|
The depth of the generation in the tree. |
required |
dic_parameter_lists
|
Optional[dict[str, Any]]
|
The dictionary of parameter lists. Defaults to None. |
None
|
dic_parameter_lists_for_naming
|
Optional[dict[str, Any]]
|
The dictionary of parameter lists for naming. Defaults to None. |
None
|
add_prefix_to_folder_names
|
bool
|
Whether to add a prefix to the folder names. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
tuple[list[str], list[str]]: The list of study file strings and the list of study paths. |
Source code in study_da/generate/generate_scan.py
eval_conditions(l_condition, dic_parameter_lists)
staticmethod
Evaluates the conditions to filter out some parameter values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l_condition
|
list[str]
|
The list of conditions. |
required |
dic_parameter_lists
|
dict[str
|
Any]): The dictionary of parameter lists. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The array of conditions. |
Source code in study_da/generate/generate_scan.py
filter_for_concomitant_parameters(array_conditions, ll_concomitant_parameters, dic_dimension_indices)
staticmethod
Filters the conditions for concomitant parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_conditions
|
ndarray
|
The array of conditions. |
required |
ll_concomitant_parameters
|
list[list[str]]
|
The list of concomitant parameters. |
required |
dic_dimension_indices
|
dict[str, int]
|
The dictionary of dimension indices. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The filtered array of conditions. |
Source code in study_da/generate/generate_scan.py
generate_render_write(gen_name, job_directory_path, template_path, depth_gen, dic_mutated_parameters={})
Generates, renders, and writes the study file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gen_name
|
str
|
The name of the generation. |
required |
study_path
|
str
|
The path to the job folder. |
required |
template_path
|
str
|
The path to the template folder. |
required |
depth_gen
|
int
|
The depth of the generation in the tree. |
required |
dic_mutated_parameters
|
dict[str, Any]
|
The dictionary of mutated parameters. Defaults to {}. |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
tuple[str, list[str]]: The study file string and the list of study paths. |
Source code in study_da/generate/generate_scan.py
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 | |
get_dic_parametric_scans(generation)
Retrieves dictionaries of parametric scan values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation
|
str
|
The generation name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], dict[str, Any], ndarray | None]
|
tuple[dict[str, Any], dict[str, Any], np.ndarray|None]: The dictionaries of parametric scan values, another dictionnary with better naming for the tree creation, and an array of conditions to filter out some parameter values. |
Source code in study_da/generate/generate_scan.py
parse_parameter_space(parameter, dic_curr_parameter, dic_parameter_lists, dic_parameter_lists_for_naming)
Parses the parameter space for a given parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
str
|
The parameter name. |
required |
dic_curr_parameter
|
dict[str, Any]
|
The dictionary of current parameter values. |
required |
dic_parameter_lists
|
dict[str, Any]
|
The dictionary of parameter lists. |
required |
dic_parameter_lists_for_naming
|
dict[str, Any]
|
The dictionary of parameter lists for naming. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], dict[str, Any]]
|
tuple[dict[str, Any], dict[str, Any]]: The updated dictionaries of parameter lists. |
Source code in study_da/generate/generate_scan.py
postprocess_parameter_lists(dic_parameter_lists, dic_parameter_lists_for_naming, dic_subvariables)
Post-processes parameter lists by ensuring values are not numpy types and handling nested parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dic_parameter_lists
|
dict[str, Any]
|
Dictionary containing parameter lists. |
required |
dic_parameter_lists_for_naming
|
dict[str, Any]
|
Dictionary containing parameter lists for naming. |
required |
dic_subvariables
|
dict[str, Any]
|
Dictionary containing subvariables for nested parameters. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], dict[str, Any]]
|
tuple[dict[str, Any], dict[str, Any]]: Updated dictionaries of parameter lists and parameter lists for naming. |
Source code in study_da/generate/generate_scan.py
render(str_parameters, template_path, path_main_configuration, study_path=None, str_dependencies=None)
Renders the study file using a template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str_parameters
|
str
|
The string representation of parameters to declare/mutate. |
required |
template_path
|
str
|
The path to the template file. |
required |
path_main_configuration
|
str
|
The path to the main configuration file. |
required |
study_path
|
str
|
The path to the root of the study. Defaults to None. |
None
|
dependencies
|
dict[str, str]
|
The dictionary of dependencies. Defaults to {}. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The rendered study file. |
Source code in study_da/generate/generate_scan.py
write(study_str, file_path, format_with_black=True)
Writes the study file to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_str
|
str
|
The study file string. |
required |
file_path
|
str
|
The path to write the study file. |
required |
format_with_black
|
bool
|
Whether to format the output file with black. Defaults to True. |
True
|
Source code in study_da/generate/generate_scan.py
write_tree(dictionary_tree)
Writes the study tree structure to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary_tree
|
dict
|
The dictionary representing the study tree structure. |
required |