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
>>> pauli_coefficients_xz_phase(matrix)
>>> 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, https://doi.org/10.48550/arXiv.2408.06206, (2024).

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.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distributions

pauli_lcu-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (14.9 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pauli_lcu-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (14.8 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pauli_lcu-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (33.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (14.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pauli_lcu-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (33.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (14.8 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pauli_lcu-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (32.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pauli_lcu-1.0.0-cp38-cp38-macosx_11_0_arm64.whl (14.9 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pauli_lcu-1.0.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pauli_lcu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e48c2ebb7d53739d91dd507fd39c9fde3337dd0678d9d42dfaa11bee0dc2807e
MD5 f0fb0391d89bf9c4f3782ff9365fb94a
BLAKE2b-256 c01a365ac3189b8f3bfac202b99b2ba81e2d0670eff7220bdc05f3a2e5c2bdb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 890c6527b7976b4b58a5cda11c6c81be97961c3eb2f76c7d2326924fc6f72557
MD5 d971d7451a632b7cd2342b763b71133a
BLAKE2b-256 edee352c7b36c506c285d40e330de87174a6db16c58e9794048bd32dd4bfc027

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 39b9a08566412f8f23e447c453cd1720bc158d11d1798e7cec21a3921953cb20
MD5 d4dac44e093cb41f72708f223c664b06
BLAKE2b-256 aa4b383b4967ca9cf69f88831f64640eeaa12939401bde3b6812b9bb34b2413d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a4ee0c4282301b87415c143e60815128e12c4e740aff5c4e0888fecfb985adc
MD5 10cfa9122d6795c5e653ed699040d84e
BLAKE2b-256 c7be035c28c744c32c379388feec8d1fb39eae4600c82ae23a24426fcfafd135

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80427ffbe20f3a59c9b8f80ff409e254dbe91270e72efa4628655e2d6f0dbc71
MD5 4b0d980cb8133f46b8d6c6400bc08452
BLAKE2b-256 8d688c740a7c3c3e1b0cc02de3504e675cf6f7ed92bcad96e594f83926ea4181

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75aa75af8c9a2c3235d174fc1abadccaa448b3c2222c68ecde354d27d8bae849
MD5 bfad828a2a2ad438887bde5fe9cc1827
BLAKE2b-256 2bc2a28e9374cab10601ede7531a86b3dbddc8ecdb6b36cc2cd48fd1f3f72f72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33ced0bd87f1253e47b374a9afa9d6825c1789f681ef1b67db11e735830a9c96
MD5 331ca33e06e560fe7ee2870d4f1773d0
BLAKE2b-256 d62a3d561b935fc7eb4a95c1e6a2c860d790ed93a2782c74b819bc6fd229792b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b63415b3f2ff6bc24e49d9589bf8fd782b536899ab787954b0e8c815c5102ae
MD5 b009833954bc08f415e99094ae28d324
BLAKE2b-256 3acf381c2f443b3a1b902b508e74bc34f69340cadf17cb01f9c460d5681ed268

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dc9d73607346d274986ecfb44961ebe62cd46d1c4314687e9b7e5aee5339531a
MD5 878864dec32d271fc1aaea1e25519c77
BLAKE2b-256 7be0906c73052999c54e96138af4f6cd11173f2326653d0d47aa07a040934d28

See more details on using hashes here.

File details

Details for the file pauli_lcu-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 68c144e0590dd3bad3e72f0406461cf434cc9831deb3e768b813fa757afd9fc2
MD5 7b86b221f72c6c097a24fcc87f42b60a
BLAKE2b-256 85ec369b34100ab5c616aa1d6d6e41105a92e565c5da74c692e32018d64cad21

See more details on using hashes here.

File details

Details for the file pauli_lcu-1.0.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pauli_lcu-1.0.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ed3aa8e668d35ba5de1a4d0df18232707cd421fe6044e1ccf85cfe83d501ed2
MD5 8421d5fb186edcb5dea75dd2ac6883d0
BLAKE2b-256 42facaecffac4b417931ae32df7c77832f5cf2f49d983d6bc40f8e2e30666502

See more details on using hashes here.

Supported by

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