Skip to content

Studies API: declarative spatial sweeps, remove JoblibBackend and hardcoded Merrill methods#56

Draft
endolith wants to merge 4 commits into
masterfrom
cursor/declarative-spatial-studies-44e5
Draft

Studies API: declarative spatial sweeps, remove JoblibBackend and hardcoded Merrill methods#56
endolith wants to merge 4 commits into
masterfrom
cursor/declarative-spatial-studies-44e5

Conversation

@endolith
Copy link
Copy Markdown
Owner

Summary

This addresses feedback that JoblibBackend only wrapped joblib without shortening scripts, that merrill_1984_comparison_methods hardcoded a method set callers should own, and that Merrill-style examples should read as declarative scenario + method maps + one aggregation call.

Changes

  • Removed merrill_1984_comparison_methods and JoblibBackend (examples use joblib.Parallel / delayed directly again; SerialBackend remains for run_batched).
  • Added approval_at_optimal in condorcet_metrics so rated-method dicts avoid repeating lambdas without shipping a full comparison preset.
  • Added elsim.studies.spatial_normal:
    • accumulate_spatial_condorcet_by_ncands — one call replaces the nested n_elections × n_cands_list × draw × tally_condorcet_agreement loop for spatial normal electorates (figures 2.c / 2.d pattern).
    • accumulate_spatial_sue_by_ncands — same for social-utility totals + random reference (figures 4.a / 4.b pattern).
  • Restored the tighter pipe-table layout in the merrill_1984_fig_4a_4b.py docstring (matches the pre-refactor column widths).
  • Simplified merrill_1984_fig_2a_2b.py to for disp in (0.5, 1.0): instead of expand_product for a single axis.
  • Updated Merrill tables 1 / 2 / 4 to define ranked_methods / rated_methods locally with approval_at_optimal.

Tests

  • Adjusted tests/test_studies.py (removed backend-specific tests; added coverage for the new accumulators and approval_at_optimal).

Branch: cursor/declarative-spatial-studies-44e5.

Open in Web Open in Cursor 

cursoragent and others added 4 commits May 11, 2026 15:23
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>
Remove the hardcoded merrill_1984_comparison_methods factory and the thin
JoblibBackend wrapper. Add approval_at_optimal for declarative rated-method
maps, plus accumulate_spatial_condorcet_by_ncands and
accumulate_spatial_sue_by_ncands for the shared Merrill-style nested loops.

Merrill spatial examples now declare n_voters, n_cands_list, corr, disp, and
method dicts, then call one accumulator per figure. Examples that only needed
parallelism use joblib.Parallel again. Restore narrower docstring tables in
merrill_1984_fig_4a_4b. Simplify merrill_1984_fig_2a_2b to a plain dispersion
loop.

Co-authored-by: endolith <endolith@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

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

Files with missing lines Patch % Lines
elsim/studies/parameters.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
+ Coverage   96.31%   97.12%   +0.80%     
==========================================
  Files          19       26       +7     
  Lines         489      661     +172     
==========================================
+ Hits          471      642     +171     
- Misses         18       19       +1     
Flag Coverage Δ
no-numba 96.52% <99.42%> (+1.01%) ⬆️
numba 91.83% <99.42%> (+2.66%) ⬆️

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.

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