Fix broken test suite, refresh docs, deps, and CI#20
Merged
Conversation
…sets np.intersect1d wraps dict_keys of State objects in 0-d object arrays, so the intersection always came back empty. The original inverted check (== instead of !=) masked this; once the inversion was fixed in 789cfe6, value iteration and both policy iteration variants started failing because value functions derived from a QFunction legitimately exclude terminal states. Compute the intersection with set semantics instead and require the smaller value function's states to be a subset of the larger one's, which is what the downstream minimum-keys logic already assumed. Fixes the 3 failing tests in test_valuefunctionhelpers.py and test_policyhelpers.py. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
__monte_carlo_control_common returned new_policy, which is unbound if the while loop body never executes. Initialize it to the starting policy, matching the fix already applied to policy_iteration_sutton. Also add the missing __init__.py to src/monte_carlo and src/problems for consistency with the other packages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
travis-ci.org shut down and the config targeted Python 3.6/3.7, which the current dependencies no longer support. Run pytest on Python 3.11 and 3.12 for pushes and pull requests instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The old file was a pip freeze of an entire 2019 virtualenv (poetry, keyring, tox-travis, an unrelated PyPI package named "state", an unused matplotlib, ...) with pins like numpy==1.18.0 that no longer install on current Python. The code only needs numpy; keep pytest and mypy for the test/lint workflow. Also ignore .venv/, .pytest_cache/, and *.egg-info/. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The README was only a list of external resources. Add what the project is, which algorithms are implemented and where, the package layout, runnable examples for value iteration, policy iteration, and Monte Carlo control on the bundled grid world, and how to run the tests. Keep the resource links. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 10, 2026
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.
What's in here
Fix:
get_value_function_differencealways raised, breaking value iteration and both policy iteration variants (3 tests were failing ondevelop).np.intersect1dwrapsdict_keysofStateobjects in 0-d object arrays, so the intersection always came back empty — the original inverted==check masked this, and once that inversion was corrected in 789cfe6 the function raised on every call where the state sets differ (which is legitimate: value functions derived from aQFunctionexclude terminal states). Now computes the intersection with set semantics and requires the smaller value function's states to be a subset of the larger one's — the assumption the downstream minimum-keys logic already made. Test suite goes from 43 passed / 3 failed to 46 passed.Fix:
UnboundLocalErrorin Monte Carlo control whenstable_count <= 0—new_policywas referenced after a loop that may never run; initialized to the starting policy, same pattern as the earlier fix inpolicy_iteration_sutton.Docs: README now documents the project itself — which algorithms are implemented (value iteration, both policy iteration variants, MC prediction/control first- and every-visit) and where, package layout, runnable grid-world examples, and how to run the tests. Existing resource links kept.
Deps:
requirements.txtslimmed from a 2019 full-venv freeze to the 3 real dependencies (numpy, pytest, mypy). The old file pinned poetry, keyring, tox-travis, an unrelated PyPI package namedstate, an unused matplotlib, andnumpy==1.18.0, which no longer installs on current Python. This should also clear most of the open Dependabot alerts.CI: dead Travis config replaced with GitHub Actions — travis-ci.org is gone and the config targeted Python 3.6/3.7; the workflow runs pytest on 3.11 and 3.12.
Hygiene: added missing
__init__.pytosrc/monte_carloandsrc/problems;.gitignorenow covers.venv/,.pytest_cache/,*.egg-info/.Verification
python -m pyteston Python 3.14 / numpy 2.5: 43 passed, 3 failed before; 46 passed after.🤖 Generated with Claude Code