Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v0.6 of the hafnian library #10

Merged
merged 4 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,40 @@
#
version: 2.1
jobs:
tests:
cpptests:
docker:
- image: gcc:latest
working_directory: ~/circleci-googletest
environment:
TEST_RESULTS: /tmp/test-results
steps:
- run:
name: Install Dependencies
command: |
apt-get -y -q update
apt-get -y -q install cmake gcc libomp-dev libeigen3-dev
- run:
name: Install Google Test
working_directory: ~/googletest
command: |
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
- checkout
- run:
name: Build unit tests
command: |
cd src/tests
GOOGLETEST_DIR=/root/googletest make cpptests
- run:
name: Run unit tests
command: |
cd src/tests && ./cpptests
- store_test_results:
# This option doesn't expand $TEST_RESULTS if used.
path: /tmp/test-results

pythontests:
docker:
- image: circleci/python:3.6.8-stretch
working_directory: ~/tests
Expand All @@ -19,7 +52,6 @@ jobs:
command: |
sudo apt-get -qq update;
sudo apt-get install -y gcc gfortran libeigen3-dev;
curl -sL -o src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
Expand All @@ -45,7 +77,7 @@ jobs:
- image: circleci/python:3.6.8-stretch
environment:
CIBW_SKIP: "cp27-* cp34-* *i686"
CIBW_BEFORE_BUILD_LINUX: curl -sL -o {project}/src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90 && curl -OsL https://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz && tar xzf 3.3.7.tar.gz eigen-eigen-323c052e1731/Eigen --strip-components 1 && cp -rf Eigen {project}/src && pip install numpy scipy cython
CIBW_BEFORE_BUILD_LINUX: curl -OsL https://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz && tar xzf 3.3.7.tar.gz eigen-eigen-323c052e1731/Eigen --strip-components 1 && cp -rf Eigen {project}/src && pip install numpy scipy cython
CIBW_TEST_REQUIRES: numpy scipy pytest pytest-cov
CIBW_TEST_COMMAND: python -m pytest {project}/hafnian
steps:
Expand Down Expand Up @@ -78,7 +110,7 @@ jobs:
xcode: "10.0.0"
environment:
CIBW_SKIP: "cp27-* cp34-* *i686"
CIBW_BEFORE_BUILD_MACOS: wget -O {project}/src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90 && brew cask uninstall --force oclint && brew install gcc eigen libomp || true; brew install gcc eigen libomp && pip install numpy scipy cython
CIBW_BEFORE_BUILD_MACOS: brew cask uninstall --force oclint && brew install gcc eigen libomp || true; brew install gcc eigen libomp && pip install numpy scipy cython
CIBW_TEST_REQUIRES: numpy scipy pytest pytest-cov
CIBW_TEST_COMMAND: python -m pytest {project}/hafnian
steps:
Expand All @@ -87,6 +119,7 @@ jobs:
name: Build the OS X wheels.
command: |
pip install --user cibuildwheel
export PATH=$PATH:/Users/distiller/Library/Python/2.7/bin
cibuildwheel --output-dir wheelhouse
- run:
name: Upload OS X wheels.
Expand All @@ -108,4 +141,6 @@ workflows:
version: 2
all-tests:
jobs:
- cpptests
- linux-wheels
- osx-wheels
22 changes: 22 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Pull request template

