The permanent of a (square) matrix, like the determinant is a polynomial in the entries of the matrix. Unlike the determinant, the signatures of the permutations are not taken into account making the permanent much more difficult to compute because decomposition methods cannot be used.
The permanent commonly appears in problems related to quantum mechanics, and the most common
brute-force combinatorial method has time complexity
This library aims to solve the need for an efficient library that solves the permanent of a given matrix.
permanent.opt()
Compute the permanent of a matrix using an automatically selected algorithm. The library uses a polynomial logistic regression model (degree 4) trained on benchmarks to predict whether Ryser's or Glynn's algorithm will be faster for the given matrix dimensions.
Parameters:
matrix:np.ndarray(M, N, dtype=(np.double|np.complex))
Returns:
permanent:(np.double|np.complex)- Permanent of matrix.
permanent.combinatoric()
Compute the permanent of a matrix combinatorically.
Formula:
Parameters:
matrix:np.ndarray(M, N, dtype=(np.double|np.complex))
Returns:
permanent:(np.double|np.complex)- Permanent of matrix.
permanent.glynn()
Formula:
Additional Information:
The original formula has been generalized here to work with
This can be neatly fit into the original formula by extending the inner sums over
Parameters:
matrix:np.ndarray(M, N, dtype=(np.double|np.complex))
Returns:
permanent:(np.double|np.complex)- Permanent of matrix.
permanent.ryser()
Formula:
Parameters:
matrix:np.ndarray(M, N, dtype=(np.double|np.complex))
Returns:
permanent:(np.double|np.complex)- Permanent of matrix.
The permanent package allows you to solve the permanent of a given matrix using the
optimal algorithm for your matrix dimensions.
Simply run:
pip install qc-permanentThis will install the package with pre-set parameters with a good performance for most cases. Advanced users can also compile the code locally and fine tune it for their specific architecture. They can either use the pre-defined parameters or fine tune them to their machine.
-
Install Python on your machine. Depending on your operating system, the instructions may vary.
-
Install gcc on your machine. Depending on your operating system, the instructions may vary.
-
Create and activate a virtual environment for this project named
permanents. One way to do this is with pip.python -m venv permanents source permanents/bin/activate -
Install Python dependencies:
pip install numpy pandas scikit-learn pytest
-
Install
qc-permanent.pip install .Optionally, install dependencies for building documentation (
doc), running the tuning algorithm (tune), and/or running the tests (test) by specifying them in square brackets:pip install '.[doc,tune,test]'
If you want to generate a machine-specific tuning header for building the library, you must first install with tuning dependencies, and then build with tuning enabled:
PERMANENT_TUNE=ON pip install '.[tune]'This compiles the code with machine specific tuning for algorithm swapping. Note that machine specific tuning will run a series of tests. This will take anywhere from 10 minutes to 1 hour depending on your system.
The C++ library can be used by including the
CMake project for matrix-permanent in your own CMake project.
The Makefile also acts as a convenience wrapper around the CMake
build for quickly compiling the C++ library.
This code is distributed under the GNU General Public License version 3 (GPLv3). See https://www.gnu.org/licenses/ for more information.