mggg / VoteKit

A Swiss Army Knife for computational social choice research
https://votekit.readthedocs.io/en/latest/
MIT License
8 stars 11 forks source link

Error in pl.generate_profile( ) in 1_intro.ipynb #131

Closed tratliff closed 6 days ago

tratliff commented 2 weeks ago

I just downloaded VoteKit and am working my way through the introductory notebooks.

In 1_intro.ipynb, I'm getting an "IndexError: list index out of range" error when I execute the first code block under "Blocs". This seems to point back to the pl.generate_profile() call:

IndexError Traceback (most recent call last) Cell In[11], line 27 21 pl = bg.slate_PlackettLuce(pref_intervals_by_bloc = pref_intervals_by_bloc, 22 bloc_voter_prop = bloc_voter_prop, 23 slate_to_candidates = slate_to_candidates, 24 cohesion_parameters=cohesion_parameters) 26 # the by_bloc parameter allows us to see which ballots came from which blocs of voters ---> 27 profile_dict, agg_profile = pl.generate_profile(number_of_ballots = 10000, by_bloc=True) 28 print(\"The ballots from Alpha voters\n", profile_dict[\"Alpha\"]) 30 print(\"The ballots from Xenon voters\n", profile_dict[\"Xenon\"])

File ~/miniconda3/envs/votekitENV/lib/python3.11/site-packages/votekit/ballot_generator.py:1571, in slate_PlackettLuce.generate_profile(self, number_of_ballots, by_bloc) 1568 ranking = [frozenset({-1})] * len(bt) 1569 for i, b in enumerate(bt): 1570 # append the current first candidate, then remove them from the ordering -> 1571 ranking[i] = frozenset({cand_ordering_by_bloc[b][0]}) 1572 cand_ordering_by_bloc[b].pop(0) 1574 if len(zero_cands) > 0:

IndexError: list index out of range

eveomett commented 1 week ago

I cloned VoteKit on May 30 and haven't updated it since. But I downloaded the 1_intro.ipynb and am getting the same error as @tratliff

cdonnay commented 1 week ago

Thanks for calling this to my attention! @eveomett @tratliff , could you try deleting your virtual environments and installing a fresh installation of votekit using pip install git+https://github.com/mggg/VoteKit.git ? My guess is that the version of votekit available on PyPI is a bit out of date, and that the version currently living in the repo fixes this error. Let me know if you need a hand with reinstalling a package. Sometimes pip really likes to use cached versions, in which case this stack exchange article might be helpful.

If this fix works, I'll be sure to get the newer version on PyPI ASAP!

tratliff commented 1 week ago

@cdonnay, Thanks! That solved it for me!

@eveomett

eveomett commented 1 week ago

@cdonnay worked for me too; thanks!

cdonnay commented 6 days ago

Fixed in release v2.0.1.