Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optimization variables to be on different domains #70

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bqth29
Copy link
Owner

@bqth29 bqth29 commented Jun 16, 2024

💬 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

  • The code matches the styling rules
  • The new code is covered by relevant tests
  • 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

Copy link

codecov bot commented Jun 16, 2024

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 ⚠️
Additional details and impacted files
@@             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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bqth29 bqth29 added feature New feature refactoring Existing code is refactored (no new feature, no breaking change) labels Jun 16, 2024
@bqth29 bqth29 changed the title Allow optimization varaiables to be on different domains Allow optimization variables to be on different domains Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature refactoring Existing code is refactored (no new feature, no breaking change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant