Sweep Sub-Module
t3co.cli.sweep
Command-line entry point that runs a T3CO analysis.
python -m t3co.cli.sweep --analysis-id=<id> loads an analysis from the
Config file, computes a Ledger for every selected Vehicle-Scenario pair
(optimizing the powertrain first when the analysis asks for it), and writes
the results CSV, plus optional charts and a grouped summary.
apply_cli_overrides(config, args, argv=None)
Apply command-line settings that were explicitly given onto a Config.
Only flags present in argv override the Config, in either the
--flag value or the --flag=value form, so values loaded from the
Config file are kept unless the user passed the matching flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Config to update. |
required |
args
|
Namespace
|
Parsed command-line arguments. |
required |
argv
|
list[str] | None
|
Raw command-line tokens, used to tell which flags were given. Defaults to None (no overrides). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Config |
Config
|
The same Config, updated in place. |
Source code in src/t3co/cli/sweep.py
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 | |
load_vehicle_scenario_energy(selection, config, vehicle=None, scenario=None, energy=None)
Loads the vehicle, scenario, and energy models based on the selection and config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selection
|
Union[int, str]
|
The selection index or string. |
required |
config
|
Config
|
The configuration instance. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Vehicle, Scenario, Energy]
|
Tuple[Vehicle, Scenario, Energy]: The vehicle, scenario, and energy models. |
Source code in src/t3co/cli/sweep.py
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 | |
generate_ledger(selection, config)
Generates the ledger for the given selection and config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selection
|
int
|
The selection index. |
required |
config
|
Config
|
The configuration instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
The ledger as a dictionary. |
Source code in src/t3co/cli/sweep.py
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 | |
run_optimization(vehicle, scenario, config)
Optimize the powertrain of one Vehicle-Scenario pair.
Each generation's designs are evaluated in a pool of
config.n_processes processes when config.parallel is set and this
process may start one, and serially otherwise, for example inside a
--run-multi worker. Both paths produce identical results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vehicle
|
Vehicle
|
Vehicle whose powertrain is sized. |
required |
scenario
|
Scenario
|
Scenario supplying knob bounds and constraints. |
required |
config
|
Config
|
Analysis configuration, including the algorithm and convergence settings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
|
Source code in src/t3co/cli/sweep.py
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 | |
create_results_filepath(config)
Creates the results file path based on the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
The configuration instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the results file. |
Source code in src/t3co/cli/sweep.py
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 | |
append_results_to_csv(reports_list, output_path, write_header=False)
Appends results to a CSV file incrementally to avoid memory issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reports_list
|
List[Dict]
|
The list of reports to append. |
required |
output_path
|
Union[str, Path]
|
The output path for the CSV file. |
required |
write_header
|
bool
|
Whether to write the header. Defaults to False. |
False
|
Source code in src/t3co/cli/sweep.py
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 | |
sort_csv_file(input_path, output_path=None, sort_by='selection', chunksize=2000)
Sorts a CSV file by a column using external merge sort to handle large files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Union[str, Path]
|
The input CSV file path. |
required |
output_path
|
Union[str, Path]
|
The output path. If None, overwrites input. |
None
|
sort_by
|
str
|
Column name to sort by. Defaults to "selection". |
'selection'
|
chunksize
|
int
|
Number of rows per chunk. Defaults to 2000. |
2000
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The output file path. |
Source code in src/t3co/cli/sweep.py
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 | |
export_results_to_csv(reports_list, config, output_path=None, return_filepath=True, return_df=False, sort_values=False)
Exports the results to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reports_list
|
List[Dict]
|
The list of reports. |
required |
config
|
Config
|
The configuration instance. |
required |
output_path
|
Union[str, Path]
|
The output path for the CSV file. Defaults to None. |
None
|
return_filepath
|
bool
|
Whether to return the file path. Defaults to True. |
True
|
return_df
|
bool
|
Whether to return the DataFrame. Defaults to False. |
False
|
sort_values
|
bool
|
Whether to sort the values by selection. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[Path, None], Union[DataFrame, None]]
|
Tuple[Union[Path, None], Union[pd.DataFrame, None]]: The output path and DataFrame if specified. |
Source code in src/t3co/cli/sweep.py
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 | |
summarize_run_results(config, results_path)
Writes a grouped summary of a sweep's results file when config.summary_group_by is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
The configuration instance. |
required |
results_path
|
Union[str, Path]
|
The results CSV written by the sweep. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
Path | None: Path of the summary CSV, or None if no summary was requested. |
Source code in src/t3co/cli/sweep.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
save_default_plots(results_csv, backend=DEFAULT_PLOT_BACKEND)
Generates and saves a default set of TCO charts from a results CSV.
Writes figures next to the results file: a TCO cost breakdown, a histogram of the discounted TCO, and - when a fuel-type grouping is available - a violin plot. With the Plotly backend all charts are combined into a single self-contained HTML report; with matplotlib each chart is a separate PNG.
The plotting dependencies are optional; if they are missing (or charting fails) the run is unaffected and a note is printed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results_csv
|
Union[str, Path]
|
Path to the T3CO results CSV. |
required |
backend
|
str
|
"plotly" (interactive HTML) or "matplotlib" (static PNG). |
DEFAULT_PLOT_BACKEND
|
Returns:
| Type | Description |
|---|---|
List[Path]
|
List[Path]: Paths of the saved figure files (empty if plotting was skipped). |
Source code in src/t3co/cli/sweep.py
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 | |
run_t3co(config, save_results=True, plot_backend=None)
Runs the T3CO analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
The configuration instance. |
required |
save_results
|
bool
|
Whether to save the results. Defaults to True. |
True
|
plot_backend
|
str
|
If set ("plotly" or "matplotlib"), generates and saves default TCO charts next to the results CSV. Defaults to None. |
None
|
Source code in src/t3co/cli/sweep.py
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 | |