Skip to main content

Decomposition of a matrix into Pauli strings

Project description

Pauli LCU

Pauli LCU is a package for calculating the Pauli Decomposition of a complex matrix $A=\{a_{r,s}\}_{r,s=0}^{2^{n}-1}$:

    A=\sum_{r,s=0}^{2^n-1} \alpha_{r,s} \bigotimes_{j=0}^{n-1} P(r_j, s_j)

where

    \alpha_{r,s}\coloneqq \frac{i^{-|r\wedge s|}}{2^n} \sum_{q=0}^{2^n-1}a_{q\oplus r,q}(H^{\otimes n})_{q,s}, \qquad P(r_j, s_j) = i^{r_j\wedge s_j} X^{r_j} Z^{s_j} \in \{I, X, Y, Z\},

and $r_j, s_j$ are the binary expansion coefficients of $r$ and $s$, according to the algorithm presented in "Timothy N. Georges, Bjorn K. Berntson, Christoph Sünderhauf, and Aleksei V. Ivanov, Pauli Decomposition via the Fast Walsh-Hadamard Transform, https://doi.org/10.48550/arXiv.2408.06206, (2024)."

Installation

To install from PyPi:

$ pip install pauli_lcu

To install Python bindings from source:

$ git clone git@github.com:riverlane/pauli_lcu.git
$ cd pauli_lcu
$ pip install .

For use in C, pauli_decomposition.h can be used as a stand-alone library. Windows is not currently supported. In this case, we recommend to use WSL or Linux VM.

Examples for Python

Compute Pauli coefficients of a matrix:

>>> import numpy as np
>>> from pauli_lcu import pauli_coefficients
>>> num_qubits = 1
>>> dim = 2 ** num_qubits
>>> matrix = np.arange(dim*dim).reshape(dim, dim).astype(complex)  # generate your matrix
>>> pauli_coefficients(matrix)   # calculate coefficients, stored in matrix, original matrix is overwritten
>>> matrix
array([[ 1.5+0.j , -1.5+0.j ],
       [ 1.5+0.j ,  0. -0.5j]])

One can also obtain the corresponding Pauli strings:

>>> from pauli_lcu import pauli_strings
>>> strings = pauli_strings(num_qubits)   # calculate Pauli strings
>>> for p_string, p_coeff in np.nditer([strings, matrix]):
...     print(p_string, p_coeff)
...
I (1.5+0j)
Z (-1.5+0j)
X (1.5+0j)
Y -0.5j

For large matrices generating all Pauli strings is memory expensive. In this case, one can access a Pauli string as follows:

>>> from pauli_lcu import pauli_string_ij
>>> it = np.nditer(matrix, flags=['multi_index'])
>>> for x in it:
...    print(pauli_string_ij(it.multi_index, num_qubits), x)
I (1.5+0j)
Z (-1.5+0j)
X (1.5+0j)
Y -0.5j

If you would like to access the array and Pauli strings in lexicographical order (eg $II$, $IX$, ...) then you can do:

>>> from pauli_lcu import lex_indices
>>> for id in range(dim**2):
...     mult_ind = lex_indices(id)
...     print(pauli_string_ij(mult_ind, num_qubits), matrix[mult_ind])
I (1.5+0j)
X (1.5+0j)
Y -0.5j
Z (-1.5+0j)

Alternatively, you can use pauli_lcu.pauli_coefficients_lexicographic() which uses extra memory to return lexicographically ordered coefficients.

If you would like to restore original matrix elements apply inverse Pauli decomposition:

>>> from pauli_lcu.decomposition import inverse_pauli_decomposition
>>> inverse_pauli_decomposition(matrix)
>>> matrix
array([[0.+0.j, 1.+0.j],
       [2.+0.j, 3.+0.j]])

However, keep in mind that if you used pauli_lcu.pauli_coefficients_lexicographic(), you can't use inverse_pauli_decomposition since it's not implemented for lexicographically ordered arrays.

We also added ZX-decomposition which can be used in Qiskit (you need it to install qiskit for this example):

