Skip to main content

Open source library for hafnian calculation

Project description

CircleCI Appveyor

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 have Python automatically install the correct binary, simply clone the git repository, and run the binary installation script:

git clone https://github.com/XanaduAI/hafnianplus
cd hafnianplus && python install_binary.py

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.

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.

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

hafnian-0.6.0.tar.gz (257.4 kB view details)

Uploaded Source

Built Distributions

hafnian-0.6.0-cp37-cp37m-win_amd64.whl (475.1 kB view details)

Uploaded CPython 3.7m Windows x86-64

hafnian-0.6.0-cp37-cp37m-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.7m

hafnian-0.6.0-cp37-cp37m-macosx_10_6_intel.whl (1.9 MB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

hafnian-0.6.0-cp36-cp36m-win_amd64.whl (475.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

hafnian-0.6.0-cp36-cp36m-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.6m

hafnian-0.6.0-cp36-cp36m-macosx_10_6_intel.whl (1.9 MB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

hafnian-0.6.0-cp35-cp35m-win_amd64.whl (474.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

hafnian-0.6.0-cp35-cp35m-manylinux1_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.5m

hafnian-0.6.0-cp35-cp35m-macosx_10_6_intel.whl (1.9 MB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

File details

Details for the file hafnian-0.6.0.tar.gz.

File metadata

  • Download URL: hafnian-0.6.0.tar.gz
  • Upload date:
  • Size: 257.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

Hashes for hafnian-0.6.0.tar.gz
Algorithm Hash digest
SHA256 19b06ec3233e41f34c8cefd0a2268b1493f220a53911f5a795914137b8e598b7
MD5 01a455f11df5b44c6fa832e6310d294a
BLAKE2b-256 9ae47c8292032de572f7db0da742560a40c47448c95263fface1cff96bfba929

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: hafnian-0.6.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 475.1 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

Hashes for hafnian-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 caa64080bfdb3c160a55e45d03caafc790324165b16cc04c6183773dcdfc58dd
MD5 1e1c42b45a370c93dfd3907a7e32e8e0
BLAKE2b-256 a4ccdde29395c2584dee34d70db05ba79273913bdfa78bd99efbc5d9f10dd318

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d36638e045fa4cad53db94630e20c1a47444ab4becd9cbc19a653605580ad3e5
MD5 3f058a007ed15312e12ec4738f85ddd5
BLAKE2b-256 d8fd359947bc10d7d434e2f96ae1d0fcba8c0dad2216d036adf52c045422ede4

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 33157f668b136d5549948d08c6efc043d108a4ecb4223750d6308cfcfa4131f2
MD5 9bbd1b72bb39d54911057b6cd9b9dba5
BLAKE2b-256 5a817a67fa0899bff8ea528edd83990ca089f3affc17b4abb273e0faed0d4098

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: hafnian-0.6.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 475.2 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

Hashes for hafnian-0.6.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a5daa3f35d3abf9b46d89d1b4faf9050afd9bf01e2353cfca59a7c24858038d0
MD5 a0417e8f21d4b5c43e9c7ad587c10c03
BLAKE2b-256 6fbffafad2cc6bc1ac0045bb7071b07f7623a4b6219e9de56b80d6966547471e

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4a94ef43f6425ce3dfb4de1c06e2d6f6e8c128f75229943b8de8dbd4169ec1a3
MD5 6c45340eb41a130a9648d2c6e64b51f0
BLAKE2b-256 629a02b1f263dc3698024e72d1cc938d1be3565efcf99fd287cdf6a63e18c174

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e15c3ebbfd3982ecddf1672d15f7ece55ca9892aa2f269ca663f12c7c596ac08
MD5 227e087d0f9470b75173ffe4b863f218
BLAKE2b-256 8b9a8210e4f393621530407385a80d33025ab4e80a5956ced3baa0042bbe1700

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: hafnian-0.6.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 474.8 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

Hashes for hafnian-0.6.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 f2592a52d7cbba6575d5862c161fc0560f1eafc23c2ca7df9861be9c9840f3c5
MD5 1db2b927fbc47d4863626e6627399585
BLAKE2b-256 d54a54ea6e23a4e323bbc0af5ff859c5c23451c4363a8f55f43e96d569d8f561

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 74df2855908badca9ab607a95836527f5d4847697dd1d105d3a46a1b86a163da
MD5 34e5b07840a98d07b35bb2b14fe9bdfc
BLAKE2b-256 d0f2f498131325130c5e70c68c4745ff77948298a1b5bead7959b7f373fbe9dc

See more details on using hashes here.

File details

Details for the file hafnian-0.6.0-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

  • Download URL: hafnian-0.6.0-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

Hashes for hafnian-0.6.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 331576d9425bdb65a4b42081b00c53f66b7b9153868f841d98d99ba52752dc7f
MD5 ca3c9e3a844f9c3406ee68397af643a5
BLAKE2b-256 cebef6cb3b5aa36248d93297dfc1361dfb161ade69ec6361eb9616b7655ecaad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page