First, and most importantly, this project has been largely inspired from: suitesparse-metis-for-windows (we do not include the compilation of "metis" because we don't need it for this project).
The goal of the files in this subdirectory is to be able to build some of the SuiteSparse
modules with cmake
(as opposed to the recommended compilation tool "make" used by this code). This allows to further speed up
lightsim2grid
code with the use of the KLU
linear solver (part of SuiteSparse) which is faster than the default
linear solver in Eigen
.
Being able to compile SuiteSparse with cmake allows to benefit the faster KLU
solver even on windows based platform,
where "make" is not a viable option.
This only works if you have a working cmake
on your system. cmake
is a free
software that you can download and install. We do not cover this (have a look at https://cmake.org/
for more information)
Of course, you also need to have a working compiler (for example microsoft visual studio on windows: https://visualstudio.microsoft.com/vs/features/cplusplus/ )
You need to cd
into the correct directory, which is the build_cmake
subdirectory
of this repo (lightsim2grid/build_cmake
). Then:
- you need to make sure to have clone the submodule, and in particular the
"SuiteSparse" submodule, otherwise this will not work (
git submodule init; git submodule update
) - generate the right sources (small hack to get cmake to work correctly):
python3 generate_c_files.py
[might require admin rights for now...] - create a "build" subdirectory, and cd there:
mkdir build; cd build
- prepare the compilation with cmake: (on windows, adapt the command the other platforms)
cmake -DCMAKE_INSTALL_PREFIX=..\built -DCMAKE_BUILD_TYPE=Release ..
NB It is mandatory to install the libraries in..\built
, otherwise they will not be detected by the installation script oflightsim2grid
and this will be useless - compile the SuiteSparse package:
cmake --build . --config Release
- "install" it (which means: "move the libraries and the header at the right place):
cmake --build . --config Release --target install
and / orcmake --install . --config Release --prefix ..\built
Now you can install lightsim2grid as usual (see the standard readme for more details):
cd ..
(to go to the source tree of lightsim2grid)py -m pip install .
To assess whether this works or not you can now, from a python "shell" (really called "repl")
from lightsim2grid.solver import KLUSolver
If you don't have any errors you are good to go.
NB you might encounter some warnings like
"Numba cannot be loaded. You will gain possibly massive speed if installing it". To silence this warning, just install
the python package numba
. This does not come from lightsim2grid, but is used by pandapower.
Compiling on windows might be tricky. Here are some errors we encounter. Feel free to post a github issue if you encounter some not listed there.
Some of these files relies on symbolic links "symlink" and you might need root privilege on windows to build them. We will try to have a workaround for that at some point.
On windows, the anti virus program (eg Avast, Windows Defender, MacAffee, etc.) might cause trouble during the compilation. You might need to disable it temporarily during the compilation, or to add the proper exception to visual c++, cmake and possibly other programs.