Skip to content

Commit e2eaeb9

Browse files
Fix Black formatting
Co-authored-by: Samuel <samuel@knutsen.co>
1 parent f044276 commit e2eaeb9

2 files changed

Lines changed: 41 additions & 121 deletions

File tree

tensorbored/plugins/core/profile_writer.py

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,10 @@ def __init__(
278278
superimposed_cards or []
279279
)
280280
if run_selection is not None:
281-
self._run_selection: list[RunSelectionEntry] = list(
282-
run_selection
283-
)
281+
self._run_selection: list[RunSelectionEntry] = list(run_selection)
284282
elif selected_runs is not None:
285283
self._run_selection = [
286-
RunSelectionEntry(
287-
type="RUN_NAME", value=r, selected=True
288-
)
284+
RunSelectionEntry(type="RUN_NAME", value=r, selected=True)
289285
for r in selected_runs
290286
]
291287
else:
@@ -352,9 +348,7 @@ def superimposed_cards(self) -> list[SuperimposedCardEntry]:
352348
return self._superimposed_cards
353349

354350
@superimposed_cards.setter
355-
def superimposed_cards(
356-
self, value: list[SuperimposedCardEntry]
357-
) -> None:
351+
def superimposed_cards(self, value: list[SuperimposedCardEntry]) -> None:
358352
self._superimposed_cards = list(value)
359353

360354
@property
@@ -444,19 +438,15 @@ def tag_axis_scales(self) -> dict[str, TagAxisScale]:
444438
return self._tag_axis_scales
445439

446440
@tag_axis_scales.setter
447-
def tag_axis_scales(
448-
self, value: dict[str, TagAxisScale]
449-
) -> None:
441+
def tag_axis_scales(self, value: dict[str, TagAxisScale]) -> None:
450442
self._tag_axis_scales = dict(value)
451443

452444
@property
453445
def tag_symlog_linear_thresholds(self) -> dict[str, float]:
454446
return self._tag_symlog_linear_thresholds
455447

456448
@tag_symlog_linear_thresholds.setter
457-
def tag_symlog_linear_thresholds(
458-
self, value: dict[str, float]
459-
) -> None:
449+
def tag_symlog_linear_thresholds(self, value: dict[str, float]) -> None:
460450
self._tag_symlog_linear_thresholds = dict(value)
461451

462452
@property
@@ -473,19 +463,15 @@ def expanded_tag_groups(self, value: dict[str, bool]) -> None:
473463

474464
def pin_scalar(self, tag: str) -> None:
475465
"""Pin a scalar card."""
476-
self._pinned_cards.append(
477-
PinnedCard(plugin="scalars", tag=tag)
478-
)
466+
self._pinned_cards.append(PinnedCard(plugin="scalars", tag=tag))
479467

480468
def pin_histogram(self, tag: str, run_id: str) -> None:
481469
"""Pin a histogram card."""
482470
self._pinned_cards.append(
483471
PinnedCard(plugin="histograms", tag=tag, runId=run_id)
484472
)
485473

