Skip to content

Commit 5c59d33

Browse files
authored
fbcode/spdl/autoresearch/_common/_visualization.py
Differential Revision: D110484472 Pull Request resolved: #1597
1 parent 4fc5ed8 commit 5c59d33

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

src/spdl/autoresearch/_common/_visualization.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,13 @@ def _plot_headspace_line(
295295
break
296296

297297

298-
def _plot_crashes(ax, crashes, valid, y_key, lower_is_better=True):
298+
def _plot_crashes(
299+
ax: plt.Axes,
300+
crashes: list[dict],
301+
valid: list[dict],
302+
y_key: str,
303+
lower_is_better: bool = True,
304+
) -> None:
299305
if not valid:
300306
crash_y = 0
301307
elif lower_is_better:
@@ -315,7 +321,7 @@ def _plot_crashes(ax, crashes, valid, y_key, lower_is_better=True):
315321
)
316322

317323

318-
def _plot_discarded(ax, discarded, y_key):
324+
def _plot_discarded(ax: plt.Axes, discarded: list[dict], y_key: str) -> None:
319325
ax.scatter(
320326
[e["idx"] for e in discarded],
321327
[e[y_key] for e in discarded],
@@ -327,7 +333,9 @@ def _plot_discarded(ax, discarded, y_key):
327333
)
328334

329335

330-
def _partition_experiments(experiments, y_key):
336+
def _partition_experiments(
337+
experiments: list[dict], y_key: str
338+
) -> tuple[list[dict], list[dict], list[dict], list[dict]]:
331339
"""Split experiments into valid, crashes, kept, discarded by status."""
332340
valid = [e for e in experiments if e["status"] == "VALID" and e.get(y_key)]
333341
crashes = [e for e in experiments if e["status"] == "CRASH"]
@@ -336,7 +344,9 @@ def _partition_experiments(experiments, y_key):
336344
return valid, crashes, kept, discarded
337345

338346

339-
def _collect_y_values(experiments, valid, metric):
347+
def _collect_y_values(
348+
experiments: list[dict], valid: list[dict], metric: MetricSpec
349+
) -> list[float]:
340350
"""Gather all y values including headspace for axis limits."""
341351
y_key = metric.key
342352
all_y = [e[y_key] for e in valid]
@@ -591,7 +601,15 @@ def _tree_font_sizes(node_count: int, max_level: int) -> dict[str, float]:
591601
}
592602

593603

594-
def _draw_edge_label(ax, label, x1, y1, x2, y2, fontsize):
604+
def _draw_edge_label(
605+
ax: plt.Axes,
606+
label: str,
607+
x1: float,
608+
y1: float,
609+
x2: float,
610+
y2: float,
611+
fontsize: float,
612+
) -> None:
595613
ax.text(
596614
(x1 + x2) / 2.0,
597615
(y1 + y2) / 2.0,
@@ -612,8 +630,14 @@ def _draw_edge_label(ax, label, x1, y1, x2, y2, fontsize):
612630

613631

614632
def _draw_tree_edges(
615-
ax, nodes, x_pos, y_pos, best_path_edges, show_edge_labels, edge_fontsize
616-
):
633+
ax: plt.Axes,
634+
nodes: dict[str, dict],
635+
x_pos: dict[str, float],
636+
y_pos: dict[str, float],
637+
best_path_edges: set[tuple[str, str]],
638+
show_edge_labels: bool,
639+
edge_fontsize: float,
640+
) -> None:
617641
for nid, n in nodes.items():
618642
for child_id in n.get("children", []):
619643
if child_id not in x_pos:
@@ -642,7 +666,16 @@ def _draw_tree_edges(
642666
)
643667

644668

645-
def _draw_tree_node(ax, nid, n, x, y, best_nid, fontsize, launch_order=None):
669+
def _draw_tree_node(
670+
ax: plt.Axes,
671+
nid: str,
672+
n: dict,
673+
x: float,
674+
y: float,
675+
best_nid: str | None,
676+
fontsize: float,
677+
launch_order: int | None = None,
678+
) -> None:
646679
box_w, box_h = 2.4, 1.0
647680
status = n.get("status", "queued")
648681
color = "#27ae60" if nid == best_nid else _STATUS_COLORS.get(status, "#ecf0f1")

0 commit comments

Comments
 (0)