Skip to content

Add elsim.studies API and migrate Monte Carlo examples (#10)#52

Draft
endolith wants to merge 3 commits into
masterfrom
cursor/issue-10-simulation-api-44e5
Draft

Add elsim.studies API and migrate Monte Carlo examples (#10)#52
endolith wants to merge 3 commits into
masterfrom
cursor/issue-10-simulation-api-44e5

Conversation

@endolith
Copy link
Copy Markdown
Owner

@endolith endolith commented May 11, 2026

Summary

This PR addresses issue #10 with a new elsim.studies subpackage and refactors all Monte Carlo–style examples to use it.

elsim.studies (building blocks)

  • Parameters: expand_product, expand_zip, expand_rows — explicit Cartesian vs zipped vs fixed scenario rows.
  • Execution: SerialBackend / JoblibBackend with map_repeat and map_each (for functools.partial job lists).
  • Batching: run_batched, merge_counters.
  • Condorcet efficiency: merrill_1984_comparison_methods, tally_condorcet_agreement.
  • Social utility (new): spatial_random_reference_utility_updates, random_society_utility_updates, ranked_rated_utility_updates — shared per-election float totals for Merrill / Weber scripts.

hypothesis_election_finder.py is documented as Hypothesis-based search, not batched Monte Carlo, so it intentionally does not import studies.

weber_1977_expressions.py stays analytical only.

Examples

Parallel examples now use JoblibBackend instead of joblib.Parallel/delayed directly. Merrill / Weber loops use the tallies above where they match prior logic (including utility_winner(utilities) without tiebreaker for Weber effectiveness / Merrill Table 3 UW).

Tests

tests/test_studies.py covers expansion, backends, batching, Condorcet tallies, and the new social-utility helpers.

Other

  • joblib added to the test optional extra so CI exercises JoblibBackend.
  • Sphinx documents elsim.studies.
Open in Web Open in Cursor 

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>
@cursor cursor Bot changed the title Add elsim.studies API for Monte Carlo example scripts (closes #10) Add elsim.studies API for Monte Carlo example scripts (#10) May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 99.39759% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.09%. Comparing base (8a7213f) to head (b475a01).

Files with missing lines Patch % Lines
elsim/studies/parameters.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #52      +/-   ##
==========================================
+ Coverage   96.31%   97.09%   +0.77%     
==========================================
  Files          19       25       +6     
  Lines         489      654     +165     
==========================================
+ Hits          471      635     +164     
- Misses         18       19       +1     
Flag Coverage Δ
no-numba 96.48% <99.39%> (+0.98%) ⬆️
numba 91.74% <99.39%> (+2.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@cursor cursor Bot changed the title Add elsim.studies API for Monte Carlo example scripts (#10) Add elsim.studies API and migrate Monte Carlo examples (#10) May 11, 2026
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>
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