Skip to main content

Quantum Mathematics Framework

Project description

QMath: Quantum Mathematics Framework

Developer: Patnam Kannabhiram From A7's Garage

QMath serves as the foundation for QEssential, a package that will build upon it.


QMath is a high-performance, Quantum Mathematics and Simulation framework. It features a templated, multi-threaded C++20 core bound seamlessly to a pythonic interface using pybind11 and scikit-build-core.

By combining the speed of optimized C++ (leveraging cache-friendly layouts and OpenMP parallelism) with the agility of Python, QMath enables rapid prototyping of quantum states, custom gates, circuits, and advanced quantum algorithms.


Key Features

  • Core Linear Algebra: High-performance Vector, Matrix, and multi-dimensional Tensor core types supporting float32, float64, complex64, and complex128.
  • Advanced Decompositions: LU, QR, Cholesky, and Jacobi Eigenvalue solver (Hermitian/Symmetric).
  • Quantum Mechanics Core:
    • Full support for both Pure States (state vectors) and Mixed States (density matrices).
    • Expectation values, von Neumann entropy, purity, quantum fidelity, and partial traces.
    • State factories for single qubits, Bell states, GHZ states, W states, and Haar random states.
  • Circuit Simulation Engine:
    • Full single-qubit and multi-qubit gate sets.
    • Evolutionary simulation (unitary application for state vectors and density matrices).
    • Single-qubit measurement collapse and multi-shot outcome sampling.
    • Text-based ASCII circuit visualizer.
  • Quantum Algorithms:
    • Quantum Fourier Transform (QFT).
    • Grover's Search Algorithm.
    • Deutsch-Jozsa Algorithm (Constant vs. Balanced oracle testing).
    • Variational Quantum Eigensolver (VQE) bound to C++ Newton-Raphson parameter minimizers.
  • Numerical Formulas: Central/second-order differentiation, Jacobian generation, trapezoidal/Simpson integration, gradient descent, and Conjugate Gradient linear solvers.
  • Symbolic Math Engine: Expression tree formulation for symbols, constants, and basic algebra.

Installation

Prerequisites

QMath requires a C++20 compatible compiler (e.g., GCC 10+, MSVC 2019+, or Clang 10+).

Building from Source

Install the package directly using pip:

pip install .

For developer / editable installations:

pip install -e .

Note: scikit-build-core will automatically fetch cmake and ninja dependencies during the build.


Quick Start Examples

1. Simulating a Bell State

from qmath import QuantumCircuit

# 1. Create a 2-qubit circuit
qc = QuantumCircuit(2)

# 2. Apply Hadamard on qubit 0 and CNOT controlled on 0 targeting 1
qc.h(0)
qc.cx(0, 1)

# 3. Print the ASCII diagram
print("Circuit Diagram:")
print(qc.draw())

# 4. Simulate the statevector evolution
state = qc.simulate()
print("\nFinal State Vector:")
print(state)

# 5. Sample measurement outcomes (1024 shots)
counts = qc.sample(shots=1024)
print("\nMeasurement counts:")
print(counts)

2. Variational Quantum Eigensolver (VQE)

import numpy as np
from qmath import Matrix
from qmath.formulas.algorithms import vqe

# Create a sample diagonal Hamiltonian where the ground state energy is 0.5
H_data = np.diag([1.5, 2.5, 3.5, 0.5])
H = Matrix(H_data)

# Minimize expectation using VQE with hardware-efficient ansatz
ground_energy = vqe(H, learning_rate=0.05, tol=1e-5, max_iter=50)

print(f"Calculated Ground State Energy: {ground_energy}")
print(f"Exact Ground State Energy: {min(np.diagonal(H_data))}")

License

This project is licensed under the MIT License.

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

qmath_a7s-0.1.2.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

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

qmath_a7s-0.1.2-cp312-cp312-win_amd64.whl (414.7 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file qmath_a7s-0.1.2.tar.gz.

File metadata

  • Download URL: qmath_a7s-0.1.2.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for qmath_a7s-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e2d1ab9c6270df80d39d68dad6b4b3edb60c655908e9806d2a71d094ff27b608
MD5 28e194148795a4d3ea73c3913f0e7f11
BLAKE2b-256 42c740beb8a33d0bc08f5fd92dcff1c38f665fd8e904a421c4ad25f3ad3259d9

See more details on using hashes here.

File details

Details for the file qmath_a7s-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: qmath_a7s-0.1.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 414.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for qmath_a7s-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ea61ea88c7872ed7d567fd66153029b32e58a3b8099b9eb71747c1685dc9b8f2
MD5 1d27fcb6f539a9c78b1420c008a03b98
BLAKE2b-256 5bf43907dbdcf39a226205bd6bfe863af8f475bf737148679eb4ae3344054200

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