-
Notifications
You must be signed in to change notification settings - Fork 8
cli/explore: resumable output + run manifest #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guillon
merged 1 commit into
xtc-tools:main
from
guillon:dev/father/loop-explore-resume-manifest
Mar 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,120 @@ | ||
| import csv | ||
| from pathlib import Path | ||
|
|
||
| from xtc.cli.explore import CSVCallback | ||
|
|
||
|
|
||
| def _read_rows(path: Path) -> list[list[str]]: | ||
| with path.open(newline="") as infile: | ||
| return list(csv.reader(infile, delimiter=",")) | ||
|
|
||
|
|
||
| def test_csv_callback_resume_dedup_skips_existing_and_keeps_new(tmp_path: Path): | ||
| output = tmp_path / "results.csv" | ||
| sample_names = ["M", "N"] | ||
|
|
||
| # Existing output already has sample [8, 16] for backend mlir. | ||
| with output.open("w", newline="") as out: | ||
| writer = csv.writer(out, delimiter=",") | ||
| writer.writerow(sample_names + ["X", "time", "peak", "backend"]) | ||
| writer.writerow([8, 16, "[8; 16]", 0.2, 5.0, "mlir"]) | ||
|
|
||
| cb = CSVCallback( | ||
| str(output), | ||
| peak_time=1.0, | ||
| sample_names=sample_names, | ||
| resume=True, | ||
| ) | ||
|
|
||
| # Duplicate for same backend must be skipped in resume mode. | ||
| cb(([8, 16], 0, 0.2, "mlir")) | ||
| # Different backend for same sample must be recorded. | ||
| cb(([8, 16], 0, 0.25, "tvm")) | ||
| # Different sample must be recorded. | ||
| cb(([8, 32], 0, 0.3, "mlir")) | ||
| del cb | ||
|
|
||
| rows = _read_rows(output) | ||
|
|
||
| # Header + original row + two new rows. | ||
| assert len(rows) == 4 | ||
| assert rows[0] == ["M", "N", "X", "time", "peak", "backend"] | ||
|
|
||
| # Check appended rows (order matters). | ||
| assert rows[2][0:2] == ["8", "16"] | ||
| assert rows[2][-1] == "tvm" | ||
| assert rows[3][0:2] == ["8", "32"] | ||
| assert rows[3][-1] == "mlir" | ||
|
|
||
|
|
||
| def test_csv_callback_default_mode_overwrites_existing_file(tmp_path: Path): | ||
| output = tmp_path / "results.csv" | ||
| sample_names = ["M", "N"] | ||
|
|
||
| with output.open("w", newline="") as out: | ||
| writer = csv.writer(out, delimiter=",") | ||
| writer.writerow(sample_names + ["X", "time", "peak", "backend"]) | ||
| writer.writerow([9, 9, "[9; 9]", 0.9, 1.1, "mlir"]) | ||
|
|
||
| cb = CSVCallback( | ||
| str(output), | ||
| peak_time=2.0, | ||
| sample_names=sample_names, | ||
| ) | ||
|
|
||
| # Default mode is neither --resume nor --append, so file is rewritten. | ||
| cb(([2, 3], 0, 0.5, "mlir")) | ||
| del cb | ||
|
|
||
| rows = _read_rows(output) | ||
| assert rows[0] == ["M", "N", "X", "time", "peak", "backend"] | ||
| assert len(rows) == 2 | ||
| assert rows[1][0:2] == ["2", "3"] | ||
| assert rows[1][-1] == "mlir" | ||
|
|
||
|
|
||
| def test_csv_callback_append_mode_allows_duplicates(tmp_path: Path): | ||
| output = tmp_path / "results.csv" | ||
| sample_names = ["M", "N"] | ||
|
|
||
| with output.open("w", newline="") as out: | ||
| writer = csv.writer(out, delimiter=",") | ||
| writer.writerow(sample_names + ["X", "time", "peak", "backend"]) | ||
| writer.writerow([4, 4, "[4; 4]", 0.1, 10.0, "mlir"]) | ||
|
|
||
| cb = CSVCallback( | ||
| str(output), | ||
| peak_time=1.0, | ||
| sample_names=sample_names, | ||
| append=True, | ||
| ) | ||
|
|
||
| # Same sample/backend is allowed in append mode. | ||
| cb(([4, 4], 0, 0.12, "mlir")) | ||
| del cb | ||
|
|
||
| rows = _read_rows(output) | ||
|
|
||
| # Header + original row + duplicate appended row. | ||
| assert len(rows) == 3 | ||
| assert rows[1][0:2] == ["4", "4"] | ||
| assert rows[2][0:2] == ["4", "4"] | ||
| assert rows[1][-1] == "mlir" | ||
| assert rows[2][-1] == "mlir" | ||
|
|
||
|
|
||
| def test_csv_callback_append_writes_header_for_new_file(tmp_path: Path): | ||
| output = tmp_path / "results.csv" | ||
|
|
||
| cb = CSVCallback( | ||
| str(output), | ||
| peak_time=2.0, | ||
| sample_names=["M", "N"], | ||
| append=True, | ||
| ) | ||
| cb(([2, 3], 0, 0.5, "mlir")) | ||
| del cb | ||
|
|
||
| rows = _read_rows(output) | ||
| assert rows[0] == ["M", "N", "X", "time", "peak", "backend"] | ||
| assert rows[1][0:2] == ["2", "3"] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.