>>> from pauli_lcu.decomposition import pauli_coefficients_xz_phase
>>> x, z, phase = pauli_coefficients_xz_phase(matrix)
>>> x 
array([[0],
       [1],
       [0],
       [1]], dtype=int8)
>>> from qiskit.quantum_info import PauliList
>>> PauliList.from_symplectic(z, x)
PauliList(['I', 'Z', 'X', 'Y'])

References

If you find this package useful please cite our paper:

Timothy N. Georges, Bjorn K. Berntson, Christoph Sünderhauf, and Aleksei V. Ivanov, Pauli Decomposition via the Fast Walsh-Hadamard Transform, New J. Phys. 27 033004 (2025), https://doi.org/10.1088/1367-2630/adb44d.

Project details


Download files

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

Source Distribution

pauli_lcu-1.0.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distributions

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

pauli_lcu-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (33.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (15.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pauli_lcu-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (32.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (15.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pauli_lcu-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (32.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.1-cp310-cp310-macosx_11_0_arm64.whl (15.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pauli_lcu-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (31.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.1-cp39-cp39-macosx_11_0_arm64.whl (15.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file pauli_lcu-1.0.1.tar.gz.

File metadata

  • Download URL: pauli_lcu-1.0.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pauli_lcu-1.0.1.tar.gz
Algorithm Hash digest
SHA256 231cdd3a4df26926f246444538094cb173ea9d3ea94a2aaff394226c39bdf1c9
MD5 0e7c9aa28984e23cc12c9a17780445b6
BLAKE2b-256 9f9a8778524f755e8ee22621b6690985501d6a690b1f75140215afc71b52bd86

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1.tar.gz:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01ddcc861338635703a76f7085ccf372d3c29a488fd4d717ac578212c2d9139f
MD5 bcfaf3a863b10f4a00acabe083d1a858
BLAKE2b-256 f59d7dab02f5d9c1021cd83e1cca8c697a41c7407931521b8b4f642a02f6ca52

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50a28a92247a844a26311311ed978a3fed442f5d98816d7fa2c2b5127de7f158
MD5 677f12f8abceb7f8f654df15be06b5ff
BLAKE2b-256 7bda930a8dc35ec8fb2a5282be3155a24e99cf8cc80021243d4af8b41ded999e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9a5cd2bf641af0574fe0d795f3a0e73b96b8dde86124168c6c07486a41d1582
MD5 98b30916396dcd0adcaeca487d2a9555
BLAKE2b-256 731f75bd816eb770824ee9f4276483db4ba3628d4d11f92ffbf956c8839a4d23

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 261643f70b3751328542f3c3d068d58a3fe862d33392e3fa26dac6d98ce36473
MD5 234b5c328467409a00d1a03aa816595d
BLAKE2b-256 127129f331d75d2ddfa364c18317f938280c64d720ff1945a02e4c124daa8775

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc9ccda59509971b07995ecf3bd88a9002d29e819368ed69b9983845e864eb09
MD5 f110c397bca2d2032715530ef943ba49
BLAKE2b-256 3d66d8d95c6627ff0683c0236b107aec53a068a185ff70c8c764ba415e600e17

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a217bec7d5b359fe8cb35694a8d23719b14407e74853845ddd43b6cb7cf068b5
MD5 8f59768456fed06c810c2270cd94101b
BLAKE2b-256 ef336802f7034873a6637742d4c3235792c11dac7b30e40aef4fff50c90b1aa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e6aa104a9554b90a585ec81b57d2a46dffb11f6ce3152eecd89d944fc942dbc
MD5 fc1960a9af53c212547c97546ed33ee9
BLAKE2b-256 f6e895baadd864394b7a15073c974a18bc277628b0c9eee57c1039b9602deb93

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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

File details

Details for the file pauli_lcu-1.0.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0316866c194c3fa4d46b16cc7e40eec528fcdaa1ec4743eee9b273c3875c465e
MD5 968a84d326f801ccae83fe6f70950568
BLAKE2b-256 70cd4a0cd7255a4a91bc7783cd742e25f44ad86a869bf4ca8f550049b0c413a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pauli_lcu-1.0.1-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: publish_to_pypi.yaml on riverlane/pauli_lcu

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