Skip to main content

Extension module for computing permanents of square and rectangular matrices.

Project description

Python 3 pre-commit GNU GPLv3

Permanent

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 $\mathcal{O}(N!N)$, thus it is useful to look for more efficient algorithms. The two algorithms considered to be the fastest are one by Ryser (based on the inclusion-exclusion principle), and one by Glynn (based on invariant theory).

This library aims to solve the need for an efficient library that solves the permanent of a given matrix.

Algorithms

permanent.opt()

Compute the permanent of a matrix using the best algorithm for the shape of the given matrix.

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:

\text{per}(A) = \sum_{\sigma \in P(N,M)}{\prod_{i=1}^M{a_{i,{\sigma(i)}}}}

Parameters:

  • matrix: np.ndarray(M, N, dtype=(np.double|np.complex))

Returns:

  • permanent: (np.double|np.complex) - Permanent of matrix.

permanent.glynn()

Formula:

\text{per}(A) = \frac{1}{2^{N-1}} \cdot \sum_{\delta \in \left[\delta_1 = 1,~ \delta_2 \dots \delta_N=\pm1\right]}{
    \left(\sum_{k=1}^N{\delta_k}\right){\prod_{j=1}^N{\sum_{i=1}^N{\delta_i a_{i,j}}}}}

Additional Information: The original formula has been generalized here to work with $M$-by-$N$ rectangular permanents with $M \leq N$ by use of the following identity (shown here for $M \geq N$):

\text{per}\left(\begin{matrix}a_{1,1} & \cdots & a_{1,N} \\ \vdots & \ddots & \vdots \\ a_{M,1} & \cdots & a_{M,N}\end{matrix}\right) = \frac{1}{(M - N + 1)!} \cdot \text{per}\left(\begin{matrix}a_{1,1} & \cdots & a_{1,N} & 1_{1,N+1} & \cdots & 1_{1,M} \\ \vdots & \ddots & \vdots & \vdots & \ddots & \vdots \\ a_{M,1} & \cdots & a_{M,N} & 1_{M,N+1} & \cdots & 1_{M,M}\end{matrix}\right)

This can be neatly fit into the original formula by extending the inner sums over $\delta$ from $[1,M]$ to $[1,N]$:

\text{per}(A) = \frac{1}{2^{N-1}} \cdot \frac{1}{(N - M + 1)!}\cdot \sum_{\delta \in \left[\delta_1 = 1,~ \delta_2 \dots \delta_N=\pm1\right]}{
        \left(\sum_{k=1}^N{\delta_k}\right)
        \prod_{j=1}^N{\left(
            \sum_{i=1}^M{\delta_i a_{i,j}} + \sum_{i=M+1}^N{\delta_i}
        \right)}
    }

Parameters:

  • matrix: np.ndarray(M, N, dtype=(np.double|np.complex))

Returns:

  • permanent: (np.double|np.complex) - Permanent of matrix.

permanent.ryser()

Formula:

\text{per}(A) = \sum_{k=0}^{M-1}{
        {(-1)}^k
        \binom{N - M + k}{k}
        \sum_{\sigma \in P(N,M-k)}{
            \prod_{i=1}^M{
                \sum_{j=1}^{M-k}{a_{i,{\sigma(j)}}}
            }
        }
    }

Parameters:

  • matrix: np.ndarray(M, N, dtype=(np.double|np.complex))

Returns:

  • permanent: (np.double|np.complex) - Permanent of matrix.

Installation

The permanent package allows you to solve the permanent of a given matrix using the optimal algorithm for your matrix dimensions.

Installing from PyPI

Simply run:

pip install qc-permanent

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

Installing manually

  1. Install Python on your machine. Depending on your operating system, the instructions may vary.

  2. Install gcc on your machine. Depending on your operating system, the instructions may vary.

  3. Create and activate a virtual environment for this project named permanents. One way to do this is with pip.

    pip install virtualenv
    virtualenv permanents
    
  4. Activate the virtual environment.

    source permanents/bin/activate
    
  5. 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, preface the pip command with the corresponding environment variable like so:

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.

Using the C++ library

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.

License

This code is distributed under the GNU General Public License version 3 (GPLv3). See http://www.gnu.org/licenses/ for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

qc_permanent-0.0.1a6-cp312-cp312-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.12Windows x86-64

qc_permanent-0.0.1a6-cp312-cp312-musllinux_1_2_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

