This repository explores Variational Quantum Algorithms (VQAs) for the Traveling Salesman Problem (TSP) using compact permutation (Lehmer) encoding and an adaptive Ansatz that evolves via Simulated Annealing (SA). It aims to keep qubit counts at O(
- What it does. Searches the space of Ansatz circuits via SA, evaluates each candidate with a VQE over TSP instances, and keeps the best topology.
- Why it matters. A compact permutation encoding shrinks the qubit register and avoids penalty terms by never casting the objective into a QUBO.
-
How it works. A 5-gene "genome" specifies alternating rotation and entanglement blocks. Simulated annealing proposes single-gene mutations; a VQE then estimates the expected tour cost and the empirical
$P_{(opt)}$ (probability of sampling the optimal permutation) directly from circuit samples no QUBO required. Candidate updates are accepted via the Metropolis criterion.
Instances/ # Folder of dataset
src/
args.py # CLI flags
Individual.py # Ansatz genome & circuit builder
simulated_annealing.py # SA loop, logging, artifact saving
myflow.py # Thin MLflow helpers
logger.py # Logging config with per-run UUID and files
uuid.py # RUN_UUID generator
__init__.py # Convenience exports
VQA/
__init__.py # Convenience exports
tsp_problem.py # TSP helpers
vqa_tsp.py # VQA runner TSP
utils/
generator_tsp_data.py # File for create instances
Python 3.9+ recommended.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtCreate run_sa.py:
from src import simulated_annealing, args
from src.logger import setup_logger
if __name__ == "__main__":
logger = setup_logger()
best = simulated_annealing(
eval_file=args.eval_file, # Instances/5_cities tsp_instance_0.json
initial_temp=args.initial_temp, # 1.0
cooling_rate=args.cooling_rate, # 0.9
max_iterations=args.max_iterations # 100
)
logger.info("Done. Best ansatz:\n%s", best)Or Run with flags (examples):
python run_sa.py \
--eval_file Instances/6_cities/tsp_instance_0.json \
--max_iterations 250 \
--initial_temp 1.0 \
--cooling_rate 0.95 \
--optimizers spsa cobyla \
--vqa_runs_per_instance 3 \
--vqa_num_tries 10 \Gate-based variational methods (VQA) prepare a parameterized state and optimize classical parameters.
VQE minimizes the expectation
Instead of QUBO style encodings that inflate qubits and require penalty terms, compact permutation/Lehmer coding maps tours to integers
The 5-gene vector
If you use this repository, please cite the accompanying paper:
Paper
F. Fagiolo, N. Vescera, Ansatz Optimization using Simulated Annealing in Variational Quantum Algorithms for the TSP, 2025. (QAI2025)
BibTeX
@article{Fagiolo-Vescera2025VQA-TSP-SA,
title = {Ansatz Optimization using Simulated Annealing in Variational Quantum Algorithms for the TSP},
author = {Fabrizio Fagiolo, Nicolò Vescera},
year = {2025},
note = {},
url = {}
}