Skip to content

FEAT: sort scenario per-group breakdown by success rate#1809

Merged
hannahwestra25 merged 5 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25/sort-scenario-results-by-success
May 26, 2026
Merged

FEAT: sort scenario per-group breakdown by success rate#1809
hannahwestra25 merged 5 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25/sort-scenario-results-by-success

Conversation

@hannahwestra25
Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in sort_groups_by_success_rate parameter to PrettyScenarioResultPrinter (and the PrettyScenarioResultMemoryPrinter subclass). When enabled, the Per-Group Breakdown section is rendered with the highest-success-rate group at the top, making it easier to scan results at a glance.

Behavior

  • Default is False — current insertion-order behavior is unchanged.
  • Sort is stable, so groups that tie on success rate keep their original relative order.
  • The per-group rate is computed once and reused for both sorting and rendering.

Usage

from pyrit.output.scenario_result.pretty import PrettyScenarioResultMemoryPrinter

printer = PrettyScenarioResultMemoryPrinter(sort_groups_by_success_rate=True)
await printer.write_async(scenario_result)

Tests

Added 3 new tests covering:

  • Default insertion order is preserved when the flag is off.
  • Groups are sorted descending by success rate when the flag is on.
  • Sort is stable for ties.

All 167 existing tests in tests/unit/output/ continue to pass; pre-commit (ruff, ty) is clean.

hannahwestra25 and others added 3 commits May 26, 2026 13:32
Add an opt-in 'sort_groups_by_success_rate' parameter to PrettyScenarioResultPrinter (and its memory subclass). When enabled, the Per-Group Breakdown section renders groups in descending success-rate order so the most successful groups appear at the top. Sort is stable, so ties keep their original ordering. Default behavior is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Surface the new sort flag on output_scenario_async and add a section to doc/code/scenarios/1_common_scenario_parameters that shows how to render the Per-Group Breakdown with the most successful groups at the top.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the sort_groups_by_success_rate example to follow the baseline run, where the default strategy set produces enough rows to make sorting visibly useful.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hannahwestra25 hannahwestra25 marked this pull request as ready for review May 26, 2026 18:04
hannahwestra25 and others added 2 commits May 26, 2026 14:22
Inject the sorted rendering of baseline_result into the sort_groups_by_success_rate cell so the notebook visibly demonstrates the feature — base64 (100%) and the three 50% strategies float to the top, 0% groups fall through in their original order.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review feedback on the per-group sort: store (name, count, rate) tuples with parameterized types, drop the redundant len(group_results) call in the render loop, and add a test that verifies output_scenario_async forwards sort_groups_by_success_rate to the printer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hannahwestra25 hannahwestra25 added this pull request to the merge queue May 26, 2026
Merged via the queue into microsoft:main with commit e4404fe May 26, 2026
47 checks passed
@hannahwestra25 hannahwestra25 deleted the hannahwestra25/sort-scenario-results-by-success branch May 26, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants