Skip to main content

Quantum-inspired genetic and evolutionary algorithms for combinatorial optimization.

Project description

qga-py

Quantum-inspired genetic and evolutionary algorithms for combinatorial optimization on classical computers.

This project does not require quantum hardware. It implements practical quantum-inspired optimizers that maintain probability amplitudes or probability-like distributions, sample candidate solutions, evaluate them, and update the distributions toward better solutions.

Installation

For local development:

pip install -e ".[dev]"

After publishing:

pip install qga-py

Usage

Binary optimization:

from qga import BinaryQGA

def fitness(bits, _):
    return bits.sum()

optimizer = BinaryQGA(
    genome_length=100,
    population_size=20,
    generations=200,
    fitness_func=fitness,
)

result = optimizer.run()
print(result.best_solution, result.best_fitness)

Permutation optimization:

from qga import PermutationQGA

def fitness(route, distance):
    length = sum(distance[route[i - 1], route[i]] for i in range(len(route)))
    return -length

optimizer = PermutationQGA(
    n_items=20,
    population_size=40,
    generations=300,
    fitness_func=fitness,
    fitness_inputs=distance,
)

result = optimizer.run()
print(result.best_solution, result.best_fitness)

Included Examples

  • examples/knapsack_demo.py
  • examples/tsp_demo.py

Publishing Checklist

  1. Update the project URLs in pyproject.toml.
  2. Run tests with pytest.
  3. Build with python -m build.
  4. Upload to TestPyPI first with python -m twine upload --repository testpypi dist/*.
  5. Install from TestPyPI and verify imports.
  6. Upload to PyPI with python -m twine upload dist/*.

License

MIT

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

qga_py-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

qga_py-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file qga_py-0.1.0.tar.gz.

File metadata

  • Download URL: qga_py-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qga_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6317e67766b1893c119519a18343b7fc0a28753a2d18b4d497e7eb705f4936e
MD5 59231a9a4bcf72ca20b7c43f1cef6917
BLAKE2b-256 f9a96056d3ad914817756307fa3cac5f655cf09d1662aebbe606b04b7b6e7d71

See more details on using hashes here.

Provenance

The following attestation bundles were made for qga_py-0.1.0.tar.gz:

Publisher: publish.yml on williamzpn/qga-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qga_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qga_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qga_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39dec1520765c82ee0907d3c3185cbd771f54e5f5263437a02145296260c5cdd
MD5 658c78f5263b37eb2b9308991d8ae4a6
BLAKE2b-256 75578dcaa92a7e716105d0ecd3e13fb40ad952114f37755a511c6ef81dc19851

See more details on using hashes here.

Provenance

The following attestation bundles were made for qga_py-0.1.0-py3-none-any.whl:

Publisher: publish.yml on williamzpn/qga-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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