Skip to content

Fix IRV results contract for strategy polling - #57

Merged
fsargent merged 1 commit into
mainfrom
fix-irv-results-contract
Jul 17, 2026
Merged

Fix IRV results contract for strategy polling#57
fsargent merged 1 commit into
mainfrom
fix-irv-results-contract

Conversation

@fsargent

@fsargent fsargent commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • Restore IRV public results to the simulator contract: rank-vector ballots in, high-is-better candidate scores out
  • Remove IRV-specific winner/resultsFor behavior so polling and strategic targeting use generic Method semantics
  • Add regression coverage for IRV polling/winner selection on the transfer example

Tests

  • uv run python -m pytest

Made with Cursor

Summary by Sourcery

Align IRV simulator results with the generic method contract so polling and strategy use high-is-better candidate scores derived from finish order.

New Features:

  • Expose helper conversions between IRV rank-vector ballots, preference orderings, and score-style results.

Bug Fixes:

  • Ensure IRV resultsFor returns score-style results compatible with strategic polling and winner selection.

Enhancements:

  • Refactor IRV result computation to convert finish ordering into high-is-better candidate scores instead of returning winner-first ordering.

Tests:

  • Add regression test verifying IRV polling and winner selection preserve the simulator score contract on a transfer example electorate.

@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

IRV’s public results contract is restored to return high-is-better candidate scores from rank-vector ballots, IRV-specific resultsFor/winner behavior is removed in favor of generic Method semantics, and regression coverage is added to ensure IRV polling and winner selection behave correctly for strategy use cases.

Sequence diagram for updated IRV.results rank-vector handling

sequenceDiagram
    participant Consumer
    participant Irv
    participant rankVectorToPreference
    participant runIrv
    participant finishOrderToResults

    Consumer->>Irv: results(ballots)
    Irv->>Irv: convert ballots to list
    loop for each ballot
        Irv->>rankVectorToPreference: rankVectorToPreference(ballot)
        rankVectorToPreference-->>Irv: preference_order
    end
    Irv->>runIrv: runIrv(buildPreferenceSchedule(rankings), ncand)
    runIrv-->>Irv: finishOrder
    Irv->>finishOrderToResults: finishOrderToResults(finishOrder)
    finishOrderToResults-->>Irv: results_scores
    Irv-->>Consumer: results_scores
Loading

File-Level Changes

Change Details Files
Normalize IRV to use rank-vector ballots internally while exposing high-is-better score-style results and generic winner semantics.
  • Remove IRV-specific resultsFor wrapper that converted rank vectors to preference orders via a custom chooser.
  • Introduce a reusable helper to convert rank-vector ballots to descending preference candidate ID lists.
  • Change IRV.results to convert rank-vector ballots to preference rankings, run the IRV tabulator, and then convert finish order into high-is-better scores.
  • Update IRV’s winner usage in tests to reflect that winner now operates on score-style results rather than finish-order arrays.
methods.py
Add regression test to enforce IRV’s simulator results contract for strategy/polling scenarios.
  • Import Irv into regression tests to allow direct method usage.
  • Add a regression test that runs IRV via resultsFor on a mixed electorate, asserting the returned results vector, winner selection, and poll ordering all match the expected high-is-better score semantics.
test/test_regressions.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@fsargent, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cde876d8-7782-4ec7-9793-9e3ed551a906

📥 Commits

Reviewing files that changed from the base of the PR and between eaed9ab and ac1a532.

📒 Files selected for processing (2)
  • src/vse_sim/methods.py
  • tests/test_regressions.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-irv-results-contract

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsargent
fsargent force-pushed the fix-irv-results-contract branch from 5912a2a to 6105908 Compare July 17, 2026 22:07
Co-authored-by: Cursor <cursoragent@cursor.com>
@fsargent
fsargent force-pushed the fix-irv-results-contract branch from 6105908 to ac1a532 Compare July 17, 2026 22:14
@fsargent
fsargent merged commit 77f4057 into main Jul 17, 2026
5 checks passed
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.

1 participant