-
Notifications
You must be signed in to change notification settings - Fork 1
Contribution guidelines
Everyone is welcome to contribute to MDPSolver! The following contains a short description of how to add features, raise issues, and contact the authors.
MDPSolver consists of a C++-based optimization module (for deriving the policy and value vector) and a Python-based class for communicating with the optimization module. Features can be added to MDPSolver by modifying the C++ code under CPP_Source_Code
and/or the Python code under Python/src/mdpsolver
.
Follow these steps to compile and install the optimization module:
Linux
- Start by creating a Python virtual environment using
conda
(note: replacepython=3.13
with the target Python version):
conda create --name myenv python=3.13
conda activate myenv
- Install
python3.13-config
(Ubuntu users:sudo apt-get install python3.13-dev
). - Install pybind11:
pip install pybind11
. - Install NumPy:
pip install numpy
. - Clone MDPSolver:
git clone https://github.com/areenberg/mdpsolver.git
. - Navigate to MDPSolver:
cd mdpsolver
. - Now run
sh build_and_test_linux.sh
to automatically compile, install, and test the new module. - The
Python/src
directory contains the updated MDPSolver package.
Manual approach
- To manually compile the optimization module on Linux, navigate to
CPP_Source_Code
and run:
g++ -O3 -fopenmp -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` *.cpp -o solvermodule`python3-config --extension-suffix`
- The above will create an SO-file containing the compiled module. Check that the SO-file exists (e.g.
solvermodule.cpython-313-x86_64-linux-gnu.so
). - To install the module in the MDPSolver package, copy the SO-file to
Python/src/mdpsolver
(e.g.cp solvermodule.cpython-310-x86_64-linux-gnu.so ../Python/src/mdpsolver/
). - Now navigate to the tests:
cd ../Python/tests
. - Run test 1 with
python3 test1.py
and test 2 withpython3 test2.py
.
GLIBC not found
Users attempting to fix the version 'GLIBC_2.32' not found
error will have to replace the version installed using pip install mdpsolver
with the updated MDPSolver package located in Python/src
.
- Start by locating the
pip
installation of MDPSolver:pip show mdpsolver
(e.g./home/anders/.local/lib/python3.10/site-packages
). - Overwrite the version installed by
pip
with the updated package (e.g.cp -r Python/src/mdpsolver /home/anders/.local/lib/python3.10/site-packages
).
Windows
- Install Visual Studio 2022 (17.9) with MSVC C++ compiler and libraries.
- Install CMake.
- Install pybind11:
pip install pybind11
. - Install NumPy:
pip install numpy
. - Clone MDPSolver:
git clone https://github.com/areenberg/mdpsolver.git
. - Navigate to MDPSolver:
cd mdpsolver
. - Now run
.\build_and_test_windows.bat
(or simply double-click the file) to automatically compile, install, and test the new module. - The
Python/src
directory contains the updated MDPSolver package.
Manual approach
- Navigate to
CPP_Source_Code
and check thatCMakeLists.txt
exists and contains the following:
cmake_minimum_required(VERSION 3.13)
project(solvermodule)
add_subdirectory(pybind11)
file(GLOB SOURCES "*.cpp")
pybind11_add_module(solvermodule ${SOURCES})
set_target_properties(solvermodule PROPERTIES CXX_STANDARD 11)
#Include OpenMP
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_compile_options(solvermodule PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/openmp:llvm>")
target_link_libraries(solvermodule PUBLIC OpenMP::OpenMP_CXX)
endif()
Note: replace cmake_minimum_required(VERSION 3.13)
with the target Python version.
- Run the following commands from the command prompt:
mkdir build
cd build
cmake ..
cmake --build . --config Release
- This will create a PYD-file containing the compiled module in the directory
CPP_Source_Code/build/Release
. Check that the file exists (e.g.solvermodule.cp313-win_amd64.pyd
). - To install the module in the MDPSolver package, copy the PYD-file to
Python/src/mdpsolver
. - Now navigate to
Python/tests
. - Run test 1 with
python test1.py
and test 2 withpython test2.py
.
Contact the authors if you want your modifications to be available in the official release of MDPSolver.
Bugs and issues can be raised in the Issues tab. Before creating a new issue, make sure to (1) check the installation instructions for your operating system, and (2) that your issue has not already been raised.
Should you have any questions about how to add features, perform other modifications, or ideas for the direction of MDPSolver, you can always contact the authors: