Skip to content

HackYeahKabanosy/quantum_genetic_algorithm

Repository files navigation

Quantum Voyager Algorithm

Solving travelling salesman problem with Genetic Algorithms and Quantum Computing

Cybersecurity challange on HackYeah2024

QuantumVoyagePlatform

Travelling Salesman Problem

Find the best path covering all the cities/points without repeating any. This task aims to minimize the total distance or cost of travel, and is widely used in logistics, planning, and routing.

How to solve it with Genetic Algorithms?

  1. We have population of solutions

  1. Solutions change with each new generation, mixing and creating potentially better solutions

  2. But they can get stuck in a local minimum, and no longer improve in new generations

  1. In such case, we need some random unexpected change - a mutation, that will modify solutions.

  1. Applying mutations allows us to "unstuck" from local optimal solution.

How to apply Quantum Computing to enhance it?

Quantum Computers

  • uses quantum bits that represent probability between 0 and 1
  • operates on circuits consisting of quantum gates
  • generates noise, unexpected outcomes, as a side-effect

Noise

Noise is a side-effect, something unexpected, outcome that “shouldn’t be possible”. Even though we can make use of it! For example a gate below has only two possible outputs: [00, 11]. But on quantum computers it can generate some unexpected outputs.

# create a Quantum Circuit with 2 qubits and 2 classical bits 
qc = QuantumCircuit(2, 2) 
# apply a Hadamard gate on qubit 0 
qc.h(0) 
# apply a CNOT gate on qubit 0 and qubit 1 
qc.cx(0, 1) 
# measure the qubits 
qc.measure([0, 1], [0, 1])

Outcome

Outcome per 1024 shots on a real quantum computer (on non-quantum computer, 0010 or 0001 would never occur)

Similarly to mutation, it’s an unepxected change that happens randomly. It’s possible to be received with different frequency, depending on a quantum machine and conditions.

# if anomaly occurs, then apply mutation
def should_apply_mutation():
  res = self.qiskit_runtime.run(shots=1)
  return 
    res.get('01', 0) > 0 
    or 
    res.get('10', 0) > 0

How to play with Quantum Voyager?

We also created a platform where you can simulate how this algorithm would work on a quantum computer with a given noise level.

git clone git@github.com:HackYeahKabanosy/quantum_genetic_algorithm.git
pip install -r requirement.txt
python program.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages