Open source library for hafnian calculation
Project description
The fastest exact hafnian library. For more information, please see the documentation.
Features
The fastest calculation of the hafnians, loop hafnians, and torontonians of general and certain structured matrices.
An easy to use interface to use the loop hafnian for quantum state calculations
State of the art algorithms to sample from hafnian and torontonians of graphs.
Efficient classical methods for approximating the hafnian of non-negative matrices.
Installation
Pre-built binary wheels are available for the following platforms:
macOS 10.6+ |
manylinux x86_64 |
Windows 64bit |
|
---|---|---|---|
Python 3.5 |
✅ |
✅ |
✅ |
Python 3.6 |
✅ |
✅ |
✅ |
Python 3.7 |
✅ |
✅ |
✅ |
To install, simply run
pip install hafnian
Compiling from source
Hafnian depends on the following Python packages:
In addition, to compile the included Fortran and C++ extensions, the following dependencies are required:
A Fortran compiler, such as gfortran
A C++11 compiler, such as g++ >= 4.8.1, clang >= 3.3, MSVC >= 14.0/2015
Eigen3 - a C++ header library for linear algebra.
On Debian-based systems, these can be installed via apt and curl:
$ sudo apt install g++ gfortran libeigen3-dev
or using Homebrew on MacOS:
$ brew install gcc eigen
Alternatively, you can download the Eigen headers manually:
$ mkdir ~/.local/eigen3 && cd ~/.local/eigen3
$ wget http://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz -O eigen3.tar.gz
$ tar xzf eigen3.tar.gz eigen-eigen-323c052e1731/Eigen --strip-components 1
$ export EIGEN_INCLUDE_DIR=$HOME/.local/eigen3
Note that we export the environment variable EIGEN_INCLUDE_DIR so that Hafnian can find the Eigen3 header files (if not provided, Hafnian will by default look in /use/include/eigen3 and /usr/local/include/eigen3).
Once all dependencies are installed, you can compile the latest stable version of the Hafnian library as follows:
$ python -m pip install hafnian --no-binary :all:
Alternatively, you can compile the latest development version by cloning the git repository, and installing using pip in development mode.
$ git clone https://github.com/XanaduAI/hafnian.git
$ cd hafnian && python -m pip install -e .
OpenMP
The Hafnian library uses OpenMP to parallelize both the permanent and the hafnian calculation. At the moment, this is only supported on Linux using the GNU g++ compiler, due to insufficient support using Windows/MSCV and MacOS/Clang.
Using LAPACK, OpenBLAS, or MKL
If you would like to take advantage of the highly optimized matrix routines of LAPACK, OpenBLAS, or MKL, you can optionally compile the Hafnian library such that Eigen uses these frameworks as backends. As a result, all calls in the Hafnian library to Eigen functions are silently substituted with calls to LAPACK/OpenBLAS/MKL.
For example, for LAPACK integration, make sure you have the lapacke C++ LAPACK bindings installed (sudo apt install liblapacke-dev in Ubuntu-based Linux distributions), and then compile with the environment variable USE_LAPACK=1:
$ USE_LAPACK=1 python -m pip install hafnian --no-binary :all:
Alternatively, you may pass USE_OPENBLAS=1 to use the OpenBLAS library.
Software tests
To ensure that the Hafnian library is working correctly after installation, the test suite can be run by navigating to the source code folder and running
$ make test
To run the low-level C++ test suite, Googletest will need to be installed. In Ubuntu-based distributions, this can be done as follows:
sudo apt-get install cmake libgtest-dev
cd /usr/src/googletest/googletest
sudo cmake
sudo make
sudo cp libgtest* /usr/lib/
sudo mkdir /usr/local/lib/googletest
sudo ln -s /usr/lib/libgtest.a /usr/local/lib/googletest/libgtest.a
sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest/libgtest_main.a
Alternatively, the latest Googletest release can be installed from source:
sudo apt install cmake
wget -qO - https://github.com/google/googletest/archive/release-1.8.1.tar.gz | tar -xz
cmake -D CMAKE_INSTALL_PREFIX:PATH=$HOME/googletest -D CMAKE_BUILD_TYPE=Release googletest-release-1.8.1
make install
If installing Googletest from source, make sure that the included headers and libraries are available on your include/library paths.
Documentation
The Hafnian+ documentation is currently not hosted online. To build it locally, you need to have the following packages installed:
They can be installed via a combination of pip and apt if on a Debian-based system:
$ sudo apt install pandoc doxygen $ pip3 install sphinx sphinxcontrib-bibtex nbsphinx breathe exhale
To build the HTML documentation, go to the top-level directory and run the command
$ make doc
The documentation can then be found in the docs/_build/html/ directory.
Support
Source Code: https://github.com/XanaduAI/hafnian
Issue Tracker: https://github.com/XanaduAI/hafnian/issues
If you are having issues, please let us know by posting the issue on our Github issue tracker.
License
Hafnian is free and open source, released under the Apache License, Version 2.0.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file hafnian-0.6.1.tar.gz
.
File metadata
- Download URL: hafnian-0.6.1.tar.gz
- Upload date:
- Size: 261.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c77180a312125fc1cf8f7f5573882b82a3587be09ece836992cce6249ffff6 |
|
MD5 | 5496b2d72c78ab7b61c9e84cb1aa379d |
|
BLAKE2b-256 | 2b5682c04b1977e42dfe1c5fe676c298c59958420ee22b2ea1e4c5989d00ddaa |
File details
Details for the file hafnian-0.6.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 477.0 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3176608bf72d8a05332f89107293040a8f20e9ac7978c80c81c7fa29bf24225f |
|
MD5 | e49f67f10a157fb1aa54416628646de8 |
|
BLAKE2b-256 | b59040fd46354774ea48f71c90b2b39d1b383a558f69908d6d4e2408618decda |
File details
Details for the file hafnian-0.6.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b9c6926abe4884aca8528efcb9a79e3aaab6797954507c84277d02c1cb9b4d2 |
|
MD5 | 57d58a46a092651b0dd833ed670eb82c |
|
BLAKE2b-256 | 371b0d120dbbab2b6f243d04b4fe29e16f856cff9679f08de49c87cde935bc67 |
File details
Details for the file hafnian-0.6.1-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfcb45bc5fd66e6e1277a390f98b1d506f15ae2ac11279dc5bb3ed07d617b0aa |
|
MD5 | f7168a3679854daae3fc3da86dbbea7d |
|
BLAKE2b-256 | ee119ff56de1ff67ae98c747c88a694cd1a5f6908e38c477c7afb5ae3c7f8833 |
File details
Details for the file hafnian-0.6.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 477.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2e1cfc640328fd7c6da5e74d695e65b7cce50ac444ca024110e1a1f03ec1bb |
|
MD5 | 385e9f36a12f9c8d224b70777f25e4a9 |
|
BLAKE2b-256 | bc035a92168cfd86619c425cd1726e4e14901c54a17b91b455dc6651a48538c6 |
File details
Details for the file hafnian-0.6.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e5ff2c90490f6df904683efb7bd971c9b59ab4171537d0140c25f206ddd6362 |
|
MD5 | 25adebee9936d1c3317077550fc904fa |
|
BLAKE2b-256 | 5c182b88829f5f3dc284696496885669dc7c1d45d2cc42c8fa294da813ace47a |
File details
Details for the file hafnian-0.6.1-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42cc014b8f28fbe53c44c9e58f3948710f6691cf3c0ebec76a99aac6d2000e85 |
|
MD5 | f2e064dddce0adbacfc25af27289f307 |
|
BLAKE2b-256 | 1d14c6353a62e295ce3dfd007416c4968ffde8d40147ba45a7b1816bef0e9898 |
File details
Details for the file hafnian-0.6.1-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 476.7 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57e2eac9c3f5007b60943b03030baa8bfb250fb3377c8d221927d39f2794fff7 |
|
MD5 | edec4b4afd1f7c6b291785b626d82047 |
|
BLAKE2b-256 | d8754a8725e93c39396ef99779de74e81af79f2343f465e4027a486693d966f2 |
File details
Details for the file hafnian-0.6.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e8c819b07bcf3017dfd22f03acde4c4fc30bf280769dd164fb56f99a8e7af58 |
|
MD5 | 8c691afc6c08714ef0cea8d5944ece9f |
|
BLAKE2b-256 | c741ebb2dc474fecee27086530b7a0173a1c0185164fdf9ab26395d015fac69e |
File details
Details for the file hafnian-0.6.1-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: hafnian-0.6.1-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 044e442e7926b7ad8760da4e8299da1ff3b8c5b983a9b543dc179942b0441dbb |
|
MD5 | 70ab554806b425a8020d498989b4acbb |
|
BLAKE2b-256 | 73ee162e8c87e79a6aeaa7c6e274269c14e7c92b96fbd4d167d7219e7ca86225 |