Skip to content

Commit

Permalink
Ignore tag order while checking their occurrences (strict_tags) (#36)
Browse files Browse the repository at this point in the history
* ignore tag order

* keep the event file sort since input_dirs could be already sorted

* remove sorted() when setting all_dirs_tags_list (now named tags_in_each_dir)

refactor missing_tags_report

* update pre-commit hooks

---------

Co-authored-by: HeinrichAD <[email protected]>
Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent 1ace02f commit cca47fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ default_install_hook_types: [pre-commit, commit-msg]

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.284
rev: v0.0.290
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black-jupyter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
rev: v1.5.1
hooks:
- id: mypy

Expand Down
21 changes: 10 additions & 11 deletions tensorboard_reducer/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,21 @@ def load_tb_events(
# strict_tags=False.
if strict_tags:
# generate list of scalar tags for all event files each in alphabetical order
all_dirs_tags_list = sorted(
accumulator.scalar_tags for accumulator in accumulators
)
first_tags = all_dirs_tags_list[0]

all_runs_same_tags = all(first_tags == tags for tags in all_dirs_tags_list)
tags_in_each_dir = [
set(accumulator.scalar_tags) for accumulator in accumulators
]

tags_set = {tag for tags in all_dirs_tags_list for tag in tags}
all_tags = {tag for tags in tags_in_each_dir for tag in tags}

# generate report of missing tags for each run directory
# will be empty string if no tags are missing
missing_tags_report = "".join(
f"- {in_dir} missing tags: {', '.join(tags_set - {*tags})}\n"
for in_dir, tags in zip(input_dirs, all_dirs_tags_list)
if len(tags_set - {*tags}) > 0
f"- {in_dir} missing tags: {', '.join(all_tags - run_tags)}\n"
for in_dir, run_tags in zip(input_dirs, tags_in_each_dir)
if len(all_tags - run_tags) > 0
)

if not all_runs_same_tags:
if missing_tags_report:
raise ValueError(
f"Some tags are in some logs but not others:\n{missing_tags_report}"
"\nIf intentional, pass CLI flag --lax-tags or strict_tags=False "
Expand Down

0 comments on commit cca47fa

Please sign in to comment.