-
Notifications
You must be signed in to change notification settings - Fork 29
refactor: switch block prod test to mixed UTxO backends #3259
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/usr/bin/env python3 | ||
| """Generate a bar chart of total blocks per backend from an SQLite database. | ||
| The script retrieves the latest run_id from the runs table, aggregates the total | ||
| blocks per backend from the blocks table, and generates a bar chart saved as an image file. | ||
| """ | ||
|
|
||
| import argparse | ||
| import contextlib | ||
| import pathlib as pl | ||
| import sqlite3 | ||
| import sys | ||
|
|
||
| import matplotlib.container as mcontainer | ||
| import matplotlib.pyplot as plt | ||
| import pandas as pd | ||
| import seaborn as sns | ||
|
|
||
|
|
||
| def get_latest_run_id(conn: sqlite3.Connection) -> str: | ||
| """Return the latest run_id from the runs table. | ||
| Assumes "latest" means last inserted row (highest rowid). | ||
| """ | ||
| cur = conn.cursor() | ||
| cur.execute("SELECT run_id FROM runs ORDER BY rowid DESC LIMIT 1;") | ||
| row = cur.fetchone() | ||
| if row is None: | ||
| err = "No runs found in 'runs' table." | ||
| raise RuntimeError(err) | ||
| return str(row[0]) | ||
|
|
||
|
|
||
| def get_blocks_per_backend(conn: sqlite3.Connection, *, run_id: str) -> list[tuple[str, int]]: | ||
| """Return a list of (backend, total_blocks) for the given run_id. | ||
| Aggregates num_blocks across all epochs and pools. | ||
| """ | ||
| cur = conn.cursor() | ||
| cur.execute( | ||
| """ | ||
| SELECT backend, SUM(num_blocks) AS total_blocks | ||
| FROM blocks | ||
| WHERE run_id = ? | ||
| GROUP BY backend | ||
| ORDER BY total_blocks DESC; | ||
| """, | ||
| (run_id,), | ||
| ) | ||
| rows = cur.fetchall() | ||
| if not rows: | ||
| err = f"No block data found in 'blocks' table for run_id={run_id}." | ||
| raise RuntimeError(err) | ||
| return rows | ||
|
|
||
|
|
||
| def plot_backend_blocks( | ||
| backend_data: list[tuple[str, int]], *, run_name: str, output_path: pl.Path | ||
| ) -> None: | ||
| """Plot a bar chart of total blocks per backend.""" | ||
| backends = [b for b, _ in backend_data] | ||
| totals = [t for _, t in backend_data] | ||
| df = pd.DataFrame({"backend": backends, "total_blocks": totals}) | ||
|
|
||
| sns.set_theme(style="whitegrid") | ||
|
|
||
| plt.figure(figsize=(8, 5)) | ||
| ax = sns.barplot(data=df, x="backend", y="total_blocks") | ||
|
|
||
| ax.set_xlabel("Backend") | ||
| ax.set_ylabel("Total blocks over run") | ||
| ax.set_title(f"Total blocks per backend in run {run_name}") | ||
|
|
||
| # Annotate bars with values (type-narrow containers to BarContainer) | ||
| for c in ax.containers: | ||
| if isinstance(c, mcontainer.BarContainer): | ||
| ax.bar_label(c) | ||
mkoura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| plt.tight_layout() | ||
| plt.savefig(output_path, dpi=150) | ||
| plt.close() | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser( | ||
| description=( | ||
| "Generate a bar chart of total blocks per backend for the latest run " | ||
| "from an SQLite database." | ||
| ) | ||
| ) | ||
| parser.add_argument( | ||
| "-d", | ||
| "--dbpath", | ||
| required=True, | ||
| help="Path to the SQLite database file.", | ||
| ) | ||
| parser.add_argument( | ||
| "-n", | ||
| "--name", | ||
| required=True, | ||
| help="Name of the run (for labeling purposes).", | ||
| ) | ||
| parser.add_argument( | ||
| "-o", | ||
| "--output", | ||
| required=True, | ||
| help="Output image filename.", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main() -> int: | ||
| args = parse_args() | ||
| dbpath = pl.Path(args.dbpath) | ||
| output_path = pl.Path(args.output) | ||
|
|
||
| if not dbpath.exists(): | ||
| print(f"Error: database file '{args.dbpath}' does not exist.", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| try: | ||
| with contextlib.closing(sqlite3.connect(dbpath)) as conn, conn: | ||
| run_id = get_latest_run_id(conn) | ||
| backend_data = get_blocks_per_backend(conn, run_id=run_id) | ||
| plot_backend_blocks( | ||
| backend_data=backend_data, run_name=args.name, output_path=output_path | ||
| ) | ||
| except (sqlite3.Error, RuntimeError) as e: | ||
| print(f"Error: {e}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| print(f"Saved graph to {args.output}") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.