bqth29 / simulated-bifurcation-algorithm

Python CPU/GPU implementation of the Simulated Bifurcation (SB) algorithm to solve quadratic optimization problems (QUBO, Ising, TSP, optimal asset allocations for a portfolio, etc.).
MIT License
108 stars 27 forks source link

Allow optimization variables to be on different domains #70

Open bqth29 opened 4 months ago

bqth29 commented 4 months ago

💬 Pull Request Description

This PR allows the optimization of quadratic polynomials to occur on different domains at the same time. For instance, let us consider a model with 4 variables:

Previously, all variables had to be defined on the same domain but it is now possible to specify one domain per variable. To do so, instead of a string, the domain argument of the optimization functions must be passed as a list of string with the same length as the number of variables. For the previous example, the input would be:

sb.minimize(model, domain=["spin", "binary", "int2", "int5"])

Note: if the domain is passed as a string, for example "spin", then all variables will be considered of this very type, i.e. spin.

Example

sb.minimize(model, domain="spin")  # All variables are optimized as spins, i.e. on {-1, 1}
sb.minimize(model, domain=["spin", "binary", "int2", "int5"])  # Variables will respectively be optimized on {-1, 1}, {0, 1}, [0, 3] and [0, 31]

⚠️ If the length of domain does not match the dimension of the optimization model, a ValueError will be raised.

✔️ Check list

🚀 New features

Possibility to define on optimization domain per variable.

🐞 Bug fixes

None.

📣 Supplementary information

The quadratic-polynomial-to-Ising conversions have been unified in a single formula. The math behind this new formula is explained below:

TODO: Add math

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 99.24242% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.94%. Comparing base (7fb0fec) to head (8af1338). Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/simulated_bifurcation/core/variable.py 96.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #70 +/- ## =========================================== - Coverage 100.00% 99.94% -0.06% =========================================== Files 36 39 +3 Lines 1600 1696 +96 =========================================== + Hits 1600 1695 +95 - Misses 0 1 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.