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

Migrate to PyOptInterface #79

Merged
merged 55 commits into from
Dec 15, 2024
Merged

Migrate to PyOptInterface #79

merged 55 commits into from
Dec 15, 2024

Conversation

staadecker
Copy link
Member

@staadecker staadecker commented Nov 29, 2024

Motivation 🎉

As discussed internally, this changes brings some important improvements:

  • Out-of-the-box support for HiGHS open-source solver! Just use Model(solver="highs") and pip install highsbox
  • ~2x faster since we avoid the slow .lp writing/parsing (based on the facility benchmarks)
  • ~15% less lines of code while maintaining the functionality (deleted io.py, io_mappers.py, solvers.py, and user_defined.py !)
  • Improved documentation!

Closes #57. Closes #75. Closes #60. Closes #19.

Thanks to @metab0t for the powerful PyOptInterface library, and the helpful responses!

Breaking changes ⚠️ ⚠️

Function Change Use instead
Model.to_file(file_path, use_var_names) Renamed with changes Model.write(file_path). Note: use_var_names should now be set when initializing the model.
Model.solve(solver, directory, use_var_names, log_fn, warmstart_fn, basis_fn, solution_file, log_to_console) Renamed with changes Model.optimize(). Note: parameters should be set through other means (e.g. model.attr.Silent = True instead of log_to_console=False)
Expression.value Renamed Expression.evaluate()
Config.print_float_precision Renamed Config.float_to_str_precision
Constraint.slack Renamed Constraint.attr.slack (Gurobi only)
Variable.RC Renamed Variable.attr.RC (Gurobi only)
Constraint.relax(...) Changed behavior Same as before except that it must be called before adding a constraint to the model.
Model.params (Gurobi only) Changed behavior Same as before except that if the parameter needs to be set during environment creation, instead use: Model(solver_env={"server_name":"bla"})
.to_str(...) and .to_str_table(...) Changed signature Parameters moved to pf.Config

Also:

  • ⚠️ Gurobi must be installed through their website (not via pip) as we now use the Gurobi C API (not the Python API). Here is a way to automate this in a build environment. ⚠️
  • Support for Python 3.8 is dropped.

Todo

  • Remove old to_str code
  • Fix failing tests
  • Fix duals!
  • Add documentation
  • List breaking changes
  • Testing of other solvers
  • Fix map_elements warnings
  • Test and support adding objective

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 95.92593% with 11 lines in your changes missing coverage. Please review.

Project coverage is 95.71%. Comparing base (53c14ff) to head (d51e9b3).

Files with missing lines Patch % Lines
src/pyoframe/model.py 90.16% 6 Missing ⚠️
src/pyoframe/core.py 96.29% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #79      +/-   ##
==========================================
+ Coverage   94.61%   95.71%   +1.10%     
==========================================
  Files          13        9       -4     
  Lines        1448     1028     -420     
==========================================
- Hits         1370      984     -386     
+ Misses         78       44      -34     
Flag Coverage Δ
smart-tests 95.71% <95.92%> (+1.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

github-actions bot commented Dec 8, 2024

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
CSV 20 (+1) 292 (-977) 292 (-977) 0 0 0 3.2K (-9.5K)
Jupyter 2 2033 2033 0 0 0 62.4K (+3B)
License 1 21 (-2) 17 (-2) 0 4 0 1K (-72B)
Markdown 25 500 (+87) 327 (+68) 0 173 (+19) 0 18.2K (+2.8K)
Python 28 (-3) 4197 (-686) 3640 (-490) 212 (-81) 345 (-115) 184 (-19) 138.9K (-17.3K)
Solidity 5 217 (-980) 217 (-980) 0 0 2 (-2) 4.4K (-22.5K)
TOML 1 66 (+10) 60 (+10) 0 6 0 1.5K (+104B)
YAML 10 (+4) 720 (+495) 513 (+299) 153 (+150) 54 (+46) 0 21.9K (+16.2K)

@staadecker staadecker marked this pull request as ready for review December 9, 2024 19:11
Copy link
Collaborator

@kjartan-at-bravos kjartan-at-bravos left a comment

Choose a reason for hiding this comment

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

Just a minor comment on choice of method name. The code looks great and I am looking forward to testing it out!

@staadecker staadecker merged commit ebf57b2 into main Dec 15, 2024
6 checks passed
@staadecker staadecker deleted the migrate-poi branch December 15, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants