(Quasi) Rejection-Free Simulated Annealing
Python implementations of quasi rejection-free and rejection-free simulated annealing to optimize QUBO problems. A CUDA implementation exists as well. Additionally, the default simulated annealing algorithm is implemented as a reference. This reference implementation makes use of an improved update scheme where only the differences to the last energy state is computed. By using this scheme, the complexity is reduced to O(n * t), where n is the number of bits in the problem and t is the number of time steps.
Usage
The package is available at pypi, so it can be installed with pip install simulated-annealing-variants.
The only requirement for the algorithms is numpy and they accept an upper triangular matrix while the example uses qubovert for the QUBO formulation.
The algorithm is simply invoked by
from simulated_annealing_variants import simulated_annealing, simulated_annealing_qrf, simulated_annealing_rf
x, energy = simulated_annealing(Q=Q, num_t_values=10000)
x, energy = simulated_annealing_qrf(Q=Q, num_t_values=10000)
x, energy = simulated_annealing_rf(Q=Q, num_t_values=10000)
Algorithm
The implementation uses a parallel computation scheme and has therefore a quadratic speedup compared to standard simulated annealing implementations. The following pseudocode describes the idea and the difference to the standard implementation. For the exact implementation of the parallel computation have a look at the quasi rejection-free or the rejection-free python file.
Procedure RFSimulatedAnnealing
x = random initial state
xb = x
For i in 0:N
x = FindLocalNeighbour(f, x, T[i])
If f(x) < f(xb)
xb = x
EndIf
EndFor
return xb
EndProcedure
Procedure RFFindLocalNeighbour(f, x, t)
DeltaE = empty vector
u = empty vector
For i in 1:length(x)
DelatE[i] = f(x) - f(flipat(x, i)) # Energy difference for x flipped at bit i
u[i] = random(0, 1)
EndFor
accepted_idx = argmin_i {max(0, DeltaE[i]) + t log( -log(u[i])) }
return flipat(x, accepted_idx)
EndProcedure
MPI
The MPI version makes use of mpi4py.
So, after installing it with pip install mpi4py the parallel version can be run with mpiexec -n 4 python mpi_simulated_annealing.py.
Currently, each process computes an individual solution, prints the found energy and sends the corresponding x vector to the root process.
The file can be altered to make use of the best solution vector as well as changing the used QUBO problem.
Metadata
Release files for simulated-annealing-variants 1.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simulated_annealing_variants-1.1.8.tar.gz | 9.7 kB | Without provenance | Details for simulated_annealing_variants-1.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simulated_annealing_variants-1.1.8-py3-none-any.whl | Python 3 | none | any | Details for simulated_annealing_variants-1.1.8-py3-none-any.whl |
Total release size: 22.1 kB
Release files / simulated_annealing_variants-1.1.8.tar.gz
| Download URL | simulated_annealing_variants-1.1.8.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b64a4e017e951ac4182a4ccd93c63df6a62c89a51fa3205233cc7cede282d335
|
|
BLAKE2b-256 checksum How to use checksums |
c505014e0827d4ac3d9bd005967ddcdfd8bf3438e3ea986e617d2137786e0c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|
Release files / simulated_annealing_variants-1.1.8-py3-none-any.whl
| Download URL | simulated_annealing_variants-1.1.8-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2111858ec3e768acdbbe189ae84600698eba44357dc5af8fa77559a0eee4ac69
|
|
BLAKE2b-256 checksum How to use checksums |
4114050091b3116aa899c7fce52fc1cea75f50c6098abb3ffd365cdb57880941
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|
Security for simulated-annealing-variants 1.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.