Make sure you are up to date on the
[Hafnian workflow](https://github.com/XanaduAI/hafnianplus/wiki/Hafnian-GitHub-Flow)
before submitting the pull request.

When ready to submit, delete everything above the dashed line and fill in the pull
request template.

Please include as much detail as possible regarding the changes made/new features
added/performance improvements. If including any bug fixes, mention the issue numbers
associated with the bugs.

------------------------------------------------------------------------------------------------------------

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ coverage_html_report
hafnian/lib
src/*.o
src/timing

src/tests/*.o
src/tests/cpptests
docs/doxyoutput/*
docs/hafnian_cpp_api/*
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ ignored-classes=numpy,ctypes,hafnian.lib,hafnian.lib.libhaf,hafnian.lib.libperm,
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
disable=line-too-long,invalid-name,too-many-lines,redefined-builtin,too-many-locals,duplicate-code
disable=line-too-long,invalid-name,too-many-lines,redefined-builtin,too-many-locals,duplicate-code,bad-continuation
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ language: python
env:
global:
- CIBW_SKIP="cp27-* cp34-* *i686"
- CIBW_BEFORE_BUILD_LINUX='curl -sL -o {project}/src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90
&& curl -OsL https://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz
- CIBW_BEFORE_BUILD_LINUX='curl -OsL https://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz
&& tar xzf 3.3.7.tar.gz eigen-eigen-323c052e1731/Eigen --strip-components 1
&& cp -rf Eigen {project}/src && pip install numpy scipy cython'
- CIBW_BEFORE_BUILD_MACOS='wget -O {project}/src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90
&& brew cask uninstall --force oclint && brew install gcc eigen libomp || true; brew install gcc eigen libomp && pip install numpy scipy cython'
- CIBW_BEFORE_BUILD_MACOS='brew cask uninstall --force oclint && brew install gcc eigen libomp || true;
brew install gcc eigen libomp && pip install numpy scipy cython'
- CIBW_TEST_REQUIRES="numpy scipy pytest pytest-cov"
- CIBW_TEST_COMMAND="python -m pytest {project}/hafnian"
- WHEELHOUSE_UPLOADER_USERNAME=AKIAJOU6ECM5Q7T6UUQQ
Expand Down Expand Up @@ -46,7 +45,6 @@ before_install:
install:
- |
if [ "$WHEEL" = "0" ]; then
curl -sL -o src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90
pip install -r requirements.txt
pip install pytest pytest-cov wheel codecov
pip install -e .
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " install to install Hafnian"
@echo " libperm to compile the Fortran permanent library"
@echo " libtor to compile the Fortran torontonian library"
@echo " wheel to build the Hafnian wheel"
@echo " dist to package the source distribution"
@echo " clean to delete all temporary, cache, and build files"
@echo " clean-docs to delete all built documentation"
@echo " test to run the test suite"
@echo " test-cpp to run the C++ test suite"
@echo " test to run the Python test suite"
@echo " coverage to generate a coverage report"

.PHONY: install
Expand Down Expand Up @@ -46,8 +46,16 @@ doc:

.PHONY : clean-docs
clean-docs:
rm -rf docs/hafnian_cpp_api
make -C docs clean

test-cpp:
make -C src/tests clean
echo "Going to compile C++ tests"
make -C src/tests
echo "Compilation done for C++ tests"
make -C src/tests runtest

test:
$(PYTHON) $(TESTRUNNER)

Expand Down
71 changes: 42 additions & 29 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
Hafnian
#######

.. image:: https://img.shields.io/travis/XanaduAI/hafnian/master.svg?style=for-the-badge
:alt: Travis
:target: https://travis-ci.org/XanaduAI/hafnian
.. image:: https://circleci.com/gh/XanaduAI/hafnianplus.svg?style=svg&circle-token=e34895951dd90ef61a72c1928b4db7ba1e856f48
:alt: CircleCI
:target: https://circleci.com/gh/XanaduAI/hafnianplus

.. image:: https://ci.appveyor.com/api/projects/status/6wt68c81f8ly583s/branch/master?svg=true
:alt: Appveyor
:target: https://ci.appveyor.com/project/josh146/hafnianplus/branch/master

.. image:: https://img.shields.io/codecov/c/github/xanaduai/hafnian/master.svg?style=for-the-badge
:alt: Codecov coverage
:target: https://codecov.io/gh/XanaduAI/hafnian

.. image:: https://img.shields.io/codacy/grade/df94d22534cf4c05b1bddcf697011a82.svg?style=for-the-badge
:alt: Codacy grade
:target: https://app.codacy.com/app/XanaduAI/hafnian?utm_source=github.com&utm_medium=referral&utm_content=XanaduAI/hafnian&utm_campaign=badger

.. image:: https://img.shields.io/readthedocs/hafnian.svg?style=for-the-badge
:alt: Read the Docs
:target: https://hafnian.readthedocs.io

.. image:: https://img.shields.io/pypi/pyversions/hafnian.svg?style=for-the-badge
:alt: PyPI - Python Version
:target: https://pypi.org/project/hafnian

The fastest exact hafnian library for real and complex matrices. For more information, please see the `documentation <https://hafnian.readthedocs.io>`_.
The fastest exact hafnian library. For more information, please see the `documentation <https://hafnian.readthedocs.io>`_.

Features
========

* The fastest calculation of the hafnian, loop hafnian, permanent, and torontonian,
of general and certain structured matrices.
* 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

* An easy to use interface to use the loop hafnian to calculate Fock matrix
elements of Gaussian states via the included quantum module.
* 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
============
Expand All @@ -51,7 +38,7 @@ Pre-built binary wheels are available for the following platforms:
| Python 3.7 | ✅ | ✅ | ✅ |
+------------+-------------+------------------+---------------+

These can be installed using ``pip``:
To install, simply run

.. code-block:: bash

Expand All @@ -69,7 +56,6 @@ 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``
* The LINPACK_Q quadruple precision linear algebra library
* A C++11 compiler, such as ``g++`` >= 4.8.1, ``clang`` >= 3.3, ``MSVC`` >= 14.0/2015
* `Eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ - a C++ header library for linear algebra.

Expand All @@ -78,14 +64,12 @@ On Debian-based systems, these can be installed via ``apt`` and ``curl``:
.. code-block:: console

$ sudo apt install g++ gfortran libeigen3-dev
$ curl -sL -o src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90

or using Homebrew on MacOS:

.. code-block:: console

$ brew install gcc eigen
$ curl -sL -o src/linpack_q_complex.f90 https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90

Alternatively, you can download the Eigen headers manually:

Expand Down Expand Up @@ -142,6 +126,32 @@ To ensure that the Hafnian library is working correctly after installation, the

$ make test

To run the low-level C++ test suite, `Googletest <https://github.com/google/googletest>`_
will need to be installed. In Ubuntu-based distributions, this can be done as follows:

.. code-block:: console

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:

.. code-block:: console

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
=============

Expand All @@ -151,12 +161,15 @@ The Hafnian+ documentation is currently not hosted online. To build it locally,
* `sphinxcontrib-bibtex <https://sphinxcontrib-bibtex.readthedocs.io/en/latest/>`_ >=0.3.6
* `nbsphinx <https://github.com/spatialaudio/nbsphinx>`_
* `Pandoc <https://pandoc.org/>`_
* `breathe <https://breathe.readthedocs.io/en/latest/>`_ >=4.12.0
* `exhale <https://exhale.readthedocs.io/en/latest/>`_
* `Doxygen <http://www.doxygen.nl/>`_

They can be installed via a combination of ``pip`` and ``apt`` if on a Debian-based system:
::

$ sudo apt install pandoc
$ pip3 install sphinx sphinxcontrib-bibtex nbsphinx --user
$ 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

Expand Down
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ environment:
APPVEYOR_SKIP_FINALIZE_ON_EXIT: true
EIGEN_INCLUDE_DIR: C:\eigen-eigen-323c052e1731\
TEST_TIMEOUT: 1000
CIBW_BEFORE_BUILD: copy "C:\linpack_q_complex.f90" "{project}\src" && pip install numpy scipy cython
CIBW_BEFORE_BUILD: pip install numpy scipy cython
CIBW_SKIP: "cp27-* cp33-* cp34-* *win32"
CIBW_TEST_REQUIRES: "numpy scipy pytest pytest-cov"
CIBW_TEST_COMMAND: "python -m pytest {project}/hafnian"
Expand All @@ -21,7 +21,6 @@ matrix:


install:
- ps: wget https://raw.githubusercontent.com/josh146/linpack_q_complex/master/linpack_q_complex.f90 -outfile C:\linpack_q_complex.f90
- ps: wget http://bitbucket.org/eigen/eigen/get/3.3.7.zip -outfile eigen3.zip
- cmd: 7z x eigen3.zip -o"C:\" -y > nul

Expand All @@ -34,6 +33,8 @@ artifacts:
- path: "wheelhouse\\*.whl"
name: Wheels

skip_branch_with_pr: true

configuration: Debug

# override common configuration
Expand Down
Loading