Skip to main content

Quantum Mathematics Framework

Project description

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, 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))}")

Developer: Patnam Kannabhiram From A7's Garage

QMath serves as the foundation for QEssential.


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.3.tar.gz (31.5 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.3-cp312-cp312-win_amd64.whl (446.9 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

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

File metadata

  • Download URL: qmath_a7s-0.1.3.tar.gz
  • Upload date:
  • Size: 31.5 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.3.tar.gz
Algorithm Hash digest
SHA256 f3cb17569b2db6e8df067b835c76132e57ea3a911847c3126105ceb6b318b03a
MD5 ab21ec6cb9c11e1ef953888e3064b84b
BLAKE2b-256 45a0463a1666f9ebd3578f519aa6209745978ddd60943168ab7282476fbe2f59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qmath_a7s-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 446.9 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 57758715c576e4b0558f0e2d16f35ffbe5e062383d395cbe79e1bff32a910345
MD5 2651af664d26111ed20fcdab8c67812f
BLAKE2b-256 c494a6b390dbff5f6500383f612bbd0efed7d57aa48344b7abbbd8809da7eb76

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