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

Create polynomials from Sympy expressions #37

Merged
merged 38 commits into from
Dec 21, 2023

Conversation

bqth29
Copy link
Owner

@bqth29 bqth29 commented Oct 20, 2023

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

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

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

  • BaseMultivariateQuadraticPolynomial
  • SpinPolynomial
  • SpinQuadraticPolynomial
  • BinaryPolynomial
  • BinaryQuadraticPolynomial
  • IntegerPolynomial
  • IntegerQuadraticPolynomial

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

@bqth29 bqth29 marked this pull request as draft October 20, 2023 14:22
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

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

@bqth29 bqth29 marked this pull request as ready for review October 20, 2023 15:26
@bqth29 bqth29 requested a review from BusyBeaver-42 October 20, 2023 15:27
Copy link
Collaborator

@BusyBeaver-42 BusyBeaver-42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be usefull to have a method to retrieve the assignment of the variables from the sb_result?

PS: We should update the readme, the package docstring, and some See Also sections.

@bqth29 bqth29 marked this pull request as draft October 27, 2023 16:25
@bqth29 bqth29 added the enhancement New feature or request label Nov 17, 2023
@bqth29 bqth29 marked this pull request as ready for review November 25, 2023 11:33
@bqth29 bqth29 requested a review from BusyBeaver-42 November 25, 2023 11:34
@bqth29
Copy link
Owner Author

bqth29 commented Dec 5, 2023

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

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@bqth29 bqth29 merged commit adaf9ff into main Dec 21, 2023
12 checks passed
@bqth29 bqth29 deleted the experiment/polynomial_compiler branch December 21, 2023 14:26
@bqth29 bqth29 added this to the Simulated Bifurcation 2.0 milestone Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] MemoryError when creating an instance of IntegerPolynomial for integers with a large number of bits
2 participants