vse-sim 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vse_sim-0.1.0/LICENSE +20 -0
- vse_sim-0.1.0/MANIFEST.in +4 -0
- vse_sim-0.1.0/PKG-INFO +171 -0
- vse_sim-0.1.0/README.md +121 -0
- vse_sim-0.1.0/compat.py +47 -0
- vse_sim-0.1.0/dataClasses.py +354 -0
- vse_sim-0.1.0/debugDump.py +11 -0
- vse_sim-0.1.0/docs/INSTALL.md +92 -0
- vse_sim-0.1.0/docs/PUBLISHING.md +98 -0
- vse_sim-0.1.0/methods.py +1158 -0
- vse_sim-0.1.0/mydecorators.py +193 -0
- vse_sim-0.1.0/pyproject.toml +139 -0
- vse_sim-0.1.0/setup.cfg +4 -0
- vse_sim-0.1.0/sodaTest.py +429 -0
- vse_sim-0.1.0/stratFunctions.py +205 -0
- vse_sim-0.1.0/test/test_binop.py +3 -0
- vse_sim-0.1.0/test/test_core_coverage.py +449 -0
- vse_sim-0.1.0/test/test_package_imports.py +53 -0
- vse_sim-0.1.0/test/test_simulation_coverage.py +206 -0
- vse_sim-0.1.0/test/test_soda_coverage.py +306 -0
- vse_sim-0.1.0/tests.py +23 -0
- vse_sim-0.1.0/voterModels.py +404 -0
- vse_sim-0.1.0/vse.py +179 -0
- vse_sim-0.1.0/vse_sim/__init__.py +105 -0
- vse_sim-0.1.0/vse_sim/compat.py +14 -0
- vse_sim-0.1.0/vse_sim/data_classes.py +23 -0
- vse_sim-0.1.0/vse_sim/methods.py +35 -0
- vse_sim-0.1.0/vse_sim/simulation.py +12 -0
- vse_sim-0.1.0/vse_sim/strategies.py +35 -0
- vse_sim-0.1.0/vse_sim/voter_models.py +35 -0
- vse_sim-0.1.0/vse_sim.egg-info/PKG-INFO +171 -0
- vse_sim-0.1.0/vse_sim.egg-info/SOURCES.txt +33 -0
- vse_sim-0.1.0/vse_sim.egg-info/dependency_links.txt +1 -0
- vse_sim-0.1.0/vse_sim.egg-info/requires.txt +34 -0
- vse_sim-0.1.0/vse_sim.egg-info/top_level.txt +11 -0
vse_sim-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Barry Clark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
vse_sim-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vse-sim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Voter Satisfaction Efficiency simulation tools for voting systems.
|
|
5
|
+
Author: VSE Sim contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/wclark/vse-sim
|
|
8
|
+
Project-URL: Documentation, http://electionscience.github.io/vse-sim/
|
|
9
|
+
Project-URL: Issues, https://github.com/wclark/vse-sim/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/wclark/vse-sim
|
|
11
|
+
Keywords: elections,simulation,voting,voter satisfaction efficiency
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
26
|
+
Provides-Extra: lint
|
|
27
|
+
Requires-Dist: ruff; extra == "lint"
|
|
28
|
+
Requires-Dist: tomli; extra == "lint"
|
|
29
|
+
Requires-Dist: validate-pyproject; extra == "lint"
|
|
30
|
+
Provides-Extra: audit
|
|
31
|
+
Requires-Dist: pip-audit; extra == "audit"
|
|
32
|
+
Provides-Extra: build-check
|
|
33
|
+
Requires-Dist: check-wheel-contents; extra == "build-check"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: build; extra == "dev"
|
|
36
|
+
Requires-Dist: check-wheel-contents; extra == "dev"
|
|
37
|
+
Requires-Dist: nox; extra == "dev"
|
|
38
|
+
Requires-Dist: pip-audit; extra == "dev"
|
|
39
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: tomli; extra == "dev"
|
|
44
|
+
Requires-Dist: twine; extra == "dev"
|
|
45
|
+
Requires-Dist: validate-pyproject; extra == "dev"
|
|
46
|
+
Provides-Extra: publish
|
|
47
|
+
Requires-Dist: build; extra == "publish"
|
|
48
|
+
Requires-Dist: twine; extra == "publish"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# Voter Satisfaction Efficiency
|
|
52
|
+
|
|
53
|
+
These are some methods for running VSE (Voter Satisfaction Efficiency)
|
|
54
|
+
simulations for various voting systems.
|
|
55
|
+
|
|
56
|
+
See [Voter Satisfaction Efficiency FAQ](http://electionscience.github.io/vse-sim/) for an explanation of the methods and results.
|
|
57
|
+
|
|
58
|
+
## Installing the code
|
|
59
|
+
|
|
60
|
+
Requirements: Python 3.10+, NumPy, SciPy.
|
|
61
|
+
|
|
62
|
+
For notebook and library-style usage, install the package into the active
|
|
63
|
+
environment:
|
|
64
|
+
|
|
65
|
+
python -m pip install .
|
|
66
|
+
|
|
67
|
+
To install directly from GitHub:
|
|
68
|
+
|
|
69
|
+
python -m pip install "vse-sim @ git+https://github.com/wclark/vse-sim.git@main"
|
|
70
|
+
|
|
71
|
+
That exposes the modern `vse_sim` package namespace:
|
|
72
|
+
|
|
73
|
+
from vse_sim import CsvBatch, Mav, PolyaModel, Score, baseRuns, medianRuns
|
|
74
|
+
|
|
75
|
+
The legacy top-level modules remain installed and importable for existing
|
|
76
|
+
scripts and examples:
|
|
77
|
+
|
|
78
|
+
from vse import CsvBatch
|
|
79
|
+
from voterModels import PolyaModel
|
|
80
|
+
|
|
81
|
+
See [Notebook and GitHub installation](docs/INSTALL.md) for Jupyter examples,
|
|
82
|
+
GitHub install variants, and the future PyPI install path.
|
|
83
|
+
|
|
84
|
+
Testing uses doctests, which should make most things pretty self-documenting.
|
|
85
|
+
For development, install the project in editable mode with the test, lint, and
|
|
86
|
+
publishing helpers:
|
|
87
|
+
|
|
88
|
+
python -m pip install -e ".[dev,publish]"
|
|
89
|
+
|
|
90
|
+
Optionally install the local Git hooks:
|
|
91
|
+
|
|
92
|
+
pre-commit install
|
|
93
|
+
|
|
94
|
+
The main local readiness checks can also be run through Nox:
|
|
95
|
+
|
|
96
|
+
nox
|
|
97
|
+
|
|
98
|
+
Then run the legacy doctest examples:
|
|
99
|
+
|
|
100
|
+
python3 -m doctest methods.py
|
|
101
|
+
python3 -m doctest voterModels.py
|
|
102
|
+
python3 -m doctest dataClasses.py
|
|
103
|
+
python3 vse.py
|
|
104
|
+
|
|
105
|
+
Run the full test and coverage gate:
|
|
106
|
+
|
|
107
|
+
python -m pytest --doctest-modules --cov=. --cov-fail-under=100
|
|
108
|
+
|
|
109
|
+
To generate the same local coverage artifacts that CI uploads:
|
|
110
|
+
|
|
111
|
+
python -m pytest --doctest-modules --cov=. --cov-fail-under=100 --cov-report=term-missing:skip-covered --cov-report=xml:coverage.xml --cov-report=html:htmlcov --junitxml=pytest-results.xml
|
|
112
|
+
|
|
113
|
+
To run lint and style checks locally:
|
|
114
|
+
|
|
115
|
+
validate-pyproject pyproject.toml
|
|
116
|
+
python -m ruff check .
|
|
117
|
+
python -m ruff format --check .
|
|
118
|
+
|
|
119
|
+
To build and check package distributions locally:
|
|
120
|
+
|
|
121
|
+
python -m build
|
|
122
|
+
python -m twine check dist/*
|
|
123
|
+
check-wheel-contents dist/*.whl
|
|
124
|
+
|
|
125
|
+
To audit runtime dependencies for known vulnerabilities:
|
|
126
|
+
|
|
127
|
+
python -m pip_audit --skip-editable --progress-spinner off .
|
|
128
|
+
|
|
129
|
+
The GitHub Actions workflow runs the same coverage check on pushes, pull requests,
|
|
130
|
+
and manual dispatches. It uploads the HTML coverage report plus machine-readable
|
|
131
|
+
coverage and JUnit XML files as workflow artifacts.
|
|
132
|
+
|
|
133
|
+
The same workflow also builds the wheel and source distribution, installs the
|
|
134
|
+
wheel into a clean environment, checks the distributions with Twine, and uploads
|
|
135
|
+
the package artifacts.
|
|
136
|
+
|
|
137
|
+
The `Lint and Style` workflow validates `pyproject.toml`, then runs Ruff
|
|
138
|
+
formatting and lint checks on pushes, pull requests, and manual dispatches.
|
|
139
|
+
|
|
140
|
+
## Security automation
|
|
141
|
+
|
|
142
|
+
GitHub Actions also runs CodeQL code scanning for Python on pushes, pull
|
|
143
|
+
requests, a weekly schedule, and manual dispatches. Dependabot checks Python and
|
|
144
|
+
GitHub Actions dependencies weekly. Dependency review blocks pull requests that
|
|
145
|
+
introduce moderate or higher vulnerabilities, and the dependency audit workflow
|
|
146
|
+
runs `pip-audit` against the project dependencies.
|
|
147
|
+
|
|
148
|
+
## Running simulations
|
|
149
|
+
|
|
150
|
+
Try
|
|
151
|
+
|
|
152
|
+
$ python3
|
|
153
|
+
>>> from vse import CsvBatch, baseRuns, Mav, medianRuns, Score
|
|
154
|
+
>>> from voterModels import PolyaModel
|
|
155
|
+
>>> csvs = CsvBatch(PolyaModel(), [[Score(), baseRuns], [Mav(), medianRuns]], nvot=5, ncand=4, niter=3)
|
|
156
|
+
>>> csvs.saveFile()
|
|
157
|
+
|
|
158
|
+
and look for the results in `SimResults1.csv`
|
|
159
|
+
|
|
160
|
+
## Repository layout
|
|
161
|
+
|
|
162
|
+
The root directory keeps the importable Python modules and common entry points so
|
|
163
|
+
older examples and direct imports keep working. Reference output snapshots live
|
|
164
|
+
in `data/`.
|
|
165
|
+
|
|
166
|
+
New code should prefer the `vse_sim` package namespace. The root-level modules
|
|
167
|
+
are kept for backward compatibility and as a useful regression target during the
|
|
168
|
+
packaging migration.
|
|
169
|
+
|
|
170
|
+
See [Publishing checklist](docs/PUBLISHING.md) for the remaining steps before a
|
|
171
|
+
public `pip install vse-sim` release.
|
vse_sim-0.1.0/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Voter Satisfaction Efficiency
|
|
2
|
+
|
|
3
|
+
These are some methods for running VSE (Voter Satisfaction Efficiency)
|
|
4
|
+
simulations for various voting systems.
|
|
5
|
+
|
|
6
|
+
See [Voter Satisfaction Efficiency FAQ](http://electionscience.github.io/vse-sim/) for an explanation of the methods and results.
|
|
7
|
+
|
|
8
|
+
## Installing the code
|
|
9
|
+
|
|
10
|
+
Requirements: Python 3.10+, NumPy, SciPy.
|
|
11
|
+
|
|
12
|
+
For notebook and library-style usage, install the package into the active
|
|
13
|
+
environment:
|
|
14
|
+
|
|
15
|
+
python -m pip install .
|
|
16
|
+
|
|
17
|
+
To install directly from GitHub:
|
|
18
|
+
|
|
19
|
+
python -m pip install "vse-sim @ git+https://github.com/wclark/vse-sim.git@main"
|
|
20
|
+
|
|
21
|
+
That exposes the modern `vse_sim` package namespace:
|
|
22
|
+
|
|
23
|
+
from vse_sim import CsvBatch, Mav, PolyaModel, Score, baseRuns, medianRuns
|
|
24
|
+
|
|
25
|
+
The legacy top-level modules remain installed and importable for existing
|
|
26
|
+
scripts and examples:
|
|
27
|
+
|
|
28
|
+
from vse import CsvBatch
|
|
29
|
+
from voterModels import PolyaModel
|
|
30
|
+
|
|
31
|
+
See [Notebook and GitHub installation](docs/INSTALL.md) for Jupyter examples,
|
|
32
|
+
GitHub install variants, and the future PyPI install path.
|
|
33
|
+
|
|
34
|
+
Testing uses doctests, which should make most things pretty self-documenting.
|
|
35
|
+
For development, install the project in editable mode with the test, lint, and
|
|
36
|
+
publishing helpers:
|
|
37
|
+
|
|
38
|
+
python -m pip install -e ".[dev,publish]"
|
|
39
|
+
|
|
40
|
+
Optionally install the local Git hooks:
|
|
41
|
+
|
|
42
|
+
pre-commit install
|
|
43
|
+
|
|
44
|
+
The main local readiness checks can also be run through Nox:
|
|
45
|
+
|
|
46
|
+
nox
|
|
47
|
+
|
|
48
|
+
Then run the legacy doctest examples:
|
|
49
|
+
|
|
50
|
+
python3 -m doctest methods.py
|
|
51
|
+
python3 -m doctest voterModels.py
|
|
52
|
+
python3 -m doctest dataClasses.py
|
|
53
|
+
python3 vse.py
|
|
54
|
+
|
|
55
|
+
Run the full test and coverage gate:
|
|
56
|
+
|
|
57
|
+
python -m pytest --doctest-modules --cov=. --cov-fail-under=100
|
|
58
|
+
|
|
59
|
+
To generate the same local coverage artifacts that CI uploads:
|
|
60
|
+
|
|
61
|
+
python -m pytest --doctest-modules --cov=. --cov-fail-under=100 --cov-report=term-missing:skip-covered --cov-report=xml:coverage.xml --cov-report=html:htmlcov --junitxml=pytest-results.xml
|
|
62
|
+
|
|
63
|
+
To run lint and style checks locally:
|
|
64
|
+
|
|
65
|
+
validate-pyproject pyproject.toml
|
|
66
|
+
python -m ruff check .
|
|
67
|
+
python -m ruff format --check .
|
|
68
|
+
|
|
69
|
+
To build and check package distributions locally:
|
|
70
|
+
|
|
71
|
+
python -m build
|
|
72
|
+
python -m twine check dist/*
|
|
73
|
+
check-wheel-contents dist/*.whl
|
|
74
|
+
|
|
75
|
+
To audit runtime dependencies for known vulnerabilities:
|
|
76
|
+
|
|
77
|
+
python -m pip_audit --skip-editable --progress-spinner off .
|
|
78
|
+
|
|
79
|
+
The GitHub Actions workflow runs the same coverage check on pushes, pull requests,
|
|
80
|
+
and manual dispatches. It uploads the HTML coverage report plus machine-readable
|
|
81
|
+
coverage and JUnit XML files as workflow artifacts.
|
|
82
|
+
|
|
83
|
+
The same workflow also builds the wheel and source distribution, installs the
|
|
84
|
+
wheel into a clean environment, checks the distributions with Twine, and uploads
|
|
85
|
+
the package artifacts.
|
|
86
|
+
|
|
87
|
+
The `Lint and Style` workflow validates `pyproject.toml`, then runs Ruff
|
|
88
|
+
formatting and lint checks on pushes, pull requests, and manual dispatches.
|
|
89
|
+
|
|
90
|
+
## Security automation
|
|
91
|
+
|
|
92
|
+
GitHub Actions also runs CodeQL code scanning for Python on pushes, pull
|
|
93
|
+
requests, a weekly schedule, and manual dispatches. Dependabot checks Python and
|
|
94
|
+
GitHub Actions dependencies weekly. Dependency review blocks pull requests that
|
|
95
|
+
introduce moderate or higher vulnerabilities, and the dependency audit workflow
|
|
96
|
+
runs `pip-audit` against the project dependencies.
|
|
97
|
+
|
|
98
|
+
## Running simulations
|
|
99
|
+
|
|
100
|
+
Try
|
|
101
|
+
|
|
102
|
+
$ python3
|
|
103
|
+
>>> from vse import CsvBatch, baseRuns, Mav, medianRuns, Score
|
|
104
|
+
>>> from voterModels import PolyaModel
|
|
105
|
+
>>> csvs = CsvBatch(PolyaModel(), [[Score(), baseRuns], [Mav(), medianRuns]], nvot=5, ncand=4, niter=3)
|
|
106
|
+
>>> csvs.saveFile()
|
|
107
|
+
|
|
108
|
+
and look for the results in `SimResults1.csv`
|
|
109
|
+
|
|
110
|
+
## Repository layout
|
|
111
|
+
|
|
112
|
+
The root directory keeps the importable Python modules and common entry points so
|
|
113
|
+
older examples and direct imports keep working. Reference output snapshots live
|
|
114
|
+
in `data/`.
|
|
115
|
+
|
|
116
|
+
New code should prefer the `vse_sim` package namespace. The root-level modules
|
|
117
|
+
are kept for backward compatibility and as a useful regression target during the
|
|
118
|
+
packaging migration.
|
|
119
|
+
|
|
120
|
+
See [Publishing checklist](docs/PUBLISHING.md) for the remaining steps before a
|
|
121
|
+
public `pip install vse-sim` release.
|
vse_sim-0.1.0/compat.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Small compatibility helpers shared across the simulation modules."""
|
|
2
|
+
|
|
3
|
+
from numbers import Number
|
|
4
|
+
|
|
5
|
+
from numpy import ceil as numpy_ceil
|
|
6
|
+
from numpy import floor as numpy_floor
|
|
7
|
+
from numpy import mean as numpy_mean
|
|
8
|
+
from numpy import median as numpy_median
|
|
9
|
+
from numpy import sqrt as numpy_sqrt
|
|
10
|
+
from numpy import std as numpy_std
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def as_builtin_scalar(value):
|
|
14
|
+
"""Convert NumPy scalar values to their Python built-in equivalents."""
|
|
15
|
+
try:
|
|
16
|
+
return value.item()
|
|
17
|
+
except (AttributeError, ValueError):
|
|
18
|
+
return value
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def ceil(*args, **kwargs):
|
|
22
|
+
return as_builtin_scalar(numpy_ceil(*args, **kwargs))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def floor(*args, **kwargs):
|
|
26
|
+
return as_builtin_scalar(numpy_floor(*args, **kwargs))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def mean(*args, **kwargs):
|
|
30
|
+
return as_builtin_scalar(numpy_mean(*args, **kwargs))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def median(*args, **kwargs):
|
|
34
|
+
return as_builtin_scalar(numpy_median(*args, **kwargs))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def sqrt(*args, **kwargs):
|
|
38
|
+
return as_builtin_scalar(numpy_sqrt(*args, **kwargs))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def std(*args, **kwargs):
|
|
42
|
+
return as_builtin_scalar(numpy_std(*args, **kwargs))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def isnum(x):
|
|
46
|
+
"""Return whether ``x`` is an instance of a numeric type."""
|
|
47
|
+
return isinstance(x, Number)
|