Skip to content

Document voting method implementations - #59

Merged
fsargent merged 1 commit into
mainfrom
docs/method-docstrings
Jul 17, 2026
Merged

Document voting method implementations#59
fsargent merged 1 commit into
mainfrom
docs/method-docstrings

Conversation

@fsargent

@fsargent fsargent commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • add concise class docstrings for every voting method
  • document generated classes and factory behavior for Score, bullet approval, and SRV
  • clarify ballot scales, tabulation rules, and simulator result conventions

Stack

Depends on #58. Retarget this PR to main after #58 merges.

Validation

  • uv run python -m pytest (44 passed)
  • trunk check

Summary by Sourcery

Documentation:

  • Add concise, method-level docstrings describing ballot formats, rating scales, tabulation rules, and result semantics for IRV, IRV Prime, Score, SRV, V321, Borda, Bullety Approval, IRNR, Schulze, Ranked Pairs, Mav, Mj, and Plurality.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR adds detailed, consistent docstrings for all major voting method implementations and their factories, clarifying ballot formats, scoring scales, tabulation rules, and simulator result semantics, without changing functional behavior.

File-Level Changes

Change Details Files
Clarify Instant-Runoff Voting behavior and its IRV Prime variant.
  • Document IRV ballot representation, preference scale, and elimination/tabulation behavior.
  • Describe IRV Prime’s protection of the classic IRV winner and pairwise challengers with a reference link.
src/vse_sim/methods/irv.py
src/vse_sim/methods/irv_prime.py
Document score-based methods and their factories, including SRV and bullet approval variants.
  • Explain the Score factory’s rating scale, utility normalization, and class-return behavior via asClass.
  • Clarify SRV’s score runoff process, result encoding, and generated class scale semantics.
  • Describe BulletyApprovalWith’s mixture of normalized approval and bullet voting and the bullets parameter.
  • Add a docstring to the generated BulletyApproval class describing the configured mixture.
src/vse_sim/methods/score.py
src/vse_sim/methods/srv.py
src/vse_sim/methods/bullety_approval.py
Document ranked and Condorcet-style methods’ ballot formats and resolution rules.
  • Clarify Borda ballots, rank value semantics, honest ballot construction, and shared helpers.
  • Describe Schulze’s strongest-path Condorcet resolution and deterministic tiebreaks.
  • Explain Ranked Pairs’ use of Schulze’s interface and lock-in ordering.
  • Document Plurality ballots as binary favorite-only vectors.
src/vse_sim/methods/borda.py
src/vse_sim/methods/schulze.py
src/vse_sim/methods/ranked_pairs.py
src/vse_sim/methods/plurality.py
Document approval/majority-style rating methods and their result encoding.
  • Explain Majority Approval Voting’s five-grade ballots, percentile-based grades, and median-with-fractional-tiebreak ordering.
  • Describe Majority Judgment’s use of Mav’s grade ballots and refinement of the median via adjacent grade balance.
  • Clarify 3-2-1 Voting’s three-level ratings, advancement/elimination steps, and how simulator result values encode the candidate ordering.
src/vse_sim/methods/mav.py
src/vse_sim/methods/mj.py
src/vse_sim/methods/v321.py
Clarify IRNR’s normalized rating elimination process.
  • Document per-round normalization of remaining candidates’ ratings and elimination of the lowest normalized total until a single winner remains.
src/vse_sim/methods/irnr.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

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 648c37e2-f68a-4d5a-99cf-1111f4d26370

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/method-docstrings

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 found 2 issues, and left some high level feedback:

  • For the factory functions (Score, Srv, BulletyApprovalWith), consider being explicit in the docstrings about the exact return type (instance vs. subclass) and any expectations about subclassing, so users understand how to compose these with other method factories.
  • Where you mention that "larger values indicate stronger preference" or encode candidate ordering, it may help to explicitly state whether results are normalized scores, raw tallies, or ordinal ranks to avoid ambiguity when interpreting simulator outputs across different methods.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- For the factory functions (Score, Srv, BulletyApprovalWith), consider being explicit in the docstrings about the exact return type (instance vs. subclass) and any expectations about subclassing, so users understand how to compose these with other method factories.
- Where you mention that "larger values indicate stronger preference" or encode candidate ordering, it may help to explicitly state whether results are normalized scores, raw tallies, or ordinal ranks to avoid ambiguity when interpreting simulator outputs across different methods.

## Individual Comments

### Comment 1
<location path="src/vse_sim/methods/borda.py" line_range="8-10" />
<code_context>


 class Borda(Method):
+    """Implement Borda count with larger rank values representing preference.
+
+    Honest ballots assign consecutive scores from least to most preferred.
+    Ranked methods also inherit this class's ballot construction and strategy
+    helpers.
</code_context>
<issue_to_address>
**suggestion:** Clarify how ranks map to preferences and scores to avoid confusion with conventional Borda.

The phrases "larger rank values representing preference" and "consecutive scores from least to most preferred" are unclear, especially since classical Borda typically treats smaller ranks as more preferred. If this implementation reverses that convention (e.g., 0 = least preferred and higher values = more preferred), please state that explicitly and add a brief example ballot to illustrate the ranking and scoring direction for readers familiar with standard Borda.
</issue_to_address>

### Comment 2
<location path="src/vse_sim/methods/bullety_approval.py" line_range="8-12" />
<code_context>


 def BulletyApprovalWith(bullets=0.5, asClass=False):
+    """Create approval voting with a configurable share of bullet voters.

-
+    Each honest ballot is either ordinary normalized approval or a bullet vote
+    for all utility-maximizing candidates. ``bullets`` is the probability of
+    bullet voting.
+    """
</code_context>
<issue_to_address>
**suggestion:** Tighten the description of how `bullets` is interpreted and any expected range.

The current docstring doesn’t specify the expected range for `bullets` or how the probability is applied. Please clarify that `bullets` is a float in [0, 1] and that it’s applied independently per honest ballot (e.g., “`bullets` is the independent probability that an honest voter casts a bullet ballot rather than a normalized approval ballot”). This will help avoid misconfiguration.
</issue_to_address>

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.

Comment on lines +8 to +10
"""Implement Borda count with larger rank values representing preference.

Honest ballots assign consecutive scores from least to most preferred.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Clarify how ranks map to preferences and scores to avoid confusion with conventional Borda.

The phrases "larger rank values representing preference" and "consecutive scores from least to most preferred" are unclear, especially since classical Borda typically treats smaller ranks as more preferred. If this implementation reverses that convention (e.g., 0 = least preferred and higher values = more preferred), please state that explicitly and add a brief example ballot to illustrate the ranking and scoring direction for readers familiar with standard Borda.

Comment on lines 8 to +12
def BulletyApprovalWith(bullets=0.5, asClass=False):
"""Create approval voting with a configurable share of bullet voters.


Each honest ballot is either ordinary normalized approval or a bullet vote
for all utility-maximizing candidates. ``bullets`` is the probability of

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Tighten the description of how bullets is interpreted and any expected range.

The current docstring doesn’t specify the expected range for bullets or how the probability is applied. Please clarify that bullets is a float in [0, 1] and that it’s applied independently per honest ballot (e.g., “bullets is the independent probability that an honest voter casts a bullet ballot rather than a normalized approval ballot”). This will help avoid misconfiguration.

@fsargent
fsargent changed the base branch from refactor/methods-package to main July 17, 2026 22:33
@fsargent
fsargent merged commit 1b39df7 into main Jul 17, 2026
2 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