Quasar Solver is a pure Python, quantum-inspired optimizer for quadratic unconstrained binary optimization (QUBO) problems. It provides a compact QUBO model, a NumPy-based simulated annealing solver, and converters for practical optimization examples.
pip install -e .For development:
pip install -e ".[dev]"🚀 Live Demo — open in browser, no install needed.
Click to place cities, hit Solve, watch the optimizer find the shortest route.
from quasar_solver import QUBO, SimulatedAnnealingSolver
q = QUBO(); q.add(0, 0, -1.0); q.add(1, 1, 2.0)
result = SimulatedAnnealingSolver(seed=42).solve(q)The routing demo builds a seeded six-city symmetric distance matrix, converts it to a QUBO with one-hot Travelling Salesman Problem constraints, and solves it with simulated annealing. It prints the best energy, decoded tour, and total route distance when the best sample is valid.
Run it with:
python demos/routing_demo.pyThe demo saves a plot of the city coordinates and decoded route to demos/tour.png. If the annealer returns an invalid one-hot assignment, the demo prints a warning and still saves the city plot.
- VRP support
- Schedule optimization
- Financial portfolio demo
- Web UI
QUBO formulation turns an optimization problem into a polynomial over binary variables. Each variable can be either 0 or 1, and the model assigns costs to individual variables and pairs of variables. Hard constraints are usually represented as large penalty terms, so invalid assignments become expensive. Once a problem is in QUBO form, many different search methods can try to minimize its energy.
Simulated annealing is a randomized search method inspired by cooling physical systems. It starts from a random binary sample, flips bits one at a time, and keeps changes that improve the energy. It can also accept worse moves early in the run, which helps it escape shallow local minima. As the temperature cools, the solver becomes more selective and settles into its best-found solution.
| Problem size (cities) | Variables (n²) | Avg solve time (ms) | Typical tour quality |
|---|---|---|---|
| 6 | 36 | 450 | Usually valid, near-optimal |
| 10 | 100 | 1,800 | Often valid, good heuristic tours |
| 20 | 400 | 9,500 | Mixed validity, useful exploratory tours |