Installation from source¶
Getting the source¶
The following instructions are for (some kind of) Linux, and tested on Ubuntu. However, the code itself should work on other operating systems as well (in particular MacOS and Windows).
git clone https://github.com/tenpy/tenpy.git $HOME/TeNPy cd $HOME/TeNPy
$HOME/TeNPy to the path wherever you want to save the library.
Optionally, if you don’t want to contribute, you can checkout the latest stable release:
git tag # this prints the available version tags git checkout v0.3.0 # or whatever is the lastest stable version
Minimal installation: Including tenpy into PYTHONPATH¶
The python source is in the directory tenpy/ of the repository. This folder tenpy/ should be placed in (one of the folders of) the environment variable PYTHONPATH. On Linux, you can simply do this with the following line in the terminal:
(If you have already a path in this variable, separate the paths with a colon
However, if you enter this in the terminal, it will only be temporary for the terminal session where you entered it.
To make it permanently, you can add the above line to the file
You might need to restart the terminal session or need to relogin to force a reload of the
Whenever the path is set, you should be able to use the library from within python:
>>> import tenpy /home/username/TeNPy/tenpy/tools/optimization.py:276: UserWarning: Couldn't load compiled cython code. Code will run a bit slower. warnings.warn("Couldn't load compiled cython code. Code will run a bit slower.") >>> tenpy.show_config() tenpy 0.4.0.dev0+7706003 (not compiled), git revision 77060034a9fa64d2c7c16b4211e130cf5b6f5272 using python 3.7.3 (default, Mar 27 2019, 22:11:17) [GCC 7.3.0] numpy 1.16.3, scipy 1.2.1
tenpy.show_config() prints the current version of the used TeNPy library as well as the versions of the used python, numpy and scipy libraries,
which might be different on your computer. It is a good idea to save this data (given as string in
tenpy.version.version_summary along with your data to allow to reproduce your results exactly.
If you got a similar output as above: congratulations! You can now run the codes :)
Compilation of np_conserved¶
At the heart of the TeNPy library is the module
tenpy.linalg.np_conseved, which provides an Array class to exploit the
conservation of abelian charges. The data model of python is not ideal for the required book-keeping, thus
we have implemented the same np_conserved module in Cython.
This allows to compile (and thereby optimize) the corresponding python module, thereby speeding up the execution of the
code. While this might give a significant speed-up for code with small matrix dimensions, don’t expect the same speed-up in
cases where most of the CPU-time is already spent in matrix multiplications (i.e. if the bond dimension of your MPS is huge).
To compile the code, you first need to install Cython
conda install cython # when using anaconda, or pip install --upgrade Cython # when using pip
Moreover, you need a C++ compiler.
For example, on Ubuntu you can install
sudo apt-get install build_essential,
or on Windows you can download MS Visual Studio 2015.
If you use anaconda, you can also use one
conda install -c conda-forge cxx-compiler.
After that, go to the root directory of TeNPy (
$HOME/TeNPy) and simply run
There is no need to compile if you installed TeNPy directly with conda or pip. (You can verify this with tenpy.show_config() as illustrated below.)
Note that it is not required to separately download (and install) Intel MKL: the compilation just obtains the includes from numpy. In other words, if your current numpy version uses MKL (as the one provided by anaconda), the compiled TeNPy code will also use it.
After a successful compilation, the warning that TeNPy was not compiled should go away:
>>> import tenpy >>> tenpy.show_config() tenpy 0.4.0.dev0+b60bad3 (compiled from git rev. b60bad3243b7e54f549f4f7c1f074dc55bb54ba3), git revision b60bad3243b7e54f549f4f7c1f074dc55bb54ba3 using python 3.7.3 (default, Mar 27 2019, 22:11:17) [GCC 7.3.0] numpy 1.16.3, scipy 1.2.1
For further optimization options, look at