simulated-bifurcation-algorithm icon indicating copy to clipboard operation
simulated-bifurcation-algorithm copied to clipboard

Allow optimization variables to be on different domains

Open bqth29 opened this issue 1 year ago • 1 comments

💬 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:

  • $x_1$ which is a spin
  • $x_2$ which is binary
  • $x_3$ which is a 2-bits encoded integer variable
  • $x_4$ which is a 5-bits encoded integer variable

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

  • [x] The code matches the styling rules
  • [x] The new code is covered by relevant tests
  • [x] Documentation was added

🚀 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

bqth29 avatar Jun 16 '24 15:06 bqth29

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 (350d972) to head (bfe36fd). Report is 13 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
@@             Coverage Diff             @@
##              main      #70      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           36       39       +3     
  Lines         1620     1716      +96     
===========================================
+ Hits          1620     1715      +95     
- Misses           0        1       +1     

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

codecov[bot] avatar Jun 16 '24 15:06 codecov[bot]