Skip to content

Validating MDPSolver

Anders Reenberg Andersen edited this page Nov 14, 2026 · 12 revisions

This section briefly describes how to test and ensure that MDPSolver produces the expected results.

How to run the tests

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:

  1. Install NumPy with pip install numpy.
  2. Clone the MDPSolver repository at the version you have installed, which pip show mdpsolver reports, e.g. for version 0.11.0 with git 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.
  3. Copy the folder MDPSolver/Python/tests to a location outside the repository. This makes the tests use your installed MDPSolver rather than the source code in the repository.
  4. 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, python test_checkmodel.py, python test_arrays.py, python test_threads.py, and python test_average.py. (Versions before 0.10.3 have the tests test1_pip.py and test2_pip.py instead.)
  5. 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 with Validation test failed at case n: and a description of what failed.

What the tests check

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 to mdp() (lists, and comma-separated and .npy files) gives the same model, and missing input, input given twice, or an .npy file that cannot be read stops with an error.
  • test_vi.py, test_pi.py, and test_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: Calling mdp() 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() before solve() or solve() before mdp(), 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: The checkModel() method finds each kind of error in a model, and finds none in a correct one.
  • test_arrays.py: A model given as NumPy arrays gives exactly the results of the same model given as lists, and arrays that do not fit their format stop with an error.
  • test_threads.py: Other Python threads run while solve() computes, models solved in several threads give the same results as solved one after another, and one model object used by several threads gives only complete results.
  • test_average.py: Under the average reward criterion, the bounds of getGain() contain the gain of the policy found and the optimal gain, also when solve() stops at its limit, and getBias() gives the known bias for every reference state.

Clone this wiki locally