Skip to content

Commit

Permalink
Fix multiprocessing pool map
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Feb 27, 2024
1 parent dfd616d commit 3dd3546
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions acto/post_process/post_diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import difflib
import glob
import hashlib
import itertools
import json
import logging
import multiprocessing
Expand Down Expand Up @@ -960,31 +961,40 @@ def __get_diff_paths(
original_result = self.trial_to_steps[trial_basename].steps[
str(gen)
]
args.append((diff_test_result, original_result, self.config))
args.append([diff_test_result, original_result, self.config])

with multiprocessing.Pool(num_workers) as pool:
diff_results = pool.map(self.check_diff_test_step, args)
diff_results = pool.starmap(__get_diff_paths_helper, args)

diff_result = self.check_diff_test_step(
diff_test_result, original_result, self.config
)

for diff_result in diff_results:
if diff_result is not None:
for diff in diff_result.diff.values():
if not isinstance(diff, list):
continue
for diff_item in diff:
if not isinstance(diff_item, DiffLevel):
continue
indeterministic_regex.add(diff_item.path())
for diff_item in itertools.chain.from_iterable(diff_results):
indeterministic_regex.add(diff_item)

# Handle the case where the name is not deterministic
common_regex = compute_common_regex(list(indeterministic_regex))

return common_regex

Check warning on line 975 in acto/post_process/post_diff_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 954-975


def __get_diff_paths_helper(
diff_test_result: DiffTestResult,
original_result: Step,
config: OperatorConfig,
) -> list[str]:
diff_result = PostDiffTest.check_diff_test_step(
diff_test_result, original_result, config
)
indeterministic_regex = set()
if diff_result is not None:
for diff in diff_result.diff.values():
if not isinstance(diff, list):
continue
for diff_item in diff:
if not isinstance(diff_item, DiffLevel):
continue
indeterministic_regex.add(diff_item.path())
return list(indeterministic_regex)

Check warning on line 995 in acto/post_process/post_diff_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 983-995


def main():
"""Main entry point."""
parser = argparse.ArgumentParser()
Expand Down

0 comments on commit 3dd3546

Please sign in to comment.