-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test now checks for files created (#43)
**Summary**: The old integration test just checked that Proto-X didn't crash. Now, it checks that files are actually created. **Details**: * The test is now Python-based instead of shell-based. * Using this test, I added functionality for analyzing a `.tfevents` file (a script I had previously written) and added a test for that as well.
- Loading branch information
1 parent
9e652d1
commit 6f27be5
Showing
46 changed files
with
473 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import json | ||
import logging | ||
import re | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import click | ||
import tensorflow | ||
from google.protobuf.json_format import MessageToJson | ||
from tensorflow.core.util.event_pb2 import Event | ||
|
||
from util.log import DBGYM_OUTPUT_LOGGER_NAME | ||
|
||
|
||
@click.group(name="analyze") | ||
def analyze_group() -> None: | ||
pass | ||
|
||
|
||
@click.command(name="tfevents") | ||
@click.argument("tfevents-path", type=Path) | ||
def analyze_tfevents(tfevents_path: Path) -> None: | ||
minimal_json = tboard_to_minimal_json(tfevents_path) | ||
logging.getLogger(DBGYM_OUTPUT_LOGGER_NAME).info( | ||
f"seconds spent resetting: {get_total_instr_time_event(minimal_json, r'.*PostgresEnv_reset$')}" | ||
) | ||
logging.getLogger(DBGYM_OUTPUT_LOGGER_NAME).info( | ||
f"seconds spent reconfiguring: {get_total_instr_time_event(minimal_json, r'.*PostgresEnv_shift_state$')}" | ||
) | ||
logging.getLogger(DBGYM_OUTPUT_LOGGER_NAME).info( | ||
f"seconds spent evaluating workload: {get_total_instr_time_event(minimal_json, r'.*Workload_execute$')}" | ||
) | ||
logging.getLogger(DBGYM_OUTPUT_LOGGER_NAME).info( | ||
f"seconds spent training agent: {get_total_instr_time_event(minimal_json, r'.*(WolpPolicy_train_actor|WolpPolicy_train_critic)$')}" | ||
) | ||
|
||
|
||
# The "minimal json" unwraps each summary so that we're left only with the parts that differ between summaries | ||
def tboard_to_minimal_json(tfevent_fpath: Path) -> list[dict[str, Any]]: | ||
minimal_json = [] | ||
|
||
raw_dataset = tensorflow.data.TFRecordDataset(tfevent_fpath) | ||
|
||
for raw_record in raw_dataset: | ||
event = Event() | ||
event.ParseFromString(raw_record.numpy()) | ||
|
||
# Convert event to JSON | ||
json_summary = json.loads(MessageToJson(event.summary)) | ||
|
||
# We get a {} at the very start | ||
if json_summary == {}: | ||
continue | ||
|
||
assert "value" in json_summary | ||
json_summary = json_summary["value"] | ||
assert len(json_summary) == 1 | ||
json_summary = json_summary[0] | ||
|
||
minimal_json.append(json_summary) | ||
|
||
return minimal_json | ||
|
||
|
||
# An "instr_time_event" is an event with a "tag" that looks like "instr_time/*" | ||
def get_total_instr_time_event( | ||
minimal_json: list[dict[str, Any]], event_regex: str | ||
) -> float: | ||
event_pattern = re.compile(event_regex) | ||
total_time = 0 | ||
|
||
for json_summary in minimal_json: | ||
if event_pattern.fullmatch(json_summary["tag"]) is not None: | ||
total_time += json_summary["simpleValue"] | ||
|
||
return total_time | ||
|
||
|
||
analyze_group.add_command(analyze_tfevents) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
from pathlib import Path | ||
|
||
from analyze.cli import get_total_instr_time_event, tboard_to_minimal_json | ||
|
||
|
||
class AnalyzeTests(unittest.TestCase): | ||
def test_tfevents(self) -> None: | ||
tfevents_path = Path("analyze/tests/unittest_analysis_files/out.tfevents") | ||
minimal_json = tboard_to_minimal_json(tfevents_path) | ||
self.assertAlmostEqual( | ||
get_total_instr_time_event(minimal_json, r".*PostgresEnv_reset$"), 8.0046994 | ||
) | ||
self.assertAlmostEqual( | ||
get_total_instr_time_event(minimal_json, r".*PostgresEnv_shift_state$"), | ||
12.4918935, | ||
) | ||
self.assertAlmostEqual( | ||
get_total_instr_time_event(minimal_json, r".*Workload_execute$"), | ||
31.831543260000004, | ||
) | ||
self.assertAlmostEqual( | ||
get_total_instr_time_event( | ||
minimal_json, r".*(WolpPolicy_train_actor|WolpPolicy_train_critic)$" | ||
), | ||
19.9834938712, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
pip freeze >dependencies/requirements.txt |
Oops, something went wrong.