Repository navigation
Validating MDPSolver
Anders Reenberg Andersen edited this page Nov 11, 2026
·
12 revisions
This section briefly describes how to test and ensure that MDPSolver produces the expected results.
Start by ensuring that MDPSolver has been correctly downloaded and installed (see the section on how to install MDPSolver), e.g. by running pip show mdpsolver in the terminal followed by import mdpsolver in Python.
Now follow these steps to ensure that MDPSolver correctly computes the policy and value vector for a given MDP problem:
- Install NumPy with
pip install numpy. - Clone the MDPSolver repository at the version you have installed, which
pip show mdpsolverreports, e.g. for version 0.11.0 withgit clone --branch v0.11.0 https://github.com/areenberg/MDPSolver.git. The tests of a newer version may use features that your version does not have. - Copy the folder
MDPSolver/Python/teststo a location outside the repository. This makes the tests use your installed MDPSolver rather than the source code in the repository. - In the copied folder, run the tests
python test_imports.py,python test_vi.py,python test_pi.py,python test_mpi.py,python test_random.py,python test_large.py,python test_reuse.py,python test_order.py,python test_output.py, andpython test_checkmodel.py. (Versions before 0.10.3 have the teststest1_pip.pyandtest2_pip.pyinstead.) - If MDPSolver runs correctly, each test prints a message such as
test_vi: All tests passed. (Python/src was not found next to the test, so the installed mdpsolver was tested as a whole.). If MDPSolver does not run correctly, the test aborts withValidation test failed at case n:and a description of what failed.
The tests compare the results of MDPSolver with exact solutions, computed independently of MDPSolver:
-
test_imports.py: Every way of giving the rewards and the transition probabilities tomdp()(lists and files) gives the same model, and missing input or input given twice stops with an error. -
test_vi.py,test_pi.py, andtest_mpi.py: Value iteration, policy iteration, and modified policy iteration find the optimal policy and values of problems with known solutions, under every update method and both optimality criteria, and reject invalid settings. -
test_random.py: The three algorithms find the exact solution of 30 random problems. -
test_large.py: Every algorithm and update method solves a large queueing problem (202 states). -
test_reuse.py: Callingmdp()twice on a model object gives an error, and solving a model again starts from the previous solution. -
test_order.py: Calling the methods in the wrong order, e.g.getPolicy()beforesolve()orsolve()beforemdp(), gives an error. -
test_output.py: The output methods and files agree with the solution, and a run that does not converge gives a warning. -
test_checkmodel.py: ThecheckModel()method finds each kind of error in a model, and finds none in a correct one.