|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="unittest-") as base_dir: |
|
|
|
tb_writer = TensorboardWriter(base_dir, clear_past_data=False) |
|
|
|
statssummary1 = StatsSummary( |
|
|
|
mean=1.0, |
|
|
|
std=1.0, |
|
|
|
num=1, |
|
|
|
sum=1.0, |
|
|
|
full_dist=[0.0], |
|
|
|
aggregation_method=StatsAggregationMethod.AVERAGE, |
|
|
|
full_dist=[1.0], aggregation_method=StatsAggregationMethod.AVERAGE |
|
|
|
) |
|
|
|
tb_writer.write_stats("category1", {"key1": statssummary1}, 10) |
|
|
|
|
|
|
|
|
|
|
def test_tensorboard_writer_clear(tmp_path): |
|
|
|
tb_writer = TensorboardWriter(tmp_path, clear_past_data=False) |
|
|
|
statssummary1 = StatsSummary( |
|
|
|
mean=1.0, |
|
|
|
std=1.0, |
|
|
|
num=1, |
|
|
|
sum=1.0, |
|
|
|
full_dist=[0.0], |
|
|
|
aggregation_method=StatsAggregationMethod.AVERAGE, |
|
|
|
full_dist=[1.0], aggregation_method=StatsAggregationMethod.AVERAGE |
|
|
|
) |
|
|
|
tb_writer.write_stats("category1", {"key1": statssummary1}, 10) |
|
|
|
# TB has some sort of timeout before making a new file |
|
|
|
|
|
|
category = "category1" |
|
|
|
console_writer = ConsoleWriter() |
|
|
|
statssummary1 = StatsSummary( |
|
|
|
mean=1.0, |
|
|
|
std=1.0, |
|
|
|
num=1, |
|
|
|
sum=1.0, |
|
|
|
full_dist=[1.0], |
|
|
|
aggregation_method=StatsAggregationMethod.AVERAGE, |
|
|
|
full_dist=[1.0], aggregation_method=StatsAggregationMethod.AVERAGE |
|
|
|
) |
|
|
|
console_writer.write_stats( |
|
|
|
category, |
|
|
|
|
|
|
10, |
|
|
|
) |
|
|
|
statssummary2 = StatsSummary( |
|
|
|
mean=0.0, |
|
|
|
std=0.0, |
|
|
|
num=1, |
|
|
|
sum=0.0, |
|
|
|
full_dist=[0.0], |
|
|
|
aggregation_method=StatsAggregationMethod.AVERAGE, |
|
|
|
full_dist=[0.0], aggregation_method=StatsAggregationMethod.AVERAGE |
|
|
|
) |
|
|
|
console_writer.write_stats( |
|
|
|
category, |
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
self.assertIn( |
|
|
|
"Mean Reward: 1.000. Std of Reward: 1.000. Training.", cm.output[0] |
|
|
|
"Mean Reward: 1.000. Std of Reward: 0.000. Training.", cm.output[0] |
|
|
|
) |
|
|
|
self.assertIn("Not Training.", cm.output[1]) |
|
|
|
|
|
|
|
|
|
|
console_writer = ConsoleWriter() |
|
|
|
console_writer.add_property(category, StatsPropertyType.SELF_PLAY, True) |
|
|
|
statssummary1 = StatsSummary( |
|
|
|
mean=1.0, |
|
|
|
std=1.0, |
|
|
|
num=1, |
|
|
|
sum=1.0, |
|
|
|
full_dist=[1.0], |
|
|
|
aggregation_method=StatsAggregationMethod.AVERAGE, |
|
|
|
full_dist=[1.0], aggregation_method=StatsAggregationMethod.AVERAGE |
|
|
|
) |
|
|
|
console_writer.write_stats( |
|
|
|
category, |
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
self.assertIn( |
|
|
|
"Mean Reward: 1.000. Std of Reward: 1.000. Training.", cm.output[0] |
|
|
|
"Mean Reward: 1.000. Std of Reward: 0.000. Training.", cm.output[0] |
|
|
|
) |