models
Data models for workflow monitoring.
Classes¶
JobInfo
dataclass
¶
Information about a single job execution.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
The name of the rule that was executed. |
job_id |
str | None
|
Optional job identifier. |
start_time |
float | None
|
Unix timestamp when the job started. |
end_time |
float | None
|
Unix timestamp when the job completed (None if still running). |
output_file |
Path | None
|
The output file path this job produces. |
wildcards |
dict[str, str] | None
|
Dictionary of wildcard names to values (e.g., {"sample": "A", "batch": "1"}). |
input_size |
int | None
|
Total size of input files in bytes (None if unknown). |
threads |
int | None
|
Number of threads allocated to this job (None if unknown). |
log_file |
Path | None
|
Path to the job's log file (parsed from snakemake log directive). |
Source code in snakesee/models.py
Attributes¶
duration
property
¶
Total duration in seconds (only for completed jobs).
Returns:
| Type | Description |
|---|---|
float | None
|
Duration in seconds (always >= 0), or None if job not completed. |
elapsed
property
¶
Elapsed time in seconds.
Returns:
| Type | Description |
|---|---|
float | None
|
Seconds elapsed since start, or None if start_time not set. |
RuleTimingStats
dataclass
¶
Aggregated timing statistics for a rule.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
The name of the rule. |
durations |
list[float]
|
List of observed durations in seconds. |
timestamps |
list[float]
|
List of Unix timestamps when each run completed (parallel to durations). |
input_sizes |
list[int | None]
|
List of input file sizes in bytes (parallel to durations, None for unknown). |
Source code in snakesee/models.py
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 | |
Attributes¶
coefficient_of_variation
property
¶
CV = stddev / mean, normalized measure of dispersion.
Returns:
| Type | Description |
|---|---|
float
|
Coefficient of variation, or 0.0 if mean is zero. |
mean_duration
property
¶
Mean duration in seconds.
Returns:
| Type | Description |
|---|---|
float
|
Mean of observed durations, or 0.0 if no data. |
median_input_size
property
¶
Median input size in bytes for jobs with known input sizes.
Returns:
| Type | Description |
|---|---|
int | None
|
Median size in bytes, or None if no size data available. |
std_dev
property
¶
Standard deviation of durations.
Returns:
| Type | Description |
|---|---|
float
|
Standard deviation, or 0.0 if fewer than 2 observations. |
Functions¶
recency_factor ¶
recency_factor(half_life_days: float | None = None, strategy: WeightingStrategy | None = None, half_life_logs: int | None = None) -> float
Calculate a recency factor (0.0-1.0) based on data freshness.
This measures how recent the timing data is. A value of 1.0 means most data is very recent; lower values indicate stale data.
For strategy="time": Based on wall-clock time since runs. For strategy="index": Based on number of runs (always 1.0 for index strategy since recency is inherent in the weighting).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
half_life_days
|
float | None
|
Half-life for time-based decay calculation. |
None
|
strategy
|
WeightingStrategy | None
|
Weighting strategy ("time" or "index"). |
None
|
half_life_logs
|
int | None
|
Half-life for index-based weighting (unused for recency). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Recency factor between 0.0 and 1.0. |
Source code in snakesee/models.py
recent_consistency ¶
Calculate consistency of recent runs (low CV = high consistency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days to look back for "recent" runs. |
7
|
Returns:
| Type | Description |
|---|---|
float
|
Consistency score between 0.3 and 1.0. |
float
|
1.0 = very consistent recent runs, lower = more variable. |
Source code in snakesee/models.py
size_scaled_estimate ¶
size_scaled_estimate(input_size: int, half_life_days: float | None = None, strategy: WeightingStrategy | None = None, half_life_logs: int | None = None) -> tuple[float, float]
Estimate duration scaled by input file size.
Uses the ratio of the given input size to the median historical input size to scale the expected duration. This helps when jobs with larger inputs take proportionally longer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_size
|
int
|
Size of input files for the job in bytes. |
required |
half_life_days
|
float | None
|
Half-life for time-based weighting. |
None
|
strategy
|
WeightingStrategy | None
|
Weighting strategy ("time" or "index"). |
None
|
half_life_logs
|
int | None
|
Half-life for index-based weighting. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (scaled_estimate, scaling_confidence). |
float
|
Confidence is higher when we have good size data correlation. |
Source code in snakesee/models.py
weighted_mean ¶
weighted_mean(half_life_days: float | None = None, strategy: WeightingStrategy | None = None, half_life_logs: int | None = None) -> float
Weighted mean favoring recent executions.
Supports two weighting strategies: - "time": Exponential decay based on wall-clock time since each run. Good for stable pipelines where data naturally ages out. - "index": Exponential decay based on log index (number of runs ago). Good for active development where each run may fix issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
half_life_days
|
float | None
|
After this many days, a run's weight is halved. Only used when strategy="time". Defaults to DEFAULT_HALF_LIFE_DAYS (7.0). |
None
|
strategy
|
WeightingStrategy | None
|
Weighting strategy to use ("time" or "index"). Defaults to DEFAULT_WEIGHTING_STRATEGY ("index"). |
None
|
half_life_logs
|
int | None
|
After this many runs, a run's weight is halved. Only used when strategy="index". Defaults to DEFAULT_HALF_LIFE_LOGS (10). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Weighted mean duration, or 0.0 if no data. |
Source code in snakesee/models.py
ThreadTimingStats
dataclass
¶
Timing statistics for a rule conditioned on thread count.
Tracks timing per (rule, threads) tuple. Example: align rule with 1 thread takes 10min, with 8 threads takes 2min.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
The rule name. |
stats_by_threads |
dict[int, RuleTimingStats]
|
Dictionary mapping thread count to their timing stats. |
Source code in snakesee/models.py
Functions¶
get_best_match ¶
get_best_match(threads: int) -> tuple[RuleTimingStats | None, int | None]
Get best matching stats with fallback strategy.
Returns:
| Type | Description |
|---|---|
RuleTimingStats | None
|
Tuple of (stats, matched_threads) where: |
int | None
|
|
tuple[RuleTimingStats | None, int | None]
|
|
tuple[RuleTimingStats | None, int | None]
|
|
Source code in snakesee/models.py
get_stats_for_threads ¶
get_stats_for_threads(threads: int) -> RuleTimingStats | None
TimeEstimate
dataclass
¶
Time remaining estimate with uncertainty bounds.
Attributes:
| Name | Type | Description |
|---|---|---|
seconds_remaining |
float
|
Expected seconds remaining. |
lower_bound |
float
|
Optimistic estimate (95% CI lower). |
upper_bound |
float
|
Pessimistic estimate (95% CI upper). |
confidence |
float
|
Confidence level (0.0 to 1.0). |
method |
str
|
Estimation method used ("simple", "weighted", "bootstrap"). |
inferred_cores |
float | None
|
Estimated core count used for thread-aware estimation. |
Source code in snakesee/models.py
Functions¶
format_eta ¶
Format as human-readable ETA string.
Delegates to snakesee.formatting.format_eta for centralized formatting.
Returns:
| Name | Type | Description |
|---|---|---|
str
|
Formatted ETA with confidence indication. |
|
Examples |
str
|
"~5m", "5-10m", "~15m (rough)", "unknown" |
Source code in snakesee/models.py
WildcardTimingStats
dataclass
¶
Timing statistics for a rule conditioned on a specific wildcard value.
Tracks timing per (rule, wildcard_key, wildcard_value) tuple. Example: align rule with sample=A takes 5min, sample=B takes 20min.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
The rule name. |
wildcard_key |
str
|
The wildcard dimension (e.g., "sample", "batch"). |
stats_by_value |
dict[str, RuleTimingStats]
|
Dictionary mapping wildcard values to their timing stats. |
Source code in snakesee/models.py
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 | |
Functions¶
get_most_predictive_key
staticmethod
¶
get_most_predictive_key(wildcard_stats: dict[str, WildcardTimingStats]) -> str | None
Find the wildcard key that explains the most variance in timing.
Uses coefficient of variation to identify which wildcard dimension is most predictive of execution time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wildcard_stats
|
dict[str, WildcardTimingStats]
|
Dictionary of wildcard timing stats by key. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The most predictive wildcard key, or None if no good predictor found. |
Source code in snakesee/models.py
get_stats_for_value ¶
get_stats_for_value(value: str) -> RuleTimingStats | None
Get timing stats for a specific wildcard value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The wildcard value to look up. |
required |
Returns:
| Type | Description |
|---|---|
RuleTimingStats | None
|
RuleTimingStats if available and has sufficient samples, None otherwise. |
Source code in snakesee/models.py
WorkflowProgress
dataclass
¶
Current state of workflow progress.
Attributes:
| Name | Type | Description |
|---|---|---|
workflow_dir |
Path
|
Path to the workflow directory. |
status |
WorkflowStatus
|
Current workflow status. |
total_jobs |
int
|
Total number of jobs in the workflow. |
completed_jobs |
int
|
Number of jobs completed. |
failed_jobs |
int
|
Number of jobs that failed. |
failed_jobs_list |
list[JobInfo]
|
List of failed job details (for --keep-going). |
incomplete_jobs_list |
list[JobInfo]
|
List of jobs that were in progress when workflow was interrupted. |
running_jobs |
list[JobInfo]
|
List of currently running jobs. |
recent_completions |
list[JobInfo]
|
List of recently completed jobs. |
start_time |
float | None
|
Unix timestamp when workflow started. |
log_file |
Path | None
|
Path to the current snakemake log file. |
Source code in snakesee/models.py
Attributes¶
elapsed_seconds
property
¶
Seconds elapsed since workflow start.
Returns:
| Type | Description |
|---|---|
float | None
|
Elapsed time in seconds, or None if start_time not set. |
pending_jobs
property
¶
Number of jobs not yet started (excludes failed, running, and incomplete).
percent_complete
property
¶
Progress as a percentage.
Returns:
| Type | Description |
|---|---|
float
|
Percentage of jobs completed (0.0 to 100.0). |
WorkflowStatus ¶
Bases: Enum
Current status of a workflow.
Source code in snakesee/models.py
Functions¶
format_duration ¶
Format seconds as human-readable duration.
This is a public API function preserved for backward compatibility. New code should use snakesee.formatting.format_duration directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Duration in seconds. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted duration string (e.g., "5s", "2m 30s", "1h 15m"). |