Skip to content

Performance experiments

Anders Reenberg Andersen edited this page Nov 13, 2026 · 10 revisions

This page describes two experiments: the solution of large models (the examples in the README), and a comparison with pymdptoolbox (the benchmark).

Large models

We solved random models of five sizes, from 100,000 states and 10 million non-zero transition probabilities to 10 million states and 1 billion non-zero transition probabilities. Every state had 5 actions, and every state-action pair had 20 next states, sampled uniformly without replacement, with exponentially distributed transition probabilities (normalised to sum to 1). The rewards were standard normal. We sampled 10 models of each size.

Each model was written to two NPY files in the elementwise format, one with the transition probabilities and one with the rewards (float64 arrays with a row per entry; see Loading models from NPY files), and loaded with mdp(discount=0.9, rewardsFromFile="rewards.npy", tranMatFromFile="transitions.npy"). MDPSolver reads the files straight into its own tables, so the Python process holds no copy of the model. The model was then solved with solve(algorithm="mpi", criterion="discounted"), with the other settings at their defaults. Each model was loaded and solved in a new Python process, for the models of 300 million non-zero transition probabilities and more 30 seconds after its files were written.

We measured the time of mdp() (loading time), the time of solve() (solution time), and the peak memory of the Python process (RAM).

Test Configuration Overview

  • State space sizes: 100,000, 1,000,000, 3,000,000, 5,000,000, 10,000,000.
  • Action space size: 5.
  • Next states for each state-action pair: 20 (uniformly sampled).
  • Sampled models for each state space size: 10.
  • Optimality criterion: Discounted reward ($\lambda=0.9$).
  • Algorithm: Modified Policy Iteration with the default settings of solve() (tolerance $1 \cdot 10^{-3}$, partial evaluation limit 100, in parallel).
  • Input: NPY files (tranMatFromFile and rewardsFromFile).

Results

States Non-zero transitions Transitions file Loading time RAM Solution time
100,000 10,000,000 0.3 GB 0.09 s 153 MB 0.035 s
1,000,000 100,000,000 3.0 GB 0.95 s 1.3 GB 0.419 s
3,000,000 300,000,000 8.9 GB 2.8 s 3.8 GB 2.56 s
5,000,000 500,000,000 14.9 GB 6.8 s 6.3 GB 5.03 s
10,000,000 1,000,000,000 29.8 GB 18.6 s 12.7 GB 13.0 s

The times are means over the 10 models of each size, and RAM is the largest peak over them. Every model was solved in 4 or 5 iterations. Most of the memory holds the transition probabilities and their next states: 12 bytes per non-zero transition (8 for the probability and 4 for the next state).

The same models in CSV files (transitions.csv and rewards.csv, of 0.3 GB to 35.6 GB) took 5.3 s to 547 s to load, with the same peak memory and similar solution times (0.034 s to 12.9 s).

Benchmark

We used pymdptoolbox as a benchmark for the performance of MDPSolver. Our tests included three optimization algorithms: Value Iteration (VI), Policy Iteration (PI), and Modified Policy Iteration (MPI) with standard value-updates. We did not test the other value-update methods since, in the pymdptoolbox, successive over-relaxation was not available and Gauss-Seidel was only available for VI. Moreover, in pymdptoolbox, the Gauss-Seidel VI employs the span norm stopping criterion, whereas MDPSolver reserves the span norm for standard value-updates. Thus, we only compared algorithms employing identical update methods and stopping criteria.

We tested the three algorithms on randomly generated MDP problems with exponentially distributed transition probabilities and normally distributed rewards. The column indices (next states) were sampled from a uniform distribution. Each randomly sampled MDP problem employed a constant action space which was the only option for pymdptoolbox. The size of the (constant) action space was uniformly sampled between 2 and 10. The tests included three levels of state space sizes (2500, 5000, and 10000) and three levels of transition matrix sparsities (80%, 90%, and 99%). We sampled 20 MDP problems for each combination of a state space size and sparsity.

We measured the runtime of the algorithms only: solve() in MDPSolver and run() in pymdptoolbox. Neither includes loading the model. pymdptoolbox checks every model when it is loaded, which we switched off, as MDPSolver only checks a model when asked (checkModel()). MDPSolver ran both in parallel (the default) and on one thread. The scripts are in the folder Benchmark of the repository.