qc_permanent-0.0.1a6-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (117.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

qc_permanent-0.0.1a6-cp312-cp312-macosx_10_13_universal2.whl (161.5 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

qc_permanent-0.0.1a6-cp311-cp311-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.11Windows x86-64

qc_permanent-0.0.1a6-cp311-cp311-musllinux_1_2_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

qc_permanent-0.0.1a6-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (117.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

qc_permanent-0.0.1a6-cp311-cp311-macosx_10_9_universal2.whl (158.7 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

qc_permanent-0.0.1a6-cp310-cp310-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.10Windows x86-64

qc_permanent-0.0.1a6-cp310-cp310-musllinux_1_2_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

qc_permanent-0.0.1a6-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (117.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

qc_permanent-0.0.1a6-cp310-cp310-macosx_10_9_universal2.whl (158.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

qc_permanent-0.0.1a6-cp39-cp39-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.9Windows x86-64

qc_permanent-0.0.1a6-cp39-cp39-musllinux_1_2_x86_64.whl (199.9 kB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

qc_permanent-0.0.1a6-cp39-cp39-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (117.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

qc_permanent-0.0.1a6-cp39-cp39-macosx_10_9_universal2.whl (158.7 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file qc_permanent-0.0.1a6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5590e8ef587620a76e36bc023a4945d483d0871d5836bc8b2c2acb4d5f619a9f
MD5 9fe8c5c1812b20d8eb620eb2db9ce5a5
BLAKE2b-256 fe7d671b1b24aec76d416d2204399d521d582ba1648f6a16c647e97b01c486a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp312-cp312-win_amd64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6884eac2003a219b520b24e402b316da2a640cf38d5951f738c9c0b723098503
MD5 89ea8d6deeec852beb1e5466237db9b4
BLAKE2b-256 78e913bc181aec419a8935372c0a66400c21631a290eec51f58b93934a21dff6

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ae6f73c0d6aaede68b2f7d31020e288b1879e1ea0f14b395a90506fd45c557ce
MD5 eb6f8478b5f1fd22f805fbfe773b6af0
BLAKE2b-256 9ea6ea1330bdf7556c29eab5bba7e284aba0f8f18bce41c1d10a4aa413d1e065

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b1a448da4661ebebdd2f62fdce933134ca19e7f14cb3c14fa9ae7c8ec732c5d2
MD5 484727d1996d8fdab5fce0f68f4f12ff
BLAKE2b-256 02f005b208d87bc3b6f94af447c109f1d5a7d493004f49239265ecfa175a8908

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 65bb70bb456a1df4efffb4fb569af454af906c568be72dd4c360d2e9bce03f81
MD5 f2613c9f149a5e18b4e595d4db8b2be6
BLAKE2b-256 67e9f6001217a247668bb816a1a68653e31cb1a951b8a3e849540a7fce865d7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp311-cp311-win_amd64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f634c0a267ef0238ac1fbe55b3b9f9cfbe8e9db9349d922ae8c787d5e07db738
MD5 1d1cf4829e92d5a9038bfd6c90fcb029
BLAKE2b-256 3d3bdbe27a2a532b1de000198c2be9434e18af47f77df7bc44feb783f9ac8628

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2412503e744befa19fdc2f6d392cacb70b3282d50311fac81d8fe786072ab46e
MD5 9d8cb976ea7515b7e10912a11a1b8082
BLAKE2b-256 6216eba0187303c652f92a8ab39f9d6b4bc6f3d39def3b94947c4909f084e5dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9d4b2b19928f950dc2e24e7b5b2237f94bcc8a79460a8543205cabe1f67120a4
MD5 aa46226175b1c8c5096b497eebe795d6
BLAKE2b-256 288461369b958b0c14ee322bdc84e756c1f79901f1bb859efdc8a2aa24e00d89

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 230a3cb914f94d651be84fbf9930b493e4e5c63c5feae2f1e05752a6702212f2
MD5 2e30981cc1bc9319d655ef5ce2631c10
BLAKE2b-256 62cd57ab3f4b345d7d43e674f83d6b2fc62293bb72962c76ddbe311502798cec

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp310-cp310-win_amd64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d6bbe6fd8a7e07e66ad46ffe5cf9b551832da0270a0a32a63adf33f183f8d0fe
MD5 300f8f94e683d5f6e548550f519bcbb5
BLAKE2b-256 be696c8073fac886d80b9cbb2236b73c1e7d314ca7c55a6a3a14bc6dd0fe30bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 e550a68ad193e085dfdac476a1be32ece972f2d6750cf903d28e3c58ecc8c5e5
MD5 191b5277a20e9f81557d856bb4a41ef4
BLAKE2b-256 bf00ad136a01f7edd19e08e45fd2abc1c1aca3e6629b20347920f66a843a33c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2755c0a9723cb503e3b959eea988a9cf92d3a7542538e156ed614ebc8e7d7c6f
MD5 3c348da1fb0c705f56f748836a7db731
BLAKE2b-256 83e71640c9e936d8b5c98fb09f384ddfbc2efd8d3202f2826655cc10e9211cc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 04ffa6d70a5f9d9dd405cd17b61bcc84a233b466d7a957cbc95a2f0aba940965
MD5 f9a675cd23b1be4e86aa30eb5ee70434
BLAKE2b-256 564bd9fe16e25a5d716d4cc13f1d0622e9642f9a83e4c1b719950874fd8a60e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp39-cp39-win_amd64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 42092e0d62cd8f98e666b3ca78a389ed0b0a3301e9cdb3833cb0576a94b85e03
MD5 8ebe97dfbc92a3b4072d9f8d85a07bb5
BLAKE2b-256 27194b4bf9170ec99be059bc9955549b8ea9f8e4ddc7f12f51dfc0958523e417

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp39-cp39-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp39-cp39-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp39-cp39-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 a8ddc6f384bb7de6a4408843499198305f253645c1202c27bc63716565007933
MD5 7496f22dfa56afe8a5317df88eb00c80
BLAKE2b-256 7a8c13d96bdfe86a54fa0c5051bd080ce3a26ef93dc4222b287bda40aaa44189

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp39-cp39-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qc_permanent-0.0.1a6-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for qc_permanent-0.0.1a6-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 dd21bc49631f31dc0ccf8eda71482f722fad83d54d34cd2ae4415f6db99661a3
MD5 5221c3a50b9cfcb902d8943a21cf51da
BLAKE2b-256 f434acd59a2ee11ca17b21b6ffab29a0972a371ec3f7c49fff19389b581088e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for qc_permanent-0.0.1a6-cp39-cp39-macosx_10_9_universal2.whl:

Publisher: publish_pypi.yml on theochem/matrix-permanent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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