Sweep module¶
t3co.sweep
¶
REPORT_COLS = {'selection': '', 'scenario_name': '', 'veh_year': '', 'veh_pt_type': '', 'pareto_front_number': '', 'run_time_[s]': '', 'algorithm': '', 'n_gen': '', 'fvals_over_gens': '', 'design_cyc_trace_miss_dist_frac': '', 'design_cyc_trace_miss_time_frac': '', 'design_cyc_trace_miss_speed_mps': '', 'design_cycle_EA_err': '', 'accel_EA_err': '', 'accel_loaded_EA_err': '', 'grade_6_EA_err': '', 'grade_125_EA_err': '', 'final_cda_pct': '', 'final_eng_eff_pct': '', 'final_ltwt_pct': '', 'final_max_motor_kw': '', 'final_battery_kwh': '', 'final_max_fc_kw': '', 'final_fs_kwh': '', 'minSpeed6PercentGradeIn5minAch': '', 'target_minSpeed6PercentGradeIn5min': '', 'delta_6PercentGrade': '', 'minSpeed1point25PercentGradeIn5minAch': '', 'target_minSpeed1point25PercentGradeIn5min': '', 'delta_1point25PercentGrade': '', 'max0to60secAtGVWRAch': '', 'target_max0to60secAtGVWR': '', 'delta_0to60sec': '', 'max0to30secAtGVWRAch': '', 'target_max0to30secAtGVWR': '', 'delta_0to30sec': ''}
module-attribute
¶
RES_FILE = report_kwargs['RES_FILE']
module-attribute
¶
algorithms = moo.ALGORITHMS
module-attribute
¶
args = parser.parse_args()
module-attribute
¶
config = rs.Config()
module-attribute
¶
end = time.time()
module-attribute
¶
exclude = args.exclude
module-attribute
¶
k = len(reports)
module-attribute
¶
kwargs = {'selections': selections, 'look_for': look_for, 'exclude': exclude, 'algo': algorithms, 'dir_mark': args.dir_mark, 'file_mark': args.file_mark.replace('.csv', ''), 'skip_save_veh': args.skip_save_veh, 'x_tol': float(args.x_tol), 'f_tol': float(args.f_tol), 'n_max_gen': int(args.n_max_gen), 'pop_size': int(args.pop_size), 'nth_gen': int(args.nth_gen), 'n_last': int(args.n_last), 'skip_all_opt': args.skip_all_opt if args.config is None else config.skip_all_opt, 'do_input_validation': args.skip_input_validation, 'range_overshoot_tol': float(args.range_overshoot_tol) if args.range_overshoot_tol is not None else None, 'write_tsv': write_tsv}
module-attribute
¶
look_for = args.look_for
module-attribute
¶
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog='SWEEP', description='The sweep.py module is the main script to run T3CO')
module-attribute
¶
report_i = run_optimize_analysis(sel, vdf=vdf, sdf=sdf, skip_all_opt=skip_all_opt, config=config, report_kwargs=report_kwargs, REPORT_COLS=REPORT_COLS)
module-attribute
¶
reports = []
module-attribute
¶
reports_df = pd.DataFrame(reports)
module-attribute
¶
resdir = Path(report_kwargs['resdir'])
module-attribute
¶
scen_df = dict(sdf.loc[sel, :])
module-attribute
¶
sel_list = [scenario_selection for scenario_selection in config.selections if str(scenario_selection).split('_')[0] == str(sel)]
module-attribute
¶
selections = -1
module-attribute
¶
selections_list = []
module-attribute
¶
skip_opt = scen_df.get('skip_opt', False)
module-attribute
¶
start = time.time()
module-attribute
¶
write_tsv = args.write_tsv
module-attribute
¶
check_input_files(df: pd.DataFrame, filetype: str, filepath: str) -> None
¶
This function contains assert statements that make sure input vehicle and scenario dataframes do not contain numm rows
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
vehicle or scenario dataframe |
required |
filetype
|
str
|
'vehicle' or 'scenario' |
required |
filepath
|
str
|
filepath of the vehicle or scenario input files |
required |
Source code in t3co/sweep.py
deug_traces(vehicle: fastsim.vehicle.Vehicle, cycles: List[fastsim.cycle.Cycle], scenario: run_scenario.Scenario) -> None
¶
This function gets a diagnostic trace of get_mpgge
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vehicle
|
fastsim.vehicle.Vehicle
|
FASTSim Vehicle object |
required |
cycles
|
List[fastsim.cycle.Cycle]
|
List of FASTSim drivecycle objects |
required |
scenario
|
run_scenario.Scenario
|
Scenario object |
required |
Source code in t3co/sweep.py
get_knobs_bounds_curves(selection: int, vpttype: str, sdf: pd.DataFrame, lw_imp_curves: pd.DataFrame, aero_drag_imp_curves: pd.DataFrame, eng_eff_curves: pd.DataFrame) -> Tuple[dict, dict]
¶
This function fetches the knobs and constraints for running the optimization for a given selection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection
|
int
|
selection number |
required |
vpttype
|
str
|
vehicle powertrain type = veh_pt_type |
required |
sdf
|
pd.DataFrame
|
scenario dataframe |
required |
lw_imp_curves
|
pd.DataFrame
|
light weighting curve dataframe |
required |
aero_drag_imp_curves
|
pd.DataFrame
|
aero drag curve dataframe |
required |
eng_eff_curves
|
pd.DataFrame
|
engine efficiency curve dataframe |
required |
Returns:
Name | Type | Description |
---|---|---|
knobs_bounds |
dict
|
dict of knobs and bounds |
curves |
dict
|
dict of lw, aero, and engine efficiency curve parameters |
Source code in t3co/sweep.py
Python | |
---|---|
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 |
|
get_objectives_constraints(selection: int, sdf: pd.DataFrame, verbose: bool = True) -> Tuple[list, list]
¶
This function appends to list of necessary variables based on the constraints and objectives selected
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection
|
int
|
selection number |
required |
sdf
|
DataFrame
|
scenario dataframe |
required |
verbose
|
bool
|
if selected, function will print objectives and constraints. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
objectives |
list
|
list of selected objective variables |
constraints |
list
|
list of selected constraint variables |
Source code in t3co/sweep.py
optimize(sel: float, sdf: pd.DataFrame, vdf: pd.DataFrame, algo: str, report_kwargs: dict, REPORT_COLS: dict, skip_opt: bool, config: run_scenario.Config, write_tsv: bool = False) -> dict
¶
This function runs the optimization for a given selection if skip_opt = False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sel
|
float
|
Selection number |
required |
sdf
|
pd.DataFrame
|
Dataframe of input scenario file |
required |
vdf
|
pd.DataFrame
|
Dataframe of input vehicle file |
required |
algo
|
str
|
Multiobjective optimization Algorithm name |
required |
report_kwargs
|
dict
|
arguments related to running T3CO |
required |
REPORT_COLS
|
dict
|
Results columns dictionary for sorting the T3CO results |
required |
skip_opt
|
bool
|
skip optimization. If true, then optimizer is not run. |
required |
config
|
run_scenario.Config
|
Config object |
required |
write_tsv
|
bool
|
if selected, intermediary dataframes are saved as tsv files.. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
report_i |
dict
|
Dictionary of T3CO results for given selection |
Source code in t3co/sweep.py
Python | |
---|---|
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 |
|
run_moo(sel: int, sdf: pd.DataFrame, optpt: str, algo: str, skip_opt: bool, pop_size: float, n_max_gen: int, n_last: int, nth_gen: int, x_tol: float, verbose: bool, f_tol: float, resdir: str, lw_imp_curves_df: pd.DataFrame, aero_drag_imp_curves_df: pd.DataFrame, eng_eff_imp_curves_df: pd.DataFrame, config: run_scenario.Scenario, **kwargs) -> Tuple[pymoo.core.result.Result, moo.T3COProblem, bool]
¶
This function calls get_objectives_constraints and get_knobs_bounds_curves, and then calls run_optimization to perform the multiobjective optimization
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sel
|
int
|
selection number |
required |
sdf
|
DataFrame
|
Scenario dataframe |
required |
optpt
|
str
|
FASTSim vehicle powertrain type |
required |
algo
|
str
|
algorithm name |
required |
skip_opt
|
bool
|
skip optimization boolean |
required |
pop_size
|
int
|
population size for optimization |
required |
n_max_gen
|
int
|
maximum number of generations for optimization |
required |
n_last
|
int
|
number of generations to look back for termination |
required |
nth_gen
|
int
|
number of generations to evaluate if convergence occurs |
required |
x_tol
|
float
|
tolerance in parameter space |
required |
verbose
|
book
|
if selected, function prints the optimization process |
required |
f_tol
|
float
|
tolerance in objective space |
required |
resdir
|
str
|
results directory |
required |
lw_imp_curves_df
|
DataFrame
|
light weighting curves dataframe |
required |
aero_drag_imp_curves_df
|
DataFrame
|
aero drag curves dataframe |
required |
eng_eff_imp_curves_df
|
DataFrame
|
engine efficiency curve dataframe |
required |
config
|
Config
|
Config class object |
required |
Returns:
Name | Type | Description |
---|---|---|
moo_results |
pymoo.core.result.Result
|
optimization results object |
moo_problem |
T3COProblem
|
minimization problem that calculates TCO |
moo_code |
bool
|
Error message |
Source code in t3co/sweep.py
Python | |
---|---|
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 |
|
run_optimize_analysis(sel: str | int, vdf: pd.DataFrame, sdf: pd.DataFrame, skip_all_opt: bool, config: run_scenario.Config, report_kwargs: dict, REPORT_COLS: dict) -> dict
¶
This function runs the optimization function based on skip_all_opt input to return the report_i dictionary with T3CO results for each selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sel
|
str | int
|
selection number |
required |
vdf
|
pd.DataFrame
|
Dataframe of input vehicle file |
required |
sdf
|
pd.DataFrame
|
Dataframe of input scenario file |
required |
skip_all_opt
|
bool
|
Skip all optimization. If true, then the optimizer is not run for any scenario |
required |
config
|
run_scenario.Config
|
Config object |
required |
report_kwargs
|
dict
|
Dictionary of args required for running T3CO |
required |
REPORT_COLS
|
dict
|
Dictionary of reporting columns from T3CO |
required |
Returns:
Name | Type | Description |
---|---|---|
report_i |
dict
|
Dictionary of T3CO results for given selection |
Source code in t3co/sweep.py
run_vehicle_scenarios(config: run_scenario.Config, REPORT_COLS: dict, **kwargs) -> Tuple[List[int | str], pd.DataFrame, pd.DataFrame, bool, dict, dict]
¶
This function reads the input files, validates inputs, compiles the selections, and returns a clean set of inputs that are needed for the current analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
Config object containing analysis attributes and scenario attribute overrides |
required |
REPORT_COLS
|
dict
|
Dictionary of reporting columns from T3CO |
required |
Raises:
Type | Description |
---|---|
Exception
|
input validation error |
Exception
|
optimization error |
Returns:
Type | Description |
---|---|
Tuple[List[int | str], pd.DataFrame, pd.DataFrame, bool, dict, dict]
|
selections, vdf, sdf, skip_all_opt, report_kwargs, REPORT_COLS (Tuple[List[int|str], pd.DataFrame, pd.DataFrame, bool, dict, dict]): Selections list, vehicle dataframe, scenario dataframe, skip all optimization, report arguments, and report columns |
Source code in t3co/sweep.py
Python | |
---|---|
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 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
|
save_tco_files(tco_files: dict, resdir: str, scenario_name: str, sel: str, ts: str) -> None
¶
This function saves the intermediary files as tsv
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tco_files
|
dict
|
Contains all TCO calculation dataframes |
required |
resdir
|
str
|
result directory strong |
required |
scenario_name
|
str
|
scenario name |
required |
sel
|
str
|
selection(s) |
required |
ts
|
str
|
timestring |
required |
Source code in t3co/sweep.py
skip_scenario(sel, selections, scenario_name, report_kwargs, verbose=False) -> bool
¶
This function checks if given selection is present in exclude or look_for selections
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sel
|
float
|
description |
required |
scenario_name
|
str
|
scenario name |
required |
verbose
|
bool
|
if selected, prints out scenarios that are skipped. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
if not present, returns True; Else False |