Skip to main content

Quantum many body simulations with Pauli strings

Project description

Tests Status Documentation arXiv SciPost

PauliStrings Python

This is a Python version of PauliStrings.jl. The Julia version is more mature, we recommend using it if you can.

Getting started

Installation

Install from github:

pip install git+https://github.com/nicolasloizeau/paulistrings.py.git

Documentation

https://nicolasloizeau.github.io/PauliStrings.py/

Creating Operators

Import the library and initialize an operator of 4 qubits:

import paulistrings as ps
H = ps.Operator(4)

Add Pauli strings to the operator:

H += "XYZ1"
H += "1YZY"
print(H)
(1.0 + 0.0j) XYZ1
(1.0 + 0.0j) 1YZY

Add a Pauli string with a coefficient:

# Coefficients can be complex
H = ps.Operator(4)
H += -1.2, "XXXZ"
(1.0 + 0.0j) XYZ1
(1.0 + 0.0j) 1YZY
(-1.2 + 0.0j) XXXZ

Add a 2-qubit string coupling qubits i and j with X and Y:

i, j = 0, 2  # example qubit indices
H += 2.0, "X", i, "Y", j  # with coefficient=2
H += "X", i, "Y", j       # with coefficient=1

Add a 1-qubit string:

i = 1  # example qubit index
H += 2.0, "Z", i  # with coefficient=2
H += "Z", i # with coefficient=1

Basic Operations

Operators support standard arithmetic operations with other operators and numbers:

# Multiplication
H3 = H1 * H2

# Addition and subtraction
H3 = H1 + H2
H3 = H1 - H2

# Scalar operations
H3 = H1 + 2  # Adding a scalar (equivalent to adding identity times scalar)
H = 5 * H    # Multiply operator by a scalar

Common operations on operators:

# Trace of an operator
trace = ps.trace(H)

# Frobenius norm
norm = ps.opnorm(H)

# Number of terms in the operator
num_terms = len(H)  # or len(H.coeffs)

# Commutator [H1, H2] = H1*H2 - H2*H1
# This is more efficient than computing H1*H2 - H2*H1 directly
comm = ps.commutator(H1, H2)

Contributing, Contact

Contributions are welcome! Feel free to open a pull request if you’d like to contribute code or documentation. For bugs and feature requests, please [open an issue](https://github.com/nicolasloizeau/PauliStrings.py/issues). For questions, you can either contact nicolas.loizeau@nbi.ku.dk or start a new [discussion](https://github.com/nicolasloizeau/PauliStrings.py/discussions) in the repository.

Citation

@Article{Loizeau2025,
    title={{Quantum many-body simulations with PauliStrings.jl}},
    author={Nicolas Loizeau and J. Clayton Peacock and Dries Sels},
    journal={SciPost Phys. Codebases},
    pages={54},
    year={2025},
    publisher={SciPost},
    doi={10.21468/SciPostPhysCodeb.54},
    url={https://scipost.org/10.21468/SciPostPhysCodeb.54},
}

@Article{Loizeau2025,
    title={{Codebase release 1.5 for PauliStrings.jl}},
    author={Nicolas Loizeau and J. Clayton Peacock and Dries Sels},
    journal={SciPost Phys. Codebases},
    pages={54-r1.5},
    year={2025},
    publisher={SciPost},
    doi={10.21468/SciPostPhysCodeb.54-r1.5},
    url={https://scipost.org/10.21468/SciPostPhysCodeb.54-r1.5},
}

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

paulistrings-0.1.0.tar.gz (482.3 kB view details)

Uploaded Source

File details

Details for the file paulistrings-0.1.0.tar.gz.

File metadata

  • Download URL: paulistrings-0.1.0.tar.gz
  • Upload date:
  • Size: 482.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for paulistrings-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ee3483eb7e33712847b3a23acda459dcd98a92988170e0d6f8af662dc008d11
MD5 257282358eb9d31c51a83c7219a8b3fb
BLAKE2b-256 21d0fabae43e17e6f84af9f034bb206657feae0656f108cb014b6e09826da7a1

See more details on using hashes here.

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