Skip to content

Fix broken test suite, refresh docs, deps, and CI#20

Merged
shehio merged 5 commits into
developfrom
claude/improvements
Jul 10, 2026
Merged

Fix broken test suite, refresh docs, deps, and CI#20
shehio merged 5 commits into
developfrom
claude/improvements

Conversation

@shehio

@shehio shehio commented Jul 5, 2026

Copy link
Copy Markdown
Owner

What's in here

Fix: get_value_function_difference always raised, breaking value iteration and both policy iteration variants (3 tests were failing on develop). np.intersect1d wraps dict_keys of State objects 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 a QFunction exclude 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: UnboundLocalError in Monte Carlo control when stable_count <= 0new_policy was referenced after a loop that may never run; initialized to the starting policy, same pattern as the earlier fix in policy_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.txt slimmed 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 named state, an unused matplotlib, and numpy==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__.py to src/monte_carlo and src/problems; .gitignore now covers .venv/, .pytest_cache/, *.egg-info/.

Verification

python -m pytest on Python 3.14 / numpy 2.5: 43 passed, 3 failed before; 46 passed after.

🤖 Generated with Claude Code

shehio and others added 5 commits July 5, 2026 07:27
…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>
@shehio
shehio merged commit f06f0eb into develop Jul 10, 2026
2 checks passed
@shehio
shehio deleted the claude/improvements branch July 10, 2026 10:14
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.

1 participant