Skip to main content

A lightweight quantum computing library for foundational tools and mathematical operations.

Project description

Qlibx: A Quantum Computing Library

Qlibx is a Python library designed to provide foundational tools for quantum computing. It offers classes and methods to represent and manipulate quantum states, operators, and their interactions. The library is lightweight and focuses on the mathematical foundations of quantum mechanics, making it an excellent choice for learning and experimentation.


Features

  • Quantum States:

    • Ket and Bra classes to represent quantum states.
    • Support for operations like addition, subtraction, scalar multiplication, tensor products, and inner/outer products.
  • Quantum Operators:

    • Operator class to represent quantum operators.
    • Methods for Hermitian, unitary, and normality checks.
    • Commutator and anti-commutator calculations.
    • Spectral decomposition and partial trace.
    • Von Neumann entropy calculation.
  • Predefined Operators:

    • Pauli matrices (pauli_x, pauli_y, pauli_z) and the identity matrix.

Installation

pip install qlibx

or

Clone the repository and include the library in your Python project:

git clone https://github.com/Suraj52721/qc_lib/tree/master
cd qlibx

Ensure the qlibx directory is in your Python path.


Usage

Importing the Library

from qlibx import Ket, Bra, Operator

Creating Quantum States

# Create a Ket vector
ket = Ket([1, 0])

# Create a Bra vector
bra = Bra([1, 0])

Quantum Operations

Addition and Subtraction

ket1 = Ket([1, 0])
ket2 = Ket([0, 1])

# Addition
result_add = ket1 + ket2
print(result_add)

# Subtraction
result_sub = ket1 - ket2
print(result_sub)

Scalar Multiplication

ket = Ket([1, 0])

# Scalar multiplication
result_scalar = 2 * ket
print(result_scalar)

Tensor Product

ket1 = Ket([1, 0])
ket2 = Ket([0, 1])

# Tensor product
result_tensor = ket1.tensor(ket2)
print(result_tensor)

Inner and Outer Products

ket = Ket([1, 0])
bra = Bra([1, 0])

# Inner product
inner = ket.inner_product(bra)
print(inner)

# Outer product
outer = ket.outer_product(bra)
print(outer)

Working with Operators

Defining and Applying Operators

# Define an operator
op = Operator([[0, 1], [1, 0]])

# Apply operator to a Ket
ket = Ket([1, 0])
result = op.op(ket)
print(result)

Hermitian, Unitary, and Normality Checks

op = Operator([[0, 1], [1, 0]])

# Check if the operator is Hermitian
print(op.hermitian())

# Check if the operator is Unitary
print(op.unitary())

# Check if the operator is Normal
print(op.normal())

Commutator and Anti-Commutator

op1 = Operator([[0, 1], [1, 0]])
op2 = Operator([[1, 0], [0, -1]])

# Commutator
commutator = op1.commutator(op2)
print(commutator)

# Anti-commutator
anti_commutator = op1.anti_commutator(op2)
print(anti_commutator)

Spectral Decomposition

op = Operator([[2, 1], [1, 2]])

# Spectral decomposition
spectral_decomp = op.spectral_decom()
print(spectral_decomp)

Partial Trace

op = Operator([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

# Partial trace over the first subsystem
partial_trace_result = op.partial_trace([2, 2], 0)
print(partial_trace_result)

Von Neumann Entropy

op = Operator([[0.5, 0], [0, 0.5]])

# Von Neumann entropy
entropy = op.von_neumann_entropy()
print(entropy)

Example: Quantum Circuit Simulation

from qlibx import Ket, Operator

# Define a quantum state |ψ⟩
psi = Ket([1, 0])

# Define a Pauli-X gate
pauli_x = Operator(Operator.pauli_x)

# Apply the gate
new_state = pauli_x.op(psi)

print(new_state)

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.


License

This project is licensed under the MIT License.


Acknowledgments

Qlibx is inspired by the mathematical foundations of quantum mechanics and aims to provide an intuitive interface for quantum computing enthusiasts.

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

qlibx-1.0.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

qlibx-1.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file qlibx-1.0.2.tar.gz.

File metadata

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

File hashes

Hashes for qlibx-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e09aa24c4a9b0727bf920de445b50c42f2c1d100bbe71c2121adaba097b1b37d
MD5 a1d2635922b17537df153a2d1d419081
BLAKE2b-256 28896b0f51cdcae043125c96ff88fd67fd156b2d257bc875fdf4c98438c17c03

See more details on using hashes here.

File details

Details for the file qlibx-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: qlibx-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for qlibx-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61e29e4cb387c13dc058020b11f63d5905cc0a2a53e17553c0e1e554ecb58539
MD5 ac58f734a87367ffc29b639311a004f2
BLAKE2b-256 52b2e1742436e898acfae586481dc5785afebfff17a9f089ffb2c3c62d72d4f8

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