Skip to main content
CircleCI Appveyor Codecov coverage Codacy grade Read the Docs PyPI - Python Version

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.

Authors

Nicolás Quesada, Brajesh Gupt, and Josh Izaac.

All contributions are acknowledged in the acknowledgments page.

If you are doing research using Hafnian, please cite our paper:

Andreas Björklund, Brajesh Gupt, and Nicolás Quesada. A faster hafnian formula for complex matrices and its benchmarking on the Titan supercomputer arXiv, 2018. arxiv:1805.12498

Support

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.

Metadata

Release files for hafnian 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hafnian 0.6.1
File Size Uploaded
hafnian-0.6.1.tar.gz 261.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for hafnian 0.6.1
File
hafnian-0.6.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
hafnian-0.6.1-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
hafnian-0.6.1-cp37-cp37m-macosx_10_6_intel.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
hafnian-0.6.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
hafnian-0.6.1-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
hafnian-0.6.1-cp36-cp36m-macosx_10_6_intel.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
hafnian-0.6.1-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
hafnian-0.6.1-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
hafnian-0.6.1-cp35-cp35m-macosx_10_6_intel.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) Details

Total release size: 23.4 MB

Release files / hafnian-0.6.1.tar.gz

Download URL hafnian-0.6.1.tar.gz
Size 261.4 kB
Tags Source
SHA-256 checksum
How to use checksums
88c77180a312125fc1cf8f7f5573882b82a3587be09ece836992cce6249ffff6
BLAKE2b-256 checksum
How to use checksums
2b5682c04b1977e42dfe1c5fe676c298c59958420ee22b2ea1e4c5989d00ddaa
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp37-cp37m-win_amd64.whl

Download URL hafnian-0.6.1-cp37-cp37m-win_amd64.whl
Size 477.0 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
3176608bf72d8a05332f89107293040a8f20e9ac7978c80c81c7fa29bf24225f
BLAKE2b-256 checksum
How to use checksums
b59040fd46354774ea48f71c90b2b39d1b383a558f69908d6d4e2408618decda
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp37-cp37m-manylinux1_x86_64.whl

Download URL hafnian-0.6.1-cp37-cp37m-manylinux1_x86_64.whl
Size 5.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
2b9c6926abe4884aca8528efcb9a79e3aaab6797954507c84277d02c1cb9b4d2
BLAKE2b-256 checksum
How to use checksums
371b0d120dbbab2b6f243d04b4fe29e16f856cff9679f08de49c87cde935bc67
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp37-cp37m-macosx_10_6_intel.whl

Download URL hafnian-0.6.1-cp37-cp37m-macosx_10_6_intel.whl
Size 1.9 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
cfcb45bc5fd66e6e1277a390f98b1d506f15ae2ac11279dc5bb3ed07d617b0aa
BLAKE2b-256 checksum
How to use checksums
ee119ff56de1ff67ae98c747c88a694cd1a5f6908e38c477c7afb5ae3c7f8833
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp36-cp36m-win_amd64.whl

Download URL hafnian-0.6.1-cp36-cp36m-win_amd64.whl
Size 477.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
2b2e1cfc640328fd7c6da5e74d695e65b7cce50ac444ca024110e1a1f03ec1bb
BLAKE2b-256 checksum
How to use checksums
bc035a92168cfd86619c425cd1726e4e14901c54a17b91b455dc6651a48538c6
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp36-cp36m-manylinux1_x86_64.whl

Download URL hafnian-0.6.1-cp36-cp36m-manylinux1_x86_64.whl
Size 5.3 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4e5ff2c90490f6df904683efb7bd971c9b59ab4171537d0140c25f206ddd6362
BLAKE2b-256 checksum
How to use checksums
5c182b88829f5f3dc284696496885669dc7c1d45d2cc42c8fa294da813ace47a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp36-cp36m-macosx_10_6_intel.whl

Download URL hafnian-0.6.1-cp36-cp36m-macosx_10_6_intel.whl
Size 1.9 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
42cc014b8f28fbe53c44c9e58f3948710f6691cf3c0ebec76a99aac6d2000e85
BLAKE2b-256 checksum
How to use checksums
1d14c6353a62e295ce3dfd007416c4968ffde8d40147ba45a7b1816bef0e9898
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp35-cp35m-win_amd64.whl

Download URL hafnian-0.6.1-cp35-cp35m-win_amd64.whl
Size 476.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
57e2eac9c3f5007b60943b03030baa8bfb250fb3377c8d221927d39f2794fff7
BLAKE2b-256 checksum
How to use checksums
d8754a8725e93c39396ef99779de74e81af79f2343f465e4027a486693d966f2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp35-cp35m-manylinux1_x86_64.whl

Download URL hafnian-0.6.1-cp35-cp35m-manylinux1_x86_64.whl
Size 5.3 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0e8c819b07bcf3017dfd22f03acde4c4fc30bf280769dd164fb56f99a8e7af58
BLAKE2b-256 checksum
How to use checksums
c741ebb2dc474fecee27086530b7a0173a1c0185164fdf9ab26395d015fac69e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / hafnian-0.6.1-cp35-cp35m-macosx_10_6_intel.whl

Download URL hafnian-0.6.1-cp35-cp35m-macosx_10_6_intel.whl
Size 1.9 MB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
044e442e7926b7ad8760da4e8299da1ff3b8c5b983a9b543dc179942b0441dbb
BLAKE2b-256 checksum
How to use checksums
73ee162e8c87e79a6aeaa7c6e274269c14e7c92b96fbd4d167d7219e7ca86225
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.6.1 This release

10 release files

0.6.0

10 release files

0.5.0

10 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page