Skip to content

Commit 20898b1

Browse files
authored
Source Metadata: cleanup (#6023)
To resolve the latest comments in #6014: - Replace `SourceMetadata` property with `GetSourceWriter()`. - Log at `info` instead of `warning` when multiple source writers are found for the same run (which is possible).
1 parent 8aa64a8 commit 20898b1

8 files changed

+22
-28
lines changed

tensorboard/backend/event_processing/event_accumulator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ def FirstEventTimestamp(self):
308308
except StopIteration:
309309
raise ValueError("No event timestamp could be found")
310310

311-
@property
312-
def SourceWriter(self) -> Optional[str]:
311+
def GetSourceWriter(self) -> Optional[str]:
313312
"""Returns the name of the event writer."""
314313
if self._source_writer is not None:
315314
return self._source_writer
@@ -365,8 +364,7 @@ def _ProcessEvent(self, event):
365364
event.source_metadata
366365
)
367366
if self._source_writer and self._source_writer != new_source_writer:
368-
# This should not happen.
369-
logger.warning(
367+
logger.info(
370368
(
371369
"Found new source writer for event.proto. "
372370
"Old: {0}, New: {1}"

tensorboard/backend/event_processing/event_accumulator_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def testFirstEventTimestampLoadsEvent(self):
713713
acc.Reload()
714714
self.assertEqual(acc.file_version, 2.0)
715715

716-
def testSourceWriter(self):
716+
def testGetSourceWriter(self):
717717
gen = _EventGenerator(self)
718718
acc = ea.EventAccumulator(gen)
719719
gen.AddEvent(
@@ -726,10 +726,10 @@ def testSourceWriter(self):
726726
)
727727
)
728728
gen.AddScalar("s1", wall_time=30, step=40, value=20)
729-
self.assertEqual(acc.SourceWriter, "custom_writer")
729+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
730730

731731
def testReloadPopulatesSourceWriter(self):
732-
"""Test that Reload() means SourceWriter won't load events."""
732+
"""Test that Reload() means GetSourceWriter() won't load events."""
733733
gen = _EventGenerator(self)
734734
acc = ea.EventAccumulator(gen)
735735
gen.AddEvent(
@@ -747,10 +747,10 @@ def _Die(*args, **kwargs): # pylint: disable=unused-argument
747747
raise RuntimeError("Load() should not be called")
748748

749749
self.stubs.Set(gen, "Load", _Die)
750-
self.assertEqual(acc.SourceWriter, "custom_writer")
750+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
751751

752-
def testSourceWriterLoadsEvent(self):
753-
"""Test that SourceWriter doesn't discard the loaded event."""
752+
def testGetSourceWriterLoadsEvent(self):
753+
"""Test that GetSourceWriter() doesn't discard the loaded event."""
754754
gen = _EventGenerator(self)
755755
acc = ea.EventAccumulator(gen)
756756
gen.AddEvent(
@@ -764,7 +764,7 @@ def testSourceWriterLoadsEvent(self):
764764
)
765765
)
766766

767-
self.assertEqual(acc.SourceWriter, "custom_writer")
767+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
768768
acc.Reload()
769769
self.assertEqual(acc.file_version, 2.0)
770770

tensorboard/backend/event_processing/event_multiplexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def GetSourceWriter(self, run) -> Optional[str]:
272272
Name of the writer that wrote the events in the run.
273273
"""
274274
accumulator = self.GetAccumulator(run)
275-
return accumulator.SourceWriter
275+
return accumulator.GetSourceWriter()
276276

277277
def Scalars(self, run, tag):
278278
"""Retrieve the scalar events associated with a run and tag.

tensorboard/backend/event_processing/event_multiplexer_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def Tags(self):
6767
def FirstEventTimestamp(self):
6868
return 0
6969

70-
@property
71-
def SourceWriter(self):
70+
def GetSourceWriter(self):
7271
return "%s_writer" % self._path
7372

7473
def _TagHelper(self, tag_name, enum):

tensorboard/backend/event_processing/plugin_event_accumulator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ def FirstEventTimestamp(self):
258258
except StopIteration:
259259
raise ValueError("No event timestamp could be found")
260260

261-
@property
262-
def SourceWriter(self) -> Optional[str]:
261+
def GetSourceWriter(self) -> Optional[str]:
263262
"""Returns the name of the event writer."""
264263
if self._source_writer is not None:
265264
return self._source_writer
@@ -336,8 +335,7 @@ def _ProcessEvent(self, event):
336335
event.source_metadata
337336
)
338337
if self._source_writer and self._source_writer != new_source_writer:
339-
# This should not happen.
340-
logger.warning(
338+
logger.info(
341339
(
342340
"Found new source writer for event.proto. "
343341
"Old: {0}, New: {1}"

tensorboard/backend/event_processing/plugin_event_accumulator_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def testFirstEventTimestampLoadsEvent(self):
381381
acc.Reload()
382382
self.assertEqual(acc.file_version, 2.0)
383383

384-
def testSourceWriter(self):
384+
def testGetSourceWriter(self):
385385
gen = _EventGenerator(self)
386386
acc = self._make_accumulator(gen)
387387
gen.AddEvent(
@@ -394,10 +394,10 @@ def testSourceWriter(self):
394394
)
395395
)
396396
gen.AddScalarTensor("s1", wall_time=30, step=40, value=20)
397-
self.assertEqual(acc.SourceWriter, "custom_writer")
397+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
398398

399399
def testReloadPopulatesSourceWriter(self):
400-
"""Test that Reload() means SourceWriter won't load events."""
400+
"""Test that Reload() means GetSourceWriter() won't load events."""
401401
gen = _EventGenerator(self)
402402
acc = self._make_accumulator(gen)
403403
gen.AddEvent(
@@ -415,10 +415,10 @@ def _Die(*args, **kwargs): # pylint: disable=unused-argument
415415
raise RuntimeError("Load() should not be called")
416416

417417
self.stubs.Set(gen, "Load", _Die)
418-
self.assertEqual(acc.SourceWriter, "custom_writer")
418+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
419419

420-
def testSourceWriterLoadsEvent(self):
421-
"""Test that SourceWriter doesn't discard the loaded event."""
420+
def testGetSourceWriterLoadsEvent(self):
421+
"""Test that GetSourceWriter() doesn't discard the loaded event."""
422422
gen = _EventGenerator(self)
423423
acc = self._make_accumulator(gen)
424424
gen.AddEvent(
@@ -431,7 +431,7 @@ def testSourceWriterLoadsEvent(self):
431431
),
432432
)
433433
)
434-
self.assertEqual(acc.SourceWriter, "custom_writer")
434+
self.assertEqual(acc.GetSourceWriter(), "custom_writer")
435435
acc.Reload()
436436
self.assertEqual(acc.file_version, 2.0)
437437

tensorboard/backend/event_processing/plugin_event_multiplexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def GetSourceWriter(self, run) -> Optional[str]:
334334
Name of the writer that wrote the events in the run.
335335
"""
336336
accumulator = self.GetAccumulator(run)
337-
return accumulator.SourceWriter
337+
return accumulator.GetSourceWriter()
338338

339339
def Graph(self, run):
340340
"""Retrieve the graph associated with the provided run.

tensorboard/backend/event_processing/plugin_event_multiplexer_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def Tags(self):
6767
def FirstEventTimestamp(self):
6868
return 0
6969

70-
@property
71-
def SourceWriter(self):
70+
def GetSourceWriter(self):
7271
return "%s_writer" % self._path
7372

7473
def _TagHelper(self, tag_name, enum):

0 commit comments

Comments
 (0)