Package: hafnian
The fastest exact hafnian library. For more information, please see thedocumentation.FeaturesThe 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 calculationsState of the art algorithms to sample from hafnian and torontonians of graphs.Efficient classical methods for approximating the hafnian of non-negative matrices.InstallationPre-built binary wheels are available for the following platforms:macOS 10.6+manylinux x86_64Windows 64bitPython 3.5✅✅✅Python 3.6✅✅✅Python 3.7✅✅✅To install, simply runpipinstallhafnianCompiling from sourceHafnian depends on the following Python packages:Python>=3.5NumPy>=1.13.3In addition, to compile the included Fortran and C++ extensions, the following dependencies are required:A Fortran compiler, such asgfortranA C++11 compiler, such asg++>= 4.8.1,clang>= 3.3,MSVC>= 14.0/2015Eigen3- a C++ header library for linear algebra.On Debian-based systems, these can be installed viaaptandcurl:$sudoaptinstallg++gfortranlibeigen3-devor using Homebrew on MacOS:$brewinstallgcceigenAlternatively, you can download the Eigen headers manually:$mkdir~/.local/eigen3&&cd~/.local/eigen3$wgethttp://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz-Oeigen3.tar.gz$tarxzfeigen3.tar.gzeigen-eigen-323c052e1731/Eigen--strip-components1$exportEIGEN_INCLUDE_DIR=$HOME/.local/eigen3Note that we export the environment variableEIGEN_INCLUDE_DIRso that Hafnian can find the Eigen3 header files (if not provided, Hafnian will by default look in/use/include/eigen3and/usr/local/include/eigen3).Once all dependencies are installed, you can compile the latest stable version of the Hafnian library as follows:$python-mpipinstallhafnian--no-binary:all:Alternatively, you can compile the latest development version by cloning the git repository, and installing using pip in development mode.$gitclonehttps://github.com/XanaduAI/hafnian.git$cdhafnian&&python-mpipinstall-e.OpenMPThe 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 MKLIf 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 thelapackeC++ LAPACK bindings installed (sudo apt installliblapacke-devin Ubuntu-based Linux distributions), and then compile with the environment variableUSE_LAPACK=1:$USE_LAPACK=1python-mpipinstallhafnian--no-binary:all:Alternatively, you may passUSE_OPENBLAS=1to use the OpenBLAS library.Software testsTo 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$maketestTo run the low-level C++ test suite,Googletestwill 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.aAlternatively, 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 installIf installing Googletest from source, make sure that the included headers and
libraries are available on your include/library paths.DocumentationThe Hafnian+ documentation is currently not hosted online. To build it locally, you need to have the following packages installed:Sphinx>=1.5sphinxcontrib-bibtex>=0.3.6nbsphinxPandocbreathe>=4.12.0exhaleDoxygenThey can be installed via a combination ofpipandaptif on a Debian-based system:$ sudo apt install pandoc doxygen
$ pip3 install sphinx sphinxcontrib-bibtex nbsphinx breathe exhaleTo build the HTML documentation, go to the top-level directory and run the command$makedocThe documentation can then be found in thedocs/_build/html/directory.AuthorsNicolás Quesada, Brajesh Gupt, and Josh Izaac.All contributions are acknowledged in theacknowledgments page.If you are doing research using Hafnian, please citeour paper:Andreas Björklund, Brajesh Gupt, and Nicolás Quesada. A faster hafnian formula for complex matrices and its benchmarking on the Titan supercomputerarXiv, 2018. arxiv:1805.12498SupportSource Code:https://github.com/XanaduAI/hafnianIssue Tracker:https://github.com/XanaduAI/hafnian/issuesIf you are having issues, please let us know by posting the issue on our Github issue tracker.LicenseHafnian isfreeandopen source, released under the Apache License, Version 2.0.