QMath: Quantum Mathematics Framework
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, andcomplex128. - 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))}")
Developer: Patnam Kannabhiram From A7's Garage
QMath serves as the foundation for QEssential.
License
This project is licensed under the MIT License.
Metadata
Release files for qmath-a7s 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qmath_a7s-0.1.3.tar.gz | 31.5 kB | Without provenance | Details for qmath_a7s-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qmath_a7s-0.1.3-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for qmath_a7s-0.1.3-cp312-cp312-win_amd64.whl |
Total release size: 478.4 kB
Release files / qmath_a7s-0.1.3.tar.gz
| Download URL | qmath_a7s-0.1.3.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3cb17569b2db6e8df067b835c76132e57ea3a911847c3126105ceb6b318b03a
|
|
BLAKE2b-256 checksum How to use checksums |
45a0463a1666f9ebd3578f519aa6209745978ddd60943168ab7282476fbe2f59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / qmath_a7s-0.1.3-cp312-cp312-win_amd64.whl
| Download URL | qmath_a7s-0.1.3-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 446.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
57758715c576e4b0558f0e2d16f35ffbe5e062383d395cbe79e1bff32a910345
|
|
BLAKE2b-256 checksum How to use checksums |
c494a6b390dbff5f6500383f612bbd0efed7d57aa48344b7abbbd8809da7eb76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for qmath-a7s 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.