estimation
Time estimation package for Snakemake workflow progress.
This package provides modular components for estimating remaining workflow time: - TimeEstimator: Main coordinator class - RuleMatchingEngine: Fuzzy rule matching by name/code hash - HistoricalDataLoader: Load timing data from metadata/events - PendingRuleInferrer: Infer pending job distribution
Classes¶
HistoricalDataLoader ¶
Loads timing data from metadata and events files.
Provides methods to load historical execution data from: - .snakemake/metadata/ directory (from previous Snakemake runs) - .snakesee_events.jsonl file (from snakesee monitoring)
Source code in snakesee/estimation/data_loader.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 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 | |
Functions¶
__init__ ¶
__init__(registry: RuleRegistry, use_wildcard_conditioning: bool = False) -> None
Initialize the loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
RuleRegistry
|
RuleRegistry to load data into. |
required |
use_wildcard_conditioning
|
bool
|
Whether to record wildcard-specific stats. |
False
|
Source code in snakesee/estimation/data_loader.py
load_from_backend ¶
load_from_backend(backend: PersistenceBackend, progress_callback: ProgressCallback | None = None) -> None
Load historical execution times from a persistence backend.
Works with both filesystem and SQLite backends via the PersistenceBackend protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
PersistenceBackend
|
Persistence backend to read from. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress. |
None
|
Source code in snakesee/estimation/data_loader.py
load_from_events ¶
Load historical execution times from a snakesee events file.
Streams the events file line by line for memory efficiency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events_file
|
Path
|
Path to .snakesee_events.jsonl file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if any wildcard data was found. |
Source code in snakesee/estimation/data_loader.py
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 | |
load_from_metadata ¶
Load historical execution times from .snakemake/metadata/.
Uses a single-pass parser for efficiency - reads each metadata file only once to collect timing stats, code hashes, and wildcard stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_dir
|
Path
|
Path to .snakemake/metadata/ directory. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress. |
None
|
Source code in snakesee/estimation/data_loader.py
PendingRuleInferrer ¶
Infers the distribution of pending jobs by rule.
When we know the total pending count but not the breakdown by rule, this class infers the distribution based on: 1. Expected job counts (from Snakemake's Job stats table) if available 2. Proportional inference from completed job distribution otherwise
Source code in snakesee/estimation/pending_inferrer.py
Functions¶
infer ¶
infer(completed_by_rule: dict[str, int], pending_count: int, expected_job_counts: dict[str, int] | None = None, current_rules: set[str] | None = None, running_by_rule: dict[str, int] | None = None) -> dict[str, int]
Infer the distribution of pending jobs by rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completed_by_rule
|
dict[str, int]
|
Count of completed jobs per rule. |
required |
pending_count
|
int
|
Total number of pending jobs. |
required |
expected_job_counts
|
dict[str, int] | None
|
Expected counts from Job stats table (most accurate). |
None
|
current_rules
|
set[str] | None
|
Set of rules in current workflow (filters deleted rules). |
None
|
running_by_rule
|
dict[str, int] | None
|
Count of running jobs per rule. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Estimated count of pending jobs per rule. |
Source code in snakesee/estimation/pending_inferrer.py
RuleMatchingEngine ¶
Matches rules by name similarity and code hash.
Used to find timing data for renamed rules or similar rules when exact matches aren't available.
Source code in snakesee/estimation/rule_matcher.py
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 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 | |
Functions¶
__init__ ¶
Initialize the matcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_distance
|
int
|
Maximum Levenshtein distance for fuzzy matches. |
3
|
find_best_match ¶
find_best_match(rule: str, code_hash_to_rules: dict[str, set[str]], rule_stats: dict[str, RuleTimingStats], max_distance: int | None = None) -> tuple[str, RuleTimingStats] | None
Find the best matching rule using code hash then fuzzy matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to match. |
required |
code_hash_to_rules
|
dict[str, set[str]]
|
Mapping of code hashes to rule sets. |
required |
rule_stats
|
dict[str, RuleTimingStats]
|
Available rule statistics. |
required |
max_distance
|
int | None
|
Maximum Levenshtein distance. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, RuleTimingStats] | None
|
Tuple of (matched_rule, stats), or None if no match. |
Source code in snakesee/estimation/rule_matcher.py
find_by_code_hash ¶
find_by_code_hash(rule: str, code_hash_to_rules: dict[str, set[str]], known_rules: set[str]) -> str | None
Find a rule with matching code hash.
When multiple rules share the same code hash and are in known_rules, returns the lexicographically smallest rule name for deterministic behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to look up. |
required |
code_hash_to_rules
|
dict[str, set[str]]
|
Mapping of code hashes to rule sets. |
required |
known_rules
|
set[str]
|
Set of rules with available stats. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Name of matching rule (lexicographically smallest if multiple), |
str | None
|
or None if not found. |
Source code in snakesee/estimation/rule_matcher.py
find_similar ¶
find_similar(rule: str, known_rules: set[str], max_distance: int | None = None) -> tuple[str, int] | None
Find similar rule by Levenshtein distance.
When multiple rules have the same distance, returns the lexicographically smallest one for deterministic behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to match. |
required |
known_rules
|
set[str]
|
Set of rules to search. |
required |
max_distance
|
int | None
|
Maximum distance (uses instance default if None). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, int] | None
|
Tuple of (matched_rule, distance), or None if no match. |
Source code in snakesee/estimation/rule_matcher.py
TimeEstimator ¶
Estimates remaining workflow time from historical data.
Uses per-rule timing statistics from previous workflow runs to estimate how long the remaining jobs will take. Falls back to simple linear estimation when historical data is unavailable.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_stats |
dict[str, RuleTimingStats]
|
Dictionary mapping rule names to their timing statistics. |
thread_stats |
dict[str, ThreadTimingStats]
|
Dictionary mapping rule names to thread-conditioned timing stats. |
wildcard_stats |
dict[str, dict[str, WildcardTimingStats]]
|
Nested dict of wildcard-conditioned timing stats. |
use_wildcard_conditioning |
Whether to use wildcard-specific estimates. |
|
config |
Centralized estimation configuration. |
Source code in snakesee/estimation/estimator.py
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 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 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 | |
Attributes¶
estimated_cores
property
¶
Inferred core count used to convert thread-seconds to wall-clock time.
Priority:
1. Provided cores: N parsed from the Snakemake log (definitive).
2. Peak observed sum of running-job threads (approximation of -j).
3. Fallback to 1.0 when no data is available.
Returns:
| Type | Description |
|---|---|
float
|
Estimated core count (>= 1.0). |
rule_stats
property
writable
¶
rule_stats: dict[str, RuleTimingStats]
Get rule stats dict from the registry.
Returns a dict view for backward compatibility with code that reads rule_stats.
thread_stats
property
¶
thread_stats: dict[str, ThreadTimingStats]
Get thread stats dict from the registry.
wildcard_stats
property
¶
wildcard_stats: dict[str, dict[str, WildcardTimingStats]]
Get wildcard stats dict from the registry.
Functions¶
__init__ ¶
__init__(use_wildcard_conditioning: bool = False, half_life_days: float | None = None, weighting_strategy: WeightingStrategy | None = None, half_life_logs: int | None = None, config: EstimationConfig | None = None, rule_registry: RuleRegistry | None = None) -> None
Initialize the estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_wildcard_conditioning
|
bool
|
Whether to use wildcard-specific timing. |
False
|
half_life_days
|
float | None
|
Half-life in days for time-based weighting. After this many days, a run's weight is halved. Only used when weighting_strategy="time". |
None
|
weighting_strategy
|
WeightingStrategy | None
|
Strategy for weighting historical data. "time" - decay based on wall-clock time (good for stable pipelines) "index" - decay based on run count (good for active development) |
None
|
half_life_logs
|
int | None
|
Half-life in log count for index-based weighting. After this many runs, a run's weight is halved. Only used when weighting_strategy="index". |
None
|
config
|
EstimationConfig | None
|
Centralized estimation configuration. If not provided, uses DEFAULT_CONFIG with any explicit parameters overriding it. |
None
|
rule_registry
|
RuleRegistry | None
|
RuleRegistry for centralized statistics. If not provided, creates an internal registry. |
None
|
Source code in snakesee/estimation/estimator.py
estimate_remaining ¶
estimate_remaining(progress: WorkflowProgress) -> TimeEstimate
Estimate remaining time for a workflow.
Uses one of several estimation strategies depending on available data: 1. "weighted" - Uses per-rule historical timing with exponential weighting 2. "simple" - Falls back to average time per completed step
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress
|
WorkflowProgress
|
Current workflow progress state. |
required |
Returns:
| Type | Description |
|---|---|
TimeEstimate
|
TimeEstimate with expected time, confidence bounds, and method. |
Source code in snakesee/estimation/estimator.py
get_estimate_for_job ¶
get_estimate_for_job(rule: str, wildcards: dict[str, str] | None = None, input_size: int | None = None, threads: int | None = None) -> tuple[float, float]
Get expected duration and variance for a specific job.
Uses a cascade of estimation strategies in priority order: 1. Full combination stats (wildcards + threads together) 2. Thread-specific stats 3. Wildcard-specific stats (if enabled) 4. Rule-level stats (with optional size scaling) 5. Fuzzy matching for renamed/similar rules 6. Global mean fallback
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
The rule name. |
required |
wildcards
|
dict[str, str] | None
|
Optional wildcard values for the job. |
None
|
input_size
|
int | None
|
Optional input file size in bytes for size-scaled estimates. |
None
|
threads
|
int | None
|
Optional thread count for thread-specific estimates. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (expected_duration, variance). The duration is always |
float
|
wall-clock seconds, even when thread-specific stats are used. |
tuple[float, float]
|
Callers that need thread-seconds should multiply by the job's |
tuple[float, float]
|
thread count: |
Source code in snakesee/estimation/estimator.py
global_mean_duration ¶
Get the global average duration across all known rules.
Used as a fallback when a specific rule has no historical data. Result is cached and invalidated when sample count or rule count changes.
Returns:
| Type | Description |
|---|---|
float
|
Average duration in seconds, or config.default_global_mean if no data. |
Source code in snakesee/estimation/estimator.py
load_from_backend ¶
load_from_backend(backend: PersistenceBackend, progress_callback: ProgressCallback | None = None) -> None
Load historical execution times from a persistence backend.
Supports both filesystem and SQLite backends via the PersistenceBackend protocol. Delegates to HistoricalDataLoader.load_from_backend().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
PersistenceBackend
|
Persistence backend to read metadata from. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress reporting. |
None
|
Source code in snakesee/estimation/estimator.py
load_from_events ¶
Load historical execution times from a snakesee events file.
Parses the .snakesee_events.jsonl file to extract job durations from job_finished events. Data is recorded directly into the RuleRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events_file
|
Path
|
Path to .snakesee_events.jsonl file. |
required |
Source code in snakesee/estimation/estimator.py
load_from_metadata ¶
Load historical execution times from .snakemake/metadata/.
Uses a single-pass parser for efficiency - reads each metadata file only once to collect timing stats, code hashes, and wildcard stats. Data is recorded directly into the RuleRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_dir
|
Path
|
Path to .snakemake/metadata/ directory. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress reporting. |
None
|
Source code in snakesee/estimation/estimator.py
set_provided_cores ¶
Set the Snakemake -j/--cores value parsed from the log.
When available, this provides a definitive upper bound for parallelism rather than relying solely on peak observed thread sums.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cores
|
int
|
Resolved core count (integer) from |
required |
Source code in snakesee/estimation/estimator.py
Functions¶
levenshtein_distance
cached
¶
Calculate the Levenshtein distance between two strings.
Results are cached for efficiency when comparing the same rule names multiple times during estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s1
|
str
|
First string. |
required |
s2
|
str
|
Second string. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The minimum number of edits (insertions, deletions, substitutions) |
int
|
needed to transform s1 into s2. |
Source code in snakesee/estimation/rule_matcher.py
Modules¶
data_loader ¶
Historical data loading for time estimation.
Classes¶
HistoricalDataLoader ¶
Loads timing data from metadata and events files.
Provides methods to load historical execution data from: - .snakemake/metadata/ directory (from previous Snakemake runs) - .snakesee_events.jsonl file (from snakesee monitoring)
Source code in snakesee/estimation/data_loader.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 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 | |
Functions¶
__init__(registry: RuleRegistry, use_wildcard_conditioning: bool = False) -> None
Initialize the loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
RuleRegistry
|
RuleRegistry to load data into. |
required |
use_wildcard_conditioning
|
bool
|
Whether to record wildcard-specific stats. |
False
|
Source code in snakesee/estimation/data_loader.py
load_from_backend(backend: PersistenceBackend, progress_callback: ProgressCallback | None = None) -> None
Load historical execution times from a persistence backend.
Works with both filesystem and SQLite backends via the PersistenceBackend protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
PersistenceBackend
|
Persistence backend to read from. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress. |
None
|
Source code in snakesee/estimation/data_loader.py
Load historical execution times from a snakesee events file.
Streams the events file line by line for memory efficiency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events_file
|
Path
|
Path to .snakesee_events.jsonl file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if any wildcard data was found. |
Source code in snakesee/estimation/data_loader.py
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 | |
Load historical execution times from .snakemake/metadata/.
Uses a single-pass parser for efficiency - reads each metadata file only once to collect timing stats, code hashes, and wildcard stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_dir
|
Path
|
Path to .snakemake/metadata/ directory. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress. |
None
|
Source code in snakesee/estimation/data_loader.py
Functions¶
estimator ¶
Time estimation for Snakemake workflow progress.
Note: The variance/confidence calculations in this module could potentially be consolidated with snakesee.variance.VarianceCalculator for DRY-ness. Both modules handle similar variance heuristics and confidence calculations. A future refactor could delegate these calculations to shared helpers in VarianceCalculator.
Classes¶
TimeEstimator ¶
Estimates remaining workflow time from historical data.
Uses per-rule timing statistics from previous workflow runs to estimate how long the remaining jobs will take. Falls back to simple linear estimation when historical data is unavailable.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_stats |
dict[str, RuleTimingStats]
|
Dictionary mapping rule names to their timing statistics. |
thread_stats |
dict[str, ThreadTimingStats]
|
Dictionary mapping rule names to thread-conditioned timing stats. |
wildcard_stats |
dict[str, dict[str, WildcardTimingStats]]
|
Nested dict of wildcard-conditioned timing stats. |
use_wildcard_conditioning |
Whether to use wildcard-specific estimates. |
|
config |
Centralized estimation configuration. |
Source code in snakesee/estimation/estimator.py
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 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 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 | |
Attributes¶
property
¶Inferred core count used to convert thread-seconds to wall-clock time.
Priority:
1. Provided cores: N parsed from the Snakemake log (definitive).
2. Peak observed sum of running-job threads (approximation of -j).
3. Fallback to 1.0 when no data is available.
Returns:
| Type | Description |
|---|---|
float
|
Estimated core count (>= 1.0). |
property
writable
¶rule_stats: dict[str, RuleTimingStats]
Get rule stats dict from the registry.
Returns a dict view for backward compatibility with code that reads rule_stats.
property
¶thread_stats: dict[str, ThreadTimingStats]
Get thread stats dict from the registry.
property
¶wildcard_stats: dict[str, dict[str, WildcardTimingStats]]
Get wildcard stats dict from the registry.
Functions¶
__init__(use_wildcard_conditioning: bool = False, half_life_days: float | None = None, weighting_strategy: WeightingStrategy | None = None, half_life_logs: int | None = None, config: EstimationConfig | None = None, rule_registry: RuleRegistry | None = None) -> None
Initialize the estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_wildcard_conditioning
|
bool
|
Whether to use wildcard-specific timing. |
False
|
half_life_days
|
float | None
|
Half-life in days for time-based weighting. After this many days, a run's weight is halved. Only used when weighting_strategy="time". |
None
|
weighting_strategy
|
WeightingStrategy | None
|
Strategy for weighting historical data. "time" - decay based on wall-clock time (good for stable pipelines) "index" - decay based on run count (good for active development) |
None
|
half_life_logs
|
int | None
|
Half-life in log count for index-based weighting. After this many runs, a run's weight is halved. Only used when weighting_strategy="index". |
None
|
config
|
EstimationConfig | None
|
Centralized estimation configuration. If not provided, uses DEFAULT_CONFIG with any explicit parameters overriding it. |
None
|
rule_registry
|
RuleRegistry | None
|
RuleRegistry for centralized statistics. If not provided, creates an internal registry. |
None
|
Source code in snakesee/estimation/estimator.py
estimate_remaining(progress: WorkflowProgress) -> TimeEstimate
Estimate remaining time for a workflow.
Uses one of several estimation strategies depending on available data: 1. "weighted" - Uses per-rule historical timing with exponential weighting 2. "simple" - Falls back to average time per completed step
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress
|
WorkflowProgress
|
Current workflow progress state. |
required |
Returns:
| Type | Description |
|---|---|
TimeEstimate
|
TimeEstimate with expected time, confidence bounds, and method. |
Source code in snakesee/estimation/estimator.py
get_estimate_for_job(rule: str, wildcards: dict[str, str] | None = None, input_size: int | None = None, threads: int | None = None) -> tuple[float, float]
Get expected duration and variance for a specific job.
Uses a cascade of estimation strategies in priority order: 1. Full combination stats (wildcards + threads together) 2. Thread-specific stats 3. Wildcard-specific stats (if enabled) 4. Rule-level stats (with optional size scaling) 5. Fuzzy matching for renamed/similar rules 6. Global mean fallback
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
The rule name. |
required |
wildcards
|
dict[str, str] | None
|
Optional wildcard values for the job. |
None
|
input_size
|
int | None
|
Optional input file size in bytes for size-scaled estimates. |
None
|
threads
|
int | None
|
Optional thread count for thread-specific estimates. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (expected_duration, variance). The duration is always |
float
|
wall-clock seconds, even when thread-specific stats are used. |
tuple[float, float]
|
Callers that need thread-seconds should multiply by the job's |
tuple[float, float]
|
thread count: |
Source code in snakesee/estimation/estimator.py
Get the global average duration across all known rules.
Used as a fallback when a specific rule has no historical data. Result is cached and invalidated when sample count or rule count changes.
Returns:
| Type | Description |
|---|---|
float
|
Average duration in seconds, or config.default_global_mean if no data. |
Source code in snakesee/estimation/estimator.py
load_from_backend(backend: PersistenceBackend, progress_callback: ProgressCallback | None = None) -> None
Load historical execution times from a persistence backend.
Supports both filesystem and SQLite backends via the PersistenceBackend protocol. Delegates to HistoricalDataLoader.load_from_backend().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
PersistenceBackend
|
Persistence backend to read metadata from. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress reporting. |
None
|
Source code in snakesee/estimation/estimator.py
Load historical execution times from a snakesee events file.
Parses the .snakesee_events.jsonl file to extract job durations from job_finished events. Data is recorded directly into the RuleRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events_file
|
Path
|
Path to .snakesee_events.jsonl file. |
required |
Source code in snakesee/estimation/estimator.py
Load historical execution times from .snakemake/metadata/.
Uses a single-pass parser for efficiency - reads each metadata file only once to collect timing stats, code hashes, and wildcard stats. Data is recorded directly into the RuleRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_dir
|
Path
|
Path to .snakemake/metadata/ directory. |
required |
progress_callback
|
ProgressCallback | None
|
Optional callback(current, total) for progress reporting. |
None
|
Source code in snakesee/estimation/estimator.py
Set the Snakemake -j/--cores value parsed from the log.
When available, this provides a definitive upper bound for parallelism rather than relying solely on peak observed thread sums.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cores
|
int
|
Resolved core count (integer) from |
required |
Source code in snakesee/estimation/estimator.py
Functions¶
pending_inferrer ¶
Inference of pending rule distribution for time estimation.
Classes¶
PendingRuleInferrer ¶
Infers the distribution of pending jobs by rule.
When we know the total pending count but not the breakdown by rule, this class infers the distribution based on: 1. Expected job counts (from Snakemake's Job stats table) if available 2. Proportional inference from completed job distribution otherwise
Source code in snakesee/estimation/pending_inferrer.py
Functions¶
infer(completed_by_rule: dict[str, int], pending_count: int, expected_job_counts: dict[str, int] | None = None, current_rules: set[str] | None = None, running_by_rule: dict[str, int] | None = None) -> dict[str, int]
Infer the distribution of pending jobs by rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completed_by_rule
|
dict[str, int]
|
Count of completed jobs per rule. |
required |
pending_count
|
int
|
Total number of pending jobs. |
required |
expected_job_counts
|
dict[str, int] | None
|
Expected counts from Job stats table (most accurate). |
None
|
current_rules
|
set[str] | None
|
Set of rules in current workflow (filters deleted rules). |
None
|
running_by_rule
|
dict[str, int] | None
|
Count of running jobs per rule. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Estimated count of pending jobs per rule. |
Source code in snakesee/estimation/pending_inferrer.py
rule_matcher ¶
Rule matching utilities for fuzzy matching and code hash lookup.
Classes¶
RuleMatchingEngine ¶
Matches rules by name similarity and code hash.
Used to find timing data for renamed rules or similar rules when exact matches aren't available.
Source code in snakesee/estimation/rule_matcher.py
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 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 | |
Functions¶
Initialize the matcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_distance
|
int
|
Maximum Levenshtein distance for fuzzy matches. |
3
|
find_best_match(rule: str, code_hash_to_rules: dict[str, set[str]], rule_stats: dict[str, RuleTimingStats], max_distance: int | None = None) -> tuple[str, RuleTimingStats] | None
Find the best matching rule using code hash then fuzzy matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to match. |
required |
code_hash_to_rules
|
dict[str, set[str]]
|
Mapping of code hashes to rule sets. |
required |
rule_stats
|
dict[str, RuleTimingStats]
|
Available rule statistics. |
required |
max_distance
|
int | None
|
Maximum Levenshtein distance. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, RuleTimingStats] | None
|
Tuple of (matched_rule, stats), or None if no match. |
Source code in snakesee/estimation/rule_matcher.py
find_by_code_hash(rule: str, code_hash_to_rules: dict[str, set[str]], known_rules: set[str]) -> str | None
Find a rule with matching code hash.
When multiple rules share the same code hash and are in known_rules, returns the lexicographically smallest rule name for deterministic behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to look up. |
required |
code_hash_to_rules
|
dict[str, set[str]]
|
Mapping of code hashes to rule sets. |
required |
known_rules
|
set[str]
|
Set of rules with available stats. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Name of matching rule (lexicographically smallest if multiple), |
str | None
|
or None if not found. |
Source code in snakesee/estimation/rule_matcher.py
find_similar(rule: str, known_rules: set[str], max_distance: int | None = None) -> tuple[str, int] | None
Find similar rule by Levenshtein distance.
When multiple rules have the same distance, returns the lexicographically smallest one for deterministic behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
str
|
Rule name to match. |
required |
known_rules
|
set[str]
|
Set of rules to search. |
required |
max_distance
|
int | None
|
Maximum distance (uses instance default if None). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, int] | None
|
Tuple of (matched_rule, distance), or None if no match. |
Source code in snakesee/estimation/rule_matcher.py
Functions¶
levenshtein_distance
cached
¶
Calculate the Levenshtein distance between two strings.
Results are cached for efficiency when comparing the same rule names multiple times during estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s1
|
str
|
First string. |
required |
s2
|
str
|
Second string. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The minimum number of edits (insertions, deletions, substitutions) |
int
|
needed to transform s1 into s2. |