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
112 stars 26 forks source link

Create polynomials from Sympy expressions #37

Closed bqth29 closed 11 months ago

bqth29 commented 1 year ago

💬 Pull Request Description

⚠️ This PR contains breaking changes. See at the bottom of this description for more information.

This PR allows polynomials to be created from mathematical expressions that can be more natural than matrices for small dimension problems.

The logic behind the creation of polynomial instances was completely redesigned and now relies on a new tool called PolynomialMap which is an object that maps a degree of an homogeneous polynomial to the associated coefficients tensor, given that the number of dimensions of the tensor is the same as degree and that all these dimensions are equal.

Finally, the domain of optimization is no longer beared by the polynomial instance but only provided when casting the polynomial to an Ising model.

✔️ Check list

Before you open the pull request, make sure the following requirements are met.

🚀 New features

Define a polynomial instance and/or a SB model from a SymPy expression.

🐞 Bug fixes

None

📣 Supplementary information

The IsingCore class has been moved to the newly created core module and renamed in the core.Ising class.

⚠️ Breaking change

This PR introduces a breaking change (first PR for version1.3.0). When this is merged, some old features will no longer be available or calling some functions/method will be different. Please be careful if you update your version of simulated_bifurcation and try to run an old code that was written for versions 1.2.0 or 1.2.1.

Deleted classes

The following classes were deleted and replaced by QuadraticPolynomial:

The enum OptimizerMode has been replaced by SimulatedBifurcationEngine which now bears the activation function and the heated property.

New methods signatures

The optimize, maximize or minimize methods/functions' parameter input_type has been renamed in domain for this name make it clearer what its purpose is.

Because the polynomial instances no longer carry their input type, calling the methods optimize, maximize or minimize on a polynomial instance now requires a domain parameter.

Similarly, building a polynomial instance no longer requires an input_type, and the parameters dtype and device are now keyword-only (because an arbitrary number of tensors can be passed).

Finally, all parameters of the sb.optimize, sb.maximize and sb.minimize functions (except the input polynomial that can be an arbitrary sequence of tensors/array or a sympy expression) are also keyword-only from now on.

On the backend side, the SimulatedBifurcationOptimizer class constructor now only takes a SimulatedBifurcationEngine enum object (enum parameter) instead of the mode and heated parameters.

Moved classes

The IsingCore class has been moved to the newly created core module and renamed in the core.Ising class. It must be imported using from simulated_bifurcation.core.ising import Ising instead of from simulated_bifurcation.ising_core import IsingCore

codecov[bot] commented 1 year ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (f0f5653) 100.00% compared to head (5854566) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #37 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 40 36 -4 Lines 1525 1595 +70 ========================================= + Hits 1525 1595 +70 ```

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

bqth29 commented 12 months ago

Shall we keep Binary, Integer and Spin polynomials but in the models module?