Open source library for hafnian calculation
Project description
A library for the calculation of hafnians, Hermite polynomials and Gaussian boson sampling. For more information, please see the documentation.
Features
Fast calculation of hafnians, loop hafnians, and torontonians of general and certain structured matrices.
An easy to use interface to use the loop hafnian for Gaussian quantum state calculations.
Sampling algorithms for hafnian and torontonians of graphs.
Efficient classical methods for approximating the hafnian of non-negative matrices.
Easy to use implementations of the multidimensional Hermite polynomials, which can also be used to calculate hafnians of all reductions of a given matrix.
Installation
Pre-built binary wheels are available for the following platforms:
macOS 10.6+ |
manylinux x86_64 |
Windows 64bit |
|
---|---|---|---|
Python 3.7 |
X |
X |
X |
Python 3.8 |
X |
X |
X |
Python 3.9 |
X |
X |
X |
To install, simply run
pip install thewalrus
Compiling from source
The Walrus depends on the following Python packages:
In addition, to compile the C++ extension, the following dependencies are required:
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.
Cython an optimising static compiler for the Python programming language.
On Debian-based systems, these can be installed via apt and curl:
$ sudo apt install g++ libeigen3-dev
$ pip install Cython
or using Homebrew on MacOS:
$ brew install gcc eigen
$ pip install Cython
Alternatively, you can download the Eigen headers manually:
$ mkdir ~/.local/eigen3 && cd ~/.local/eigen3
$ wget https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-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 The Walrus can find the Eigen3 header files (if not provided, The Walrus will by default look in /use/include/eigen3 and /usr/local/include/eigen3).
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/thewalrus.git
$ cd thewalrus && python -m pip install -e .
OpenMP
libwalrus 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 libwalrus such that Eigen uses these frameworks as backends. As a result, all calls in the libwalrus 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 thewalrus --no-binary :all:
Alternatively, you may pass USE_OPENBLAS=1 to use the OpenBLAS library.
Software tests
To ensure that The Walrus 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
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 Walrus documentation is available online on Read the Docs.
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.
Contributing to The Walrus
We welcome contributions - simply fork The Walrus repository, and then make a pull request containing your contribution. All contributors to The Walrus will be listed as authors on the releases.
We also encourage bug reports, suggestions for new features and enhancements, and even links to projects, applications or scientific publications that use The Walrus.
Support
Source Code: https://github.com/XanaduAI/thewalrus
Issue Tracker: https://github.com/XanaduAI/thewalrus/issues
If you are having issues, please let us know by posting the issue on our Github issue tracker.
License
The Walrus is free and open source, released under the Apache License, Version 2.0.
Project details
Release history Release notifications | RSS feed
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
Hashes for thewalrus-0.15.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3f8a0ee06dfab4ac558791251428c962356e3f6a5fc7237397c677686f35eb7 |
|
MD5 | 327ad96b49be5edaa318002cb099e756 |
|
BLAKE2b-256 | 074d545f2dc83ea375b71a1a00e97c574c167cb1f3a80a511148fc9fd002bd07 |
Hashes for thewalrus-0.15.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02146c3b625265a74155882960f5a46ad82954aa24cf3a8d6f197e49cd6ef1b3 |
|
MD5 | 93ffe8a0ac0d542f7ee314dc22c5361b |
|
BLAKE2b-256 | a7ad4faea23861929979b8d3bbd328725636b33209d59ff71064fbe6a074a60b |
Hashes for thewalrus-0.15.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fcc7d0359c4c31eed8cf84978154109d30f1e8f0bac9aa06f7c14038db0d95a |
|
MD5 | 87b7850e7a995aae039097c5cfdcb1d6 |
|
BLAKE2b-256 | 36db1352ca7ad2c41592d493e6e0b69df2d4591730ba50b5d11299d1e74f0219 |
Hashes for thewalrus-0.15.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e3867f858c4e33b226792880a510d73e770ec6462efd6dea92bf20c0e9b7c8 |
|
MD5 | 7ccc51123193defed391372d3cc133c5 |
|
BLAKE2b-256 | 380c1944567dbe74bda5d52e845856e815a7e267e126d28dc9b0973df0284641 |
Hashes for thewalrus-0.15.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 781f2ac8e60fa08726715e444899d60424468876d0b01b5ec02cba02f2c4466d |
|
MD5 | 57f92ffa7609ed335e639ef37b6a496e |
|
BLAKE2b-256 | 2a0a9a6787be9f3aa913a1f17e7764132e04ee4466be9275d4f52e2fee34bb55 |
Hashes for thewalrus-0.15.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df83d0ae0741517543da4c26439a7dfa48c2f9dec09a5ca86135793e4cd15fb3 |
|
MD5 | 299df662d25bec39cba28e176ac592ec |
|
BLAKE2b-256 | 5d1519887ae2bc1003a9d06ca3fb30eeaed045024be07d4127d1d194fca1bbc5 |
Hashes for thewalrus-0.15.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f949727268ef1030328b118d053daeebc6af1abf4bbab530c8d35320f49492be |
|
MD5 | bd8edd76e351cdfb289cd94fb808938d |
|
BLAKE2b-256 | 762327d217b1e3927caab3810609ed0cbd3f3baaabc85732137587ef2e719f26 |
Hashes for thewalrus-0.15.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3dde7f1d70eab21fa7b3410dc985c23469c6d5990df0e12e470b7fbd090d7a3 |
|
MD5 | fae7694c42443178c3beb39046dc589c |
|
BLAKE2b-256 | 3b4616904b3ccbf8fa4c9f4016577f15c61ac7425911978c3d22b473e4e9323e |
Hashes for thewalrus-0.15.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ed9c7fdaf130c0e6ceafe242a00948c26ae1dd8d804de78a3d129ef47036b4 |
|
MD5 | 1e2a7493d5568ba946158b9a80e2d8a9 |
|
BLAKE2b-256 | c65502ed6cab50dc98fe9ef8a98ddfb7692a95f685920d858c3857fd35557854 |