Add elsim.studies API and migrate Monte Carlo examples (closes #10)#52
Open
endolith wants to merge 7 commits into
Open
Add elsim.studies API and migrate Monte Carlo examples (closes #10)#52endolith wants to merge 7 commits into
endolith wants to merge 7 commits into
Conversation
elsim.studies API for Monte Carlo example scripts (closes #10)elsim.studies API for Monte Carlo example scripts (#10)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 96.37% 97.27% +0.90%
==========================================
Files 17 23 +6
Lines 496 661 +165
==========================================
+ Hits 478 643 +165
Misses 18 18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
elsim.studies API for Monte Carlo example scripts (#10)elsim.studies API and migrate Monte Carlo examples (#10)
Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.14 to 0.15.15. - [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases) - [Commits](astral-sh/ruff-pre-commit@v0.15.14...v0.15.15) --- updated-dependencies: - dependency-name: https://github.com/astral-sh/ruff-pre-commit dependency-version: 0.15.15 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
b475a01 to
295ca19
Compare
elsim.studies API and migrate Monte Carlo examples (#10)Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.15 to 0.15.16. - [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases) - [Commits](astral-sh/ruff-pre-commit@v0.15.15...v0.15.16) --- updated-dependencies: - dependency-name: https://github.com/astral-sh/ruff-pre-commit dependency-version: 0.15.16 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
Introduce parameter expansion helpers (expand_product, expand_zip, expand_rows), serial and Joblib backends with map_repeat and map_each, run_batched and merge_counters, and Merrill-style Condorcet-efficiency tallies. Refactor three examples to use the new helpers, document the module in Sphinx, add tests, and include joblib in the test extra for CI. Co-authored-by: endolith <endolith@gmail.com>
Add social_utility helpers for Merrill/Weber-style utility totals. Refactor every batch-style example to use JoblibBackend (or studies metrics) instead of raw joblib, document the Hypothesis script as out of scope, and restore tabulate/elapsed output where tooling had stripped it. Co-authored-by: endolith <endolith@gmail.com>
Exercise social_utility branches, runner edge cases, parameter helpers, Serial/Joblib backend error paths (including simulated missing joblib), and Merrill Condorcet rated-method tallies. Use Optional[str] for UW tiebreaker annotation for Python 3.8. Co-authored-by: endolith <endolith@gmail.com>
Co-authored-by: endolith <endolith@gmail.com>
Co-authored-by: endolith <endolith@gmail.com>
295ca19 to
05e3b98
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
elsim.studies, a small orchestration layer for Monte Carlo election studies (issue #10). Theelections/strategies/methodsmodules remain the core simulation model;studiesonly handles parameter expansion, batched trial execution, result merging, and shared tallies used across paper-reproduction scripts.Rebased onto
master(2025-06-12). One conflict inelsim/__init__.pyresolved in favor of this PR's design: relative imports andstudiesexported alongside the existing submodules.Scope —
elsim.studiesAPIparametersexpand_product,expand_zip,expand_rows— Cartesian product, zipped columns, and explicit scenario rowsbackendsSerialBackend,JoblibBackend— swappable execution forrun_batchedrunnerrun_batched,merge_counters— batched trials and Counter aggregationcondorcet_metricsmerrill_1984_comparison_methods,tally_condorcet_agreement— shared Condorcet-paradox talliessocial_utilityspatial_random_reference_utility_updates,random_society_utility_updates,ranked_rated_utility_updates— per-election utility increments for Merrill/Weber-style tablesSphinx docs:
docs/elsim.studies.rst. Tests:tests/test_studies.py.Migrated examples (21 scripts)
All Monte Carlo / batch-reproduction scripts now use
elsim.studieshelpers instead of ad-hocjoblibloops:distributions_by_dispersion.py,distributions_by_method.py,distributions_by_method_2D.py,distributions_by_n_cands.pymerrill_1984_table_1_fig_1.py,merrill_1984_table_2.py,merrill_1984_table_3_fig_3.py,merrill_1984_table_4.py,merrill_1984_fig_2a_2b.py,merrill_1984_fig_2c_2d.py,merrill_1984_fig_2c_2d_updated.py,merrill_1984_fig_4a_4b.py,merrill_1984_fig_4a_4b_updated.pyniemi_1968_table_1.py,niemi_1968_table_2.pyweber_1977_table_4.py,weber_1977_effectiveness_table.py,weber_1977_verify_vote_for_k.pytomlinson_2023_figure_3.py,tomlinson_2023_figure_3_updated.pywikipedia_condorcet_paradox_likelihood.pyNot migrated (intentional)
hypothesis_election_finder.pyweber_1977_expressions.pyOut of scope — PR #56
PR #56 (
cursor/declarative-spatial-studies-44e5) explores a separate, declarative spatial-study API. This PR does not include or depend on that approach. The two designs can be evaluated independently; merging this PR does not preclude a future declarative layer.CI
masterruff check . --select=E9,F63,F7,F82— passpytest— 251 tests pass locally (Python 3.12)Closes #10.