k4bench.analysis.plots¶
k4bench.analysis.plots ¶
Plotly plotting functions for k4bench results.
All functions return a :class:~plotly.graph_objects.Figure.
In Jupyter the figure renders inline automatically; call fig.show()
to display it explicitly, or fig.write_html("out.html") to export.
Typical notebook usage::
from k4bench.analysis import load_results, plot_run_overview, plot_event_timing
plot_run_overview("logs/")
plot_event_timing("logs/")
BinCountOptions ¶
Bases: NamedTuple
Automatic and allowed dashboard bin counts for one data selection.
Measure
dataclass
¶
Measure(column: str, title: str, unit: str, write: Callable[[float], str], total: str | None = None, tickformat: str = ',~g', log: bool = True)
One measure a :func:plot_standing panel draws.
auto_bin_count ¶
auto_bin_count(source: dict[str, DataFrame] | str | Path | list[str | Path], *, column: str, labels: list[str] | None = None, exclude_events: list[int] | None = None, outlier_threshold: float = 3.5) -> int
Return the bin count plot_event_* would choose with bins="auto".
Runs the same preparation the plotting functions do — the same event exclusions, the same outlier clipping, the same pooled range — so callers that want to offer an editable bin count can seed it with the number the figure would otherwise have used, instead of an arbitrary default that would silently rebin the plot on first render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, pd.DataFrame], str/Path, or list of str/Path
|
As for :func: |
required |
column
|
str
|
The value column to bin, e.g. |
required |
labels
|
list[str] or None
|
Restrict to these run labels. |
None
|
exclude_events
|
list[int] or None
|
Event numbers to exclude. Defaults to |
None
|
outlier_threshold
|
float
|
MAD-based modified Z-score threshold for range clipping. |
3.5
|
Source code in k4bench/analysis/plots/event.py
event_bin_options ¶
event_bin_options(source: dict[str, DataFrame] | str | Path | list[str | Path], *, column: str, labels: list[str] | None = None, exclude_events: list[int] | None = None, outlier_threshold: float = 3.5) -> BinCountOptions
Return automatic and sensible editable bin counts for an event metric.
The maximum is derived from the current pooled in-range sample: more bins than observations normally add no statistical resolution. If NumPy's automatic rule itself chooses more, that exact automatic count remains selectable. The renderer ceiling remains the absolute upper bound.
Source code in k4bench/analysis/plots/event.py
plot_event_memory ¶
plot_event_memory(source: dict[str, DataFrame] | str | Path | list[str | Path], *, column: str = 'rss_end_mb', labels: list[str] | None = None, baseline_label: str | None = None, show: str = 'both', bins: BinSpec = 'auto', bin_width: float | None = None, bin_origin: float | None = None, show_errors: bool = False, show_mean_lines: bool = True, alpha: float = 0.7, figsize: tuple[float, float] | None = None, outlier_threshold: float = 3.5, exclude_events: list[int] | None = None, palette: list[str] | None = None) -> Figure
Plot per-event memory (RSS) distributions for one or more runs.
Distribution panel shows a histogram of the chosen RSS, sampled at the end of each event. Sequence panel shows it vs event number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, pd.DataFrame], str/Path, or list of str/Path
|
Pre-loaded dict from :func: |
required |
column
|
str
|
Which RSS to draw, one of :data: |
'rss_end_mb'
|
labels
|
list[str] or None
|
Restrict to these run labels. |
None
|
baseline_label
|
str or None
|
Reference run for the ratio panel (multi-run only). |
None
|
show
|
('both', 'distribution', 'sequence')
|
Which panels to display. |
"both"
|
bins
|
int, str, or sequence of float
|
Bin count, a :func: |
'auto'
|
bin_width
|
float or None
|
Fixed bin width in data units. Mutually exclusive with |
None
|
bin_origin
|
float or None
|
Origin of the fixed-width grid. Used only with |
None
|
show_errors
|
bool
|
Draw Poisson |
False
|
show_mean_lines
|
bool
|
Draw the dashed per-run mean line on the distribution panel. |
True
|
alpha
|
float
|
Opacity of the filled bars (default: 0.7). The step outline drawn over
each histogram stays fully opaque, so lowering this fades overlapping
fills without losing any distribution; |
0.7
|
figsize
|
(width, height) or None
|
Figure size in inches (converted to pixels at 96 dpi). |
None
|
outlier_threshold
|
float
|
MAD-based modified Z-score threshold for x-range clipping. |
3.5
|
exclude_events
|
list[int] or None
|
Event numbers to exclude. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in k4bench/analysis/plots/event.py
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 | |
plot_event_timing ¶
plot_event_timing(source: dict[str, DataFrame] | str | Path | list[str | Path], *, labels: list[str] | None = None, baseline_label: str | None = None, show: str = 'both', bins: BinSpec = 'auto', bin_width: float | None = None, bin_origin: float | None = None, show_errors: bool = False, show_mean_lines: bool = True, alpha: float = 0.7, figsize: tuple[float, float] | None = None, outlier_threshold: float = 3.5, exclude_events: list[int] | None = None, palette: list[str] | None = None, quantity: str = 'Event time', references: Mapping[str, str] | None = None) -> Figure
Plot per-event timing distributions for one or more runs.
Single run: histogram with μ ± SEM and σ ± SE(σ) shown as an annotation.
Multiple runs: overlaid histograms and, with show="both", bin-by-bin
and per-event ratio panels for every non-baseline run against the reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, pd.DataFrame], str/Path, or list of str/Path
|
Pre-loaded dict from :func: |
required |
labels
|
list[str] or None
|
Restrict to these run labels. |
None
|
baseline_label
|
str or None
|
Reference run for the ratio panel (multi-run only). |
None
|
show
|
('both', 'distribution', 'sequence')
|
Which panels to display. |
"both"
|
bins
|
int, str, or sequence of float
|
Bin count, a :func: |
'auto'
|
bin_width
|
float or None
|
Fixed bin width in data units. Mutually exclusive with |
None
|
bin_origin
|
float or None
|
Origin of the fixed-width grid. Used only with |
None
|
show_errors
|
bool
|
Draw Poisson |
False
|
show_mean_lines
|
bool
|
Draw the dashed per-run mean line on the distribution panel. |
True
|
alpha
|
float
|
Opacity of the filled bars (default: 0.7). The step outline drawn over
each histogram stays fully opaque, so lowering this fades overlapping
fills without losing any distribution; |
0.7
|
figsize
|
(width, height) or None
|
Figure size in inches (converted to pixels at 96 dpi). |
None
|
outlier_threshold
|
float
|
MAD-based modified Z-score threshold for x-range clipping. |
3.5
|
exclude_events
|
list[int] or None
|
Event numbers to exclude. Defaults to |
None
|
quantity
|
str
|
What the times are, as the axes name them: an algorithm's own time
in each event ( |
'Event time'
|
references
|
mapping or None
|
Each run's own reference for the ratio panels, in place of
|
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in k4bench/analysis/plots/event.py
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 | |
plot_standing ¶
plot_standing(values: DataFrame, name: str, measures: Sequence[Measure], *, color: str = ACCENT) -> Figure | None
A panel per one of measures that name has a value above zero in:
every component of values (indexed by component) with one, as a column,
the largest first, name's in color and pointed at with its value, the
rest grey; over the panel, its rank and, for a measure whose values add
up, its share of their sum, under its title and unit. A panel's axis is
logarithmic unless its measure says otherwise. A panel's columns carry their component's name as
customdata[0]. None when name has a value in none of them.
Source code in k4bench/analysis/plots/component.py
plot_component_heap_events ¶
plot_component_heap_events(start: Series, peak: Series, end: Series, *, before_first: float | None = None, after_finalize: float | None = None, color: str = _PALETTE[0], warm_up: int | None = 0) -> Figure | None
One component's heap event by event, in MB, each series indexed by
event number: a bar from what it held as the event started (start) up to
the most it held during it (peak), the event's working set, and a marker
at what it held at the event's end (end). What it held before the first
event and after finalize, where given, head the chart, so its axis spans
the events alone. Without peaks (a job that ran events at once), the bars
are left out and the marks drawn alone. The warm_up event is paler.
None when there is nothing to draw.
Source code in k4bench/analysis/plots/heap.py
plot_heap_timeline ¶
plot_heap_timeline(held: DataFrame, before_first: Series, after_finalize: Series, named: list[str], *, colors: Mapping[str, str] | None = None, rss: Series | None = None, change: bool = False, warm_up: int | None = 0, steps: DataFrame | None = None, log_y: bool = False) -> Figure | None
The heap each series held, from initialization through each event to finalization.
held is events × series, in MB at each event's end, indexed by event
number: the job's components (execute["held_bytes"]) or groups of them,
:data:~k4bench.analysis.heap.NO_COMPONENT among them.
before_first and after_finalize are the same series' heap before the
first event and after the job's finalize.
Stacked, the named series are a band each, the most stable lowest; the
rest are one "Other (k)" band, and what no component allocated the lowest
band of all, both in neutral greys. The bands are opaque and set apart by
a gap in the surface colour; one wide enough at the last event carries its
name inside it there. A dashed line is rss, the anonymous RSS of the job
at each event's end (MB, indexed by event number) where given; the top of
the stack, the heap of the whole job, is in the hover. With change, each
of the named series is instead a line of what it held at each event's
end beyond what it held at the first event's end, so growth rises and a
step jumps, and the rest and what no component allocated are two grey
lines: together the lines make the whole heap's change, so growth in a
series not named still shows. colors maps a series to its colour; the others take the
default palette's colours but its grey, in order, which a caller drawing
more series than it has colours must not rely on. The
warm_up event is shaded. steps marks the events where a series
rose at once, one row each with its series, event_number and
step_mb (:meth:~k4bench.analysis.heap.ComponentHeap.steps): a
marker in the series' colour on the top of the stack, one for all of an
event's steps (in the largest's colour, every one in the hover), or on
the series' line with change (a step of a series not named is not
marked there). With log_y, the stack is drawn on a log axis reaching
below the lowest band, so the small bands under a large one stay
readable; it does not apply with change, whose lines cross zero.
None when there is nothing to draw.
Source code in k4bench/analysis/plots/heap.py
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 | |
plot_run_overview ¶
plot_run_overview(results: DataFrame | str | Path | list[str | Path], *, labels: list[str] | None = None, metrics: list[tuple[str, str]] | None = None, relative: bool = True, baseline_label: str | None = None) -> Figure
Plot run metrics for all runs in a 2 × 2 panel grid.
Each metric is drawn as a horizontal bar chart with value annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
pd.DataFrame, str/Path, or list of str/Path
|
Results DataFrame, a single log-dir path, or a list of log-dir paths for multi-detector comparisons. |
required |
labels
|
list[str] or None
|
Show only these run labels. |
None
|
metrics
|
list of (column, axis-label) pairs or None
|
Which metrics to plot. Defaults to wall_time_s, peak_rss_mb, user_cpu_s, events_per_sec. |
None
|
relative
|
bool
|
If |
True
|
baseline_label
|
str or None
|
Which run to treat as 100 % when |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in k4bench/analysis/plots/overview.py
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 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
plot_event_composition ¶
plot_event_composition(times: DataFrame, components: list[str], *, colors: Mapping[str, str] | None = None, sort: bool = False, warm_up: int | None = 0) -> Figure
The event loop event by event: a column per event stacking each of components' self time in it, the rest as "Other".
times is the job's execute["wall_s"] (events × components, NaN
where a component did not run). colors maps a component to its colour,
as :func:plot_phase_component_pie takes it. sort orders the events by
their time, longest first, instead of by event number. The warm_up
event is drawn paler. A component's bars carry its name as their
customdata; "Other"'s carry none.
Source code in k4bench/analysis/plots/phases.py
plot_phase_component_pie ¶
plot_phase_component_pie(seconds: Series, *, top_n: int = 5, colors: Mapping[str, str] | None = None, title: str | None = None, duration: float | None = None, unit: str = 's') -> Figure
A donut of one phase's time by component: the :func:top_components
and the rest as one "Other (k)" slice, the total in the middle.
seconds is component → self seconds in the phase
(:meth:~k4bench.analysis.components.ComponentTiming.phase_component_seconds).
duration is the phase's elapsed seconds
(:meth:~k4bench.analysis.components.ComponentTiming.phase_seconds):
the part of it no component was charged for is one more slice,
:data:UNATTRIBUTED, and the middle is the phase's duration. Without
it, the middle is the components' summed time; when that exceeds
duration (components run in parallel), too, marked as component time.
colors maps a component to its colour, so a component that several
donuts show keeps one; the others take the palette in order. Parts of
another quantity than time give its unit.
Source code in k4bench/analysis/plots/phases.py
plot_phase_history ¶
plot_phase_history(series: DataFrame, *, palette: list[str] = _PALETTE, relative: bool = False, value: str = 'seconds', unit: str = 's', y_title: str = 'Time (s)', whole: str = 'phase', all_runs: bool = False) -> Figure | None
One phase's time per nightly tag, a column per tag stacking
:func:phase_component_series' series in their order, "Other" grey and
:data:UNATTRIBUTED paler: a column's height is the series' total,
written above it, the phase's duration when the series carry its
unattributed part. relative draws each series as its share of the
column. A tag run more than once shows its latest run
(:func:latest_run_per_tag). None when there is nothing to draw.
Series of another quantity than time (their :func:phase_component_series
value) give its column as value, its unit, the y_title of the
axis and what a column is the whole of.
all_runs draws a column per run instead, every run of a tag, in the
order they were measured: each named by the night it ran, the hover
adding its release (:func:run_label). Two runs are never one column,
whatever night or tag they share.
Source code in k4bench/analysis/plots/phases.py
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 | |
plot_region_timing ¶
plot_region_timing(source: dict[str, dict] | str | Path | list[str | Path], *, labels: list[str] | None = None, show: str = 'both', attribution: str = 'at_location', top_n: int = 8, figsize: tuple[float, float] | None = None, exclude_events: list[int] | None = None, palette: list[str] | None = None, alpha: float = 0.85) -> Figure
Plot per-detector timing breakdown and/or per-event sequence for one or more runs.
Single run: a donut chart + sorted horizontal bar chart (breakdown panel) and/or a stacked-area sequence chart. Multiple runs: a grouped horizontal bar chart (breakdown) and/or a vertical stack of per-run stacked-area sequence charts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, dict], str/Path, or list of str/Path
|
Pre-loaded dict from :func: |
required |
labels
|
list[str] or None
|
Restrict to these run labels. |
None
|
show
|
('both', 'breakdown', 'sequence')
|
Which panels to display. |
"both"
|
attribution
|
('at_location', 'by_birth')
|
Which attribution to use. |
"at_location"
|
top_n
|
int
|
Show the top n detectors by mean time; remaining are grouped into |
8
|
figsize
|
(width, height) or None
|
Figure size in inches (converted to pixels at 96 dpi). |
None
|
exclude_events
|
list[int] or None
|
Event numbers to exclude. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in k4bench/analysis/plots/region.py
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 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 | |