The Walrus Documentation

Responsive image

A library for the calculation of hafnians, Hermite polynomials, and Gaussian boson sampling.


  • 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.

Getting started

To get the The Walrus installed and running on your system, begin at the download and installation guide. Then, familiarise yourself with some background information on the Hafnian and the computational algorithm.

For getting started with using the The Walrus in your own code, have a look at the Python tutorial.

Finally, detailed documentation on the code and API is provided.


If you are having issues, please let us know, either by email or by posting the issue on our Github issue tracker.


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

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

Brajesh Gupt, Josh Izaac and Nicolás Quesada. The Walrus: a library for the calculation of hafnians, Hermite polynomials and Gaussian boson sampling. Journal of Open Source Software, 4(44), 1705 (2019)


The Walrus library is free and open source, released under the Apache License, Version 2.0.