486-
def pin_image(
487-
self, tag: str, run_id: str, sample: int = 0
488-
) -> None:
474+
def pin_image(self, tag: str, run_id: str, sample: int = 0) -> None:
489475
"""Pin an image card."""
490476
self._pinned_cards.append(
491477
PinnedCard(
@@ -510,9 +496,7 @@ def add_superimposed_card(
510496
def select_runs(self, run_names: list[str]) -> None:
511497
"""Set visible runs by name (replaces current selection)."""
512498
self._run_selection = [
513-
RunSelectionEntry(
514-
type="RUN_NAME", value=name, selected=True
515-
)
499+
RunSelectionEntry(type="RUN_NAME", value=name, selected=True)
516500
for name in run_names
517501
]
518502

@@ -575,17 +559,13 @@ def serialize(self) -> SerializedProfile:
575559
if self._tag_axis_scales:
576560
data["tagAxisScales"] = dict(self._tag_axis_scales)
577561
if self._symlog_linear_threshold is not None:
578-
data["symlogLinearThreshold"] = (
579-
self._symlog_linear_threshold
580-
)
562+
data["symlogLinearThreshold"] = self._symlog_linear_threshold
581563
if self._tag_symlog_linear_thresholds:
582564
data["tagSymlogLinearThresholds"] = dict(
583565
self._tag_symlog_linear_thresholds
584566
)
585567
if self._expanded_tag_groups:
586-
data["expandedTagGroups"] = dict(
587-
self._expanded_tag_groups
588-
)
568+
data["expandedTagGroups"] = dict(self._expanded_tag_groups)
589569
return SerializedProfile(version=PROFILE_VERSION, data=data)
590570

591571
def write(self, logdir: str) -> str:
@@ -603,38 +583,30 @@ def write(self, logdir: str) -> str:
603583
# --------------------------------------------------------------- #
604584

605585
@classmethod
606-
def from_serialized(
607-
cls, serialized: SerializedProfile
608-
) -> Profile:
586+
def from_serialized(cls, serialized: SerializedProfile) -> Profile:
609587
"""Create a :class:`Profile` from a ``SerializedProfile``."""
610588
data = serialized["data"]
611589
return cls(
612590
name=data["name"],
613591
pinned_cards=data.get("pinnedCards", []),
614592
run_colors={
615-
e["runId"]: e["color"]
616-
for e in data.get("runColors", [])
593+
e["runId"]: e["color"] for e in data.get("runColors", [])
617594
},
618595
group_colors={
619-
e["groupKey"]: e["colorId"]
620-
for e in data.get("groupColors", [])
596+
e["groupKey"]: e["colorId"] for e in data.get("groupColors", [])
621597
},
622598
superimposed_cards=data.get("superimposedCards", []),
623599
run_selection=data.get("runSelection"),
624600
metric_descriptions=data.get("metricDescriptions"),
625601
tag_filter=data.get("tagFilter", ""),
626602
run_filter=data.get("runFilter", ""),
627603
smoothing=data.get("smoothing", 0.6),
628-
symlog_linear_threshold=data.get(
629-
"symlogLinearThreshold"
630-
),
604+
symlog_linear_threshold=data.get("symlogLinearThreshold"),
631605
group_by=data.get("groupBy"),
632606
y_axis_scale=data.get("yAxisScale"),
633607
x_axis_scale=data.get("xAxisScale"),
634608
tag_axis_scales=data.get("tagAxisScales"),
635-
tag_symlog_linear_thresholds=data.get(
636-
"tagSymlogLinearThresholds"
637-
),
609+
tag_symlog_linear_thresholds=data.get("tagSymlogLinearThresholds"),
638610
expanded_tag_groups=data.get("expandedTagGroups"),
639611
)
640612

@@ -669,18 +641,12 @@ def update(self, other: Profile) -> None:
669641
``None``.
670642
"""
671643
self._name = other._name
672-
self._tag_filter = _merge_regex(
673-
self._tag_filter, other._tag_filter
674-
)
675-
self._run_filter = _merge_regex(
676-
self._run_filter, other._run_filter
677-
)
644+
self._tag_filter = _merge_regex(self._tag_filter, other._tag_filter)
645+
self._run_filter = _merge_regex(self._run_filter, other._run_filter)
678646
self._smoothing = other._smoothing
679647

680648
if other._symlog_linear_threshold is not None:
681-
self._symlog_linear_threshold = (
682-
other._symlog_linear_threshold
683-
)
649+
self._symlog_linear_threshold = other._symlog_linear_threshold
684650
if other._group_by is not None:
685651
self._group_by = other._group_by
686652
if other._y_axis_scale is not None:
@@ -822,9 +788,7 @@ def create_profile(
822788
run_filter=run_filter,
823789
smoothing=smoothing,
824790
symlog_linear_threshold=(
825-
symlog_linear_threshold
826-
if symlog_linear_threshold != 1.0
827-
else None
791+
symlog_linear_threshold if symlog_linear_threshold != 1.0 else None
828792
),
829793
group_by=group_by,
830794
y_axis_scale=y_axis_scale,
@@ -835,9 +799,7 @@ def create_profile(
835799
)
836800

837801

838-
def write_profile(
839-
logdir: str, profile: SerializedProfile | Profile
840-
) -> str:
802+
def write_profile(logdir: str, profile: SerializedProfile | Profile) -> str:
841803
"""Write a profile to the logdir.
842804
843805
The profile is written to

tensorbored/plugins/core/profile_writer_test.py

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ def test_create_profile_with_tag_axis_scales(self):
233233
"eval/loss": {"y": "log10", "x": "symlog10"},
234234
},
235235
)
236-
self.assertEqual(
237-
profile.tag_axis_scales["train/loss"], {"y": "log10"}
238-
)
236+
self.assertEqual(profile.tag_axis_scales["train/loss"], {"y": "log10"})
239237
self.assertEqual(
240238
profile.tag_axis_scales["eval/loss"],
241239
{"y": "log10", "x": "symlog10"},
@@ -345,12 +343,8 @@ def test_construction_with_kwargs(self):
345343
self.assertEqual(p.y_axis_scale, "log10")
346344
self.assertEqual(p.x_axis_scale, "symlog10")
347345
self.assertEqual(p.tag_axis_scales, {"loss": {"y": "log10"}})
348-
self.assertEqual(
349-
p.tag_symlog_linear_thresholds, {"loss": 5.0}
350-
)
351-
self.assertEqual(
352-
p.expanded_tag_groups, {"train": True, "eval": False}
353-
)
346+
self.assertEqual(p.tag_symlog_linear_thresholds, {"loss": 5.0})
347+
self.assertEqual(p.expanded_tag_groups, {"train": True, "eval": False})
354348

355349
def test_selected_runs_convenience(self):
356350
p = profile_writer.Profile(selected_runs=["train", "eval"])
@@ -360,9 +354,7 @@ def test_selected_runs_convenience(self):
360354

361355
def test_run_selection_takes_priority_over_selected_runs(self):
362356
sel = [{"type": "RUN_ID", "value": "abc", "selected": False}]
363-
p = profile_writer.Profile(
364-
run_selection=sel, selected_runs=["x"]
365-
)
357+
p = profile_writer.Profile(run_selection=sel, selected_runs=["x"])
366358
self.assertEqual(len(p.run_selection), 1)
367359
self.assertEqual(p.run_selection[0]["value"], "abc")
368360

@@ -456,13 +448,9 @@ def test_pin_image(self):
456448

457449
def test_add_superimposed_card(self):
458450
p = profile_writer.Profile()
459-
p.add_superimposed_card(
460-
"Train vs Eval", ["train/loss", "eval/loss"]
461-
)
451+
p.add_superimposed_card("Train vs Eval", ["train/loss", "eval/loss"])
462452
self.assertEqual(len(p.superimposed_cards), 1)
463-
self.assertEqual(
464-
p.superimposed_cards[0]["title"], "Train vs Eval"
465-
)
453+
self.assertEqual(p.superimposed_cards[0]["title"], "Train vs Eval")
466454
self.assertEqual(
467455
p.superimposed_cards[0]["tags"],
468456
["train/loss", "eval/loss"],
@@ -499,13 +487,9 @@ def test_serialize_defaults(self):
499487
self.assertNotIn("expandedTagGroups", data)
500488

501489
def test_serialize_run_colors(self):
502-
p = profile_writer.Profile(
503-
run_colors={"a": "#111", "b": "#222"}
504-
)
490+
p = profile_writer.Profile(run_colors={"a": "#111", "b": "#222"})
505491
data = p.serialize()["data"]
506-
color_dict = {
507-
e["runId"]: e["color"] for e in data["runColors"]
508-
}
492+
color_dict = {e["runId"]: e["color"] for e in data["runColors"]}
509493
self.assertEqual(color_dict, {"a": "#111", "b": "#222"})
510494

511495
def test_serialize_group_colors(self):
@@ -535,13 +519,9 @@ def test_serialize_all_optional_fields(self):
535519
self.assertEqual(data["groupBy"]["key"], "RUN")
536520
self.assertEqual(data["yAxisScale"], "log10")
537521
self.assertEqual(data["xAxisScale"], "symlog10")
538-
self.assertEqual(
539-
data["tagAxisScales"], {"loss": {"y": "log10"}}
540-
)
522+
self.assertEqual(data["tagAxisScales"], {"loss": {"y": "log10"}})
541523
self.assertEqual(data["symlogLinearThreshold"], 2.0)
542-
self.assertEqual(
543-
data["tagSymlogLinearThresholds"], {"loss": 3.0}
544-
)
524+
self.assertEqual(data["tagSymlogLinearThresholds"], {"loss": 3.0})
545525
self.assertEqual(data["expandedTagGroups"], {"train": True})
546526

547527
def test_serialize_validates_tag_axis_scales(self):
@@ -584,19 +564,13 @@ def test_from_serialized_round_trip(self):
584564
{"train": "#ff0000", "eval": "#00ff00"},
585565
)
586566
self.assertEqual(loaded.group_colors, {"grp": 2})
587-
self.assertEqual(
588-
loaded.metric_descriptions, {"loss": "desc"}
589-
)
567+
self.assertEqual(loaded.metric_descriptions, {"loss": "desc"})
590568
self.assertEqual(loaded.tag_filter, "loss")
591569
self.assertEqual(loaded.smoothing, 0.8)
592570
self.assertEqual(loaded.y_axis_scale, "log10")
593-
self.assertEqual(
594-
loaded.expanded_tag_groups, {"train": True}
595-
)
571+
self.assertEqual(loaded.expanded_tag_groups, {"train": True})
596572
self.assertEqual(loaded.symlog_linear_threshold, 5.0)
597-
self.assertEqual(
598-
loaded.tag_symlog_linear_thresholds, {"loss": 10.0}
599-
)
573+
self.assertEqual(loaded.tag_symlog_linear_thresholds, {"loss": 10.0})
600574

601575
# ---- write / load round-trip ----
602576

@@ -647,12 +621,8 @@ def test_update_merges_dicts(self):
647621
expanded_tag_groups={"eval": False},
648622
)
649623
a.update(b)
650-
self.assertEqual(
651-
a.run_colors, {"r1": "#aaa", "r2": "#bbb"}
652-
)
653-
self.assertEqual(
654-
a.metric_descriptions, {"loss": "d1", "acc": "d2"}
655-
)
624+
self.assertEqual(a.run_colors, {"r1": "#aaa", "r2": "#bbb"})
625+
self.assertEqual(a.metric_descriptions, {"loss": "d1", "acc": "d2"})
656626
self.assertEqual(
657627
a.expanded_tag_groups,
658628
{"train": True, "eval": False},
@@ -726,34 +696,24 @@ def test_or_returns_new_profile(self):
726696
self.assertIsNot(c, a)
727697
self.assertIsNot(c, b)
728698
self.assertEqual(c.name, "B")
729-
self.assertEqual(
730-
c.run_colors, {"r1": "#aaa", "r2": "#bbb"}
731-
)
699+
self.assertEqual(c.run_colors, {"r1": "#aaa", "r2": "#bbb"})
732700
self.assertEqual(len(c.pinned_cards), 2)
733701
self.assertEqual(c.y_axis_scale, "log10")
734702
# Originals are unmodified.
735703
self.assertEqual(a.run_colors, {"r1": "#aaa"})
736704
self.assertEqual(len(a.pinned_cards), 1)
737705

738706
def test_ior_mutates_in_place(self):
739-
a = profile_writer.Profile(
740-
"A", run_colors={"r1": "#aaa"}
741-
)
742-
b = profile_writer.Profile(
743-
"B", run_colors={"r2": "#bbb"}
744-
)
707+
a = profile_writer.Profile("A", run_colors={"r1": "#aaa"})
708+
b = profile_writer.Profile("B", run_colors={"r2": "#bbb"})
745709
a |= b
746710
self.assertEqual(a.name, "B")
747-
self.assertEqual(
748-
a.run_colors, {"r1": "#aaa", "r2": "#bbb"}
749-
)
711+
self.assertEqual(a.run_colors, {"r1": "#aaa", "r2": "#bbb"})
750712

751713
def test_or_not_implemented_for_non_profile(self):
752714
p = profile_writer.Profile()
753715
self.assertEqual(p.__or__("not a profile"), NotImplemented)
754-
self.assertEqual(
755-
p.__ior__("not a profile"), NotImplemented
756-
)
716+
self.assertEqual(p.__ior__("not a profile"), NotImplemented)
757717

758718
# ---- builder workflow ----
759719

@@ -769,9 +729,7 @@ def test_builder_workflow(self):
769729
p.y_axis_scale = "log10"
770730
p.metric_descriptions["train/loss"] = "Training loss"
771731
p.expanded_tag_groups["train"] = True
772-
p.add_superimposed_card(
773-
"Loss Comparison", ["train/loss", "eval/loss"]
774-
)
732+
p.add_superimposed_card("Loss Comparison", ["train/loss", "eval/loss"])
775733
p.select_runs(["train", "eval"])
776734

777735
path = p.write(self.logdir)

0 commit comments

Comments
 (0)