PauliAlgebra
PauliAlgebra is a module to deal with exact calculations of Pauli matrices
The interface to the module is the class PauliVector that can be used to instantiate any 2x2 Hermitian matrix
from PauliAlgebra import PauliVector
M = PauliVector([
1, # Identity
2, # sigma x
0, # sigma y
1j # sigma z
])
PauliVectoris fully compatible withsympyexpressions!
Alternatively, the module exposes the standard matrices
-
Id:2x2Identity -
sigma_x -
sigma_y -
sigma_z -
sigma_plussigma_plus = (sigma_x + 1j*sigma_y)/2 # ((0,1) # (0,0))
-
sigma_minus=(sigma_x - 1j*sigma_y)/2sigma_minus = (sigma_x - 1j*sigma_y)/2 # ((0,0) # (1,0))
-
P_upP_up = (Id + sigma_z)/2 # ((1,0) # (0,0))
-
P_downP_down = (Id - sigma_z)/2 # ((0,0) # (0,1))
Arithmetic Operations
PauliVector supports the following arithmetic operations:
- Addition and subtraction with another
PauliVector - Multiplication with a scalar or another
PauliVector(performs matrix multiplication) - Division by a scalar
So the above example could have been written as
from PauliAlgebra import (
Id,
sigma_x,
sigma_z
)
M = Id + 2*sigma_x + 1j*sigma_z
Commutators and Anticommutators
This module allows for fast adn exact computation of commutators and anticommutators of two PauliVector using the relationship
$$ \left(\vec{a} \cdot \vec{\sigma}\right)\left(\vec{b} \cdot \vec{\sigma}\right) = Id~ \left(\vec{a} \cdot\vec{b} \right) + i \left(\vec{a} \times\vec{b} \right) \cdot \vec{\sigma} $$
and the (anti)commutativity of dot and cross product.
A = sigma_x
B = sigma_y
commAB = PauliVector.commutator(A,B) # = 2j*sigma_z
anticommAB = PauliVector.anticommutator(A,B) # = 0
Exponentiation
PauliVector supports exponentiation with the standard formula
$$ \exp\left(i \theta \hat{n} \cdot \vec{\sigma} \right) = Id~ \cos{\theta} + i \hat{n} \cdot \vec{\sigma} \sin{\theta} $$
M = -1j*np.pi*sigma_x
expM = M.exponentiate() # == Id
Usage with sympy expressions
PauliVector is fully compatible with sympy expressions!
theta = sp.symbols(r'\theta')
M = (Id* sp.sin(theta) + sigma_z*sp.cos(theta))/sp.sqrt(2)
M.to_sp().applyfunc(sp.trigsimp)
# [sqrt(2)*sin(\theta + pi/4), 0],
# [ 0, -sqrt(2)*cos(\theta + pi/4)]]
For complex expressions
M.simplify()will simplify theId,x,y, andzcomponents
Going back to numpy or sympy
Once you are done performing algebra on a PauliVector you can turn it back into more common types
M.toMatrix()->np.ndarray(shape==(2,2))M.to_sp()->sp.Matrix(shape==(2,2))
Installation
PauliAlgebra is available on pypi!
It can be yours by simply
$ pip install PauliAlgebra
in the environment of your choice!
Metadata
Release files for PauliAlgebra 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| paulialgebra-1.0.0.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| PauliAlgebra-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / paulialgebra-1.0.0.tar.gz
| Download URL | paulialgebra-1.0.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bb802da5db2ed5c012f76a30ff7c52f734858fd1d51ad3b8b90f8f2c06dbe3b
|
|
BLAKE2b-256 checksum How to use checksums |
c051143c2c50ef31966ecc46d4aba00151c45d0bb376058f4179417a4751f6ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / PauliAlgebra-1.0.0-py3-none-any.whl
| Download URL | PauliAlgebra-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cb4deecd38a1d1494a6c7f21eec0feee20cfb8ba7e6bc77f2c6457be4fb3dce
|
|
BLAKE2b-256 checksum How to use checksums |
f754bd25d83ef99a530aeff3f14401ab431b2e1b5c6d1a5bcb26998915701034
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|