trace-artifact / figures /make_taxonomy_matrix.py
idacy's picture
TRACE artifact: framework, corpus, instrumented case, provider case, evaluators, figures
2955ecc verified
Raw
History Blame Contribute Delete
7.07 kB
#!/usr/bin/env python3
"""Figure 2: registry-derived observable-family and access-context matrix."""
from __future__ import annotations
from collections import OrderedDict
import matplotlib.pyplot as plt
import yaml
from matplotlib.patches import Rectangle
from style import (
BLUE,
INK,
LIGHT_GREY,
MID_GREY,
HERE,
REPO_ROOT,
assert_text_inside_figure,
assert_text_not_overlapping,
save_figure,
)
INPUT = REPO_ROOT / "observables" / "observables.yaml"
OUTPUT = HERE / "fig_taxonomy_matrix.pdf"
FIGURE_WIDTH_IN = 6.25
TABLE_TEXT_PT = 9.0
ACCESS_TEXT_PT = 8.5
DISPLAY_NAMES = OrderedDict(
[
("O01", "inventory and device state"),
("O02", "topology and capability"),
("O03", "scheduler and allocation"),
("O04", "cloud control plane"),
("O05", "accelerator telemetry"),
# Follow the released registry rather than the manuscript's proposed
# but unimplemented O06 profiling expansion.
("O06", "achieved-operation counters"),
("O07", "local accelerator interconnect"),
("O08", "scale-out fabric"),
("O09", "general network"),
("O10", "storage and data movement"),
("O11", "power and energy"),
("O12", "cooling and environment"),
("O13", "host and container resources"),
("O14", "maintenance and physical access"),
("O15", "site and electrical timing"),
]
)
ACCESS = OrderedDict(
[
("public_or_out_of_band", "public /\nOOB"),
("facility_operator", "facility"),
("cluster_operator", "cluster"),
("cloud_provider_control_plane", "cloud /\ncontrol"),
("host_or_orchestrator_resource", "host /\norch."),
("storage_network_operator", "storage /\nnetwork"),
]
)
def load_registry() -> list[dict]:
data = yaml.safe_load(INPUT.read_text(encoding="utf-8"))
if data.get("taxonomy_id") != "operator_visible_datacenter_observables":
raise ValueError("unexpected taxonomy identifier")
if data.get("version") != "2026-05-15":
raise ValueError("taxonomy version changed; review Figure 2 before regeneration")
if list(data.get("access_contexts", {})) != list(ACCESS):
raise ValueError("access-context schema changed")
families = data.get("observables", [])
if [family.get("id") for family in families] != list(DISPLAY_NAMES):
raise ValueError("expected exactly O01--O15 in registry order")
if len(families) != 15:
raise ValueError("expected 15 indirect families")
features = [feature for family in families for feature in family.get("features", [])]
if len(features) != 83:
raise ValueError("expected 83 value-level features for taxonomy version 2026-05-15")
feature_ids = [feature.get("id") for feature in features]
if len(set(feature_ids)) != len(feature_ids):
raise ValueError("feature identifiers are not globally unique")
for family in families:
unknown = set(family.get("access_contexts", [])) - set(ACCESS)
if unknown:
raise ValueError(f"{family['id']} contains unknown access contexts: {unknown}")
return families
def main() -> None:
families = load_registry()
fig, ax = plt.subplots(figsize=(FIGURE_WIDTH_IN, 4.15))
fig.subplots_adjust(left=0.018, right=0.985, bottom=0.035, top=0.965)
ax.set_xlim(0.0, 1.0)
ax.set_ylim(0.0, 1.0)
ax.axis("off")
# Coordinates are normalized so the access columns retain a fixed,
# inspectable width when the physical output size changes.
x_name = 0.004
x_count = 0.460
x_divider = 0.510
x_access = [0.555, 0.634, 0.713, 0.792, 0.871, 0.958]
group_header_y = 0.947
header_y = 0.845
group_rule_y = 0.905
rule_y = 0.785
row_top = 0.752
row_step = 0.0476
header_text = [
ax.text(
x_name,
header_y,
"observable family",
ha="left",
va="center",
fontsize=TABLE_TEXT_PT,
),
ax.text(
x_count,
header_y,
"features\n$n$",
ha="center",
va="center",
fontsize=TABLE_TEXT_PT,
linespacing=0.95,
),
ax.text(
sum(x_access) / len(x_access),
group_header_y,
"declared access context",
ha="center",
va="center",
fontsize=TABLE_TEXT_PT,
color=MID_GREY,
),
]
for x, label in zip(x_access, ACCESS.values()):
header_text.append(
ax.text(
x,
header_y,
label,
ha="center",
va="center",
fontsize=ACCESS_TEXT_PT,
linespacing=0.93,
)
)
ax.plot(
[x_access[0] - 0.035, x_access[-1] + 0.035],
[group_rule_y, group_rule_y],
color=LIGHT_GREY,
lw=0.55,
)
ax.plot([0.0, 0.995], [rule_y, rule_y], color=INK, lw=0.75)
ax.plot(
[x_divider, x_divider],
[0.045, group_rule_y],
color=LIGHT_GREY,
lw=0.7,
)
for row, family in enumerate(families):
y = row_top - row * row_step
ax.plot(
[0.0, 0.995],
[y - row_step / 2, y - row_step / 2],
color=LIGHT_GREY,
lw=0.45,
)
ax.text(
x_name,
y,
rf"$\bf{{{family['id']}}}$ {DISPLAY_NAMES[family['id']]}",
ha="left",
va="center",
fontsize=TABLE_TEXT_PT,
)
ax.text(
x_count,
y,
str(len(family["features"])),
ha="center",
va="center",
fontsize=TABLE_TEXT_PT,
)
declared = set(family["access_contexts"])
for x, key in zip(x_access, ACCESS):
if key in declared:
# Use one simple vector cell. PDFKit/Quick Look misplaces
# repeated transformed circles and compound pseudo-circles,
# while a single rectangle per declaration remains stable.
ax.add_patch(
Rectangle(
(x - 0.0055, y - 0.0085),
width=0.0110,
height=0.0170,
facecolor=BLUE,
edgecolor=INK,
lw=0.35,
zorder=3,
)
)
# This table uses a deliberately conservative inset beyond the global
# one-point guard because multi-line column headers are easy to misread as
# clipped even when their glyph boxes technically fit.
assert_text_not_overlapping(fig, header_text, padding_points=1.5)
assert_text_inside_figure(fig, padding_points=6.0)
save_figure(
fig,
OUTPUT,
subject="Access contexts for the fifteen indirect TRACE observable families",
)
if __name__ == "__main__":
main()