Test Configuration Overview

  • State space sizes: 2500, 5000, 10000.
  • Sparsities: 80%, 90%, 99%.
  • Action space sizes: 2-10 (uniformly sampled).
  • Sampled MDP problems for each state space size and sparsity: 20.
  • Optimality criterion: Discounted reward ($\lambda=0.99$).
  • Tolerance ($\epsilon$): $1 \cdot 10^{-3}$ ($1 \cdot 10^{-4}$ for PI).
  • Partial evaluation limit: 100 (only used by MPI).
  • MDPSolver: in parallel (default) and on one thread.

Results

Brief Overview

Our Policy Iteration algorithm was up to 719x faster than the same algorithm in pymdptoolbox. For the Modified Policy Iteration algorithm, the speedup was up to 407x, and for the Value Iteration algorithm, the speedup was up to 6.2x. On one thread, MDPSolver was up to 264x (PI), 229x (MPI), and 3.3x (VI) faster. Both packages found the same policy for every MDP.

Details

We validated the performance of MDPSolver by dividing the runtime of pymdptoolbox with the runtime of MDPSolver for the same MDP and algorithm. That is, we defined the performance (speedup) of MDPSolver as $\delta = r_1 / r_2$, where $r_1$ is the runtime of pymdptoolbox, and $r_2$ the runtime of MDPSolver. If $r_1 > r_2$, MDPSolver outperforms the runtime of pymdptoolbox by a factor of $\delta$.

In general, $\delta$ was notably greater than 1 and increased as a function of the number of states and the sparsity. For the VI algorithm, however, the speedup was smaller: pymdptoolbox's VI spends its time in sparse matrix-vector products, which are compiled code, as in MDPSolver. For the smallest and sparsest MDPs (2500 states, 99% sparsity), MDPSolver was faster on one thread than in parallel, since an iteration is too little work to share between threads. The details of each algorithm follow below.

Policy Iteration. MDPSolver outperformed pymdptoolbox by an average factor between 27.2 (State space size: 2500, Sparsity: 80%) and 718.8 (State space size: 10000, Sparsity: 99%). On one thread, the factor was between 11.9 and 264.3 for the same MDPs. Figure 1 illustrates boxplots of the performance tests for the PI algorithm.

Modified Policy Iteration. MDPSolver outperformed pymdptoolbox by an average factor between 39.3 (State space size: 10000, Sparsity: 80%) and 406.5 (State space size: 10000, Sparsity: 99%). On one thread, the factor was between 18.0 (State space size: 2500, Sparsity: 80%) and 229.5 (State space size: 5000, Sparsity: 99%). Figure 2 illustrates boxplots of the performance tests for the MPI algorithm.

Value Iteration. MDPSolver outperformed pymdptoolbox by an average factor between 1.7 (State space size: 2500, Sparsity: 99%) and 6.2 (State space size: 5000, Sparsity: 80%). On one thread, the factor was between 1.9 (State space size: 5000, Sparsity: 99%) and 3.3 (State space size: 10000, Sparsity: 90%). Figure 3 illustrates boxplots of the performance tests for the VI algorithm.




Figure 1. Relative runtime of pymdptoolbox compared to MDPSolver for the Policy Iteration algorithm, with MDPSolver in parallel (left) and on one thread (right).


Figure 2. Relative runtime of pymdptoolbox compared to MDPSolver for the Modified Policy Iteration algorithm, with MDPSolver in parallel (left) and on one thread (right).


Figure 3. Relative runtime of pymdptoolbox compared to MDPSolver for the Value Iteration algorithm, with MDPSolver in parallel (left) and on one thread (right).


Test Environment

Both experiments ran on the same machine.

  • Operating System: macOS 27.0.1.
  • Processor: Apple M5, 10 cores.
  • Memory (RAM): 24GB
  • Storage: internal SSD (the files of the large models).
  • Python version: 3.14.8.
  • MDPSolver version: 0.12.0.
  • pymdptoolbox version: 4.0b3 (with NumPy 2.5.3 and SciPy 1.18.1).

Clone this wiki locally