pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

Added MAiNGO appsi-interface

Open MAiNGO-github opened this issue 1 year ago • 6 comments

Fixes:

None

Summary/Motivation:

Added an interface to our global optimization solver MAiNGO

Changes proposed in this PR:

Add appsi-interface for MAiNGO

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

MAiNGO-github avatar Feb 26 '24 16:02 MAiNGO-github

We took a quick look at this during the Dev Call this week. Most of the test failures are do to a test that tracks the modules that are automatically imported by pyomo.environ, and the failure is because the maingopy import is getting triggered by

class SolverModel(maingopy.MAiNGOmodel):

The easiest workaround is probably to move the SolverModel class definition to its own module, and then conditionally import that module into solvers/maingo.py (using attempt_import).

jsiirola avatar Mar 14 '24 13:03 jsiirola

We took a quick look at this during the Dev Call this week. Most of the test failures are do to a test that tracks the modules that are automatically imported by pyomo.environ, and the failure is because the maingopy import is getting triggered by

class SolverModel(maingopy.MAiNGOmodel):

The easiest workaround is probably to move the SolverModel class definition to its own module, and then conditionally import that module into solvers/maingo.py (using attempt_import).

Thank you for the advice, now the import works just fine.

MAiNGO-github avatar Mar 22 '24 15:03 MAiNGO-github

Codecov Report

Attention: Patch coverage is 91.38277% with 43 lines in your changes are missing coverage. Please review.

Project coverage is 88.46%. Comparing base (6393961) to head (0c14380).

Files Patch % Lines
pyomo/contrib/appsi/solvers/maingo.py 91.61% 27 Missing :warning:
pyomo/contrib/appsi/solvers/maingo_solvermodel.py 90.69% 16 Missing :warning:
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3165    +/-   ##
========================================
  Coverage   88.45%   88.46%            
========================================
  Files         849      851     +2     
  Lines       95329    95825   +496     
========================================
+ Hits        84327    84773   +446     
- Misses      11002    11052    +50     
Flag Coverage Δ
linux 86.43% <91.38%> (+0.02%) :arrow_up:
osx 76.33% <90.58%> (+0.07%) :arrow_up:
other 86.62% <91.38%> (+0.01%) :arrow_up:
win 83.94% <91.38%> (+0.03%) :arrow_up:

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

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

codecov[bot] avatar Apr 01 '24 18:04 codecov[bot]

Dear @mrmundt We have adressed all your comments and fixed some bugs. The interface does no pass all tests (locally on our machine).

There are a few points we need your input on:

  • MAiNGO does not compute duals or reduced costs. We have extended the tests, so that duals or RCs are not computed for MAiNGO. Maybe there is a nicer way to do this?
  • MAiNGO has rather loose tolerances by default. To pass the tests we needed to raise them to a level which we do not want to set as default. For now, we create a new solverclass that inherits from our base solver class that uses tighter tolerances (MAiNGOTest). Again, is there a nicer way to do this?
  • MAiNGO does not support unbounded variables. To deal with unbounded variables we bound them to [-1e8,1e8]. As a consequence, we cannot recognice a problem to be unbounded.
  • We had to modify two tests (make variables > 0) as MAiNGO cannot handle log of negative values or division by 0.

Thank you!

MAiNGO-github avatar Apr 17 '24 14:04 MAiNGO-github

@MAiNGO-github - I will reply to your other comments soon, but FYI on the two failures:

  1. conda is not your fault; something just didn't download correctly
  2. singletest is looking to make sure that you have registered the SolverFactory in the plugins system. See here: https://github.com/Pyomo/pyomo/blob/main/pyomo/contrib/appsi/plugins.py <- you'll need to add your new solver to the list.

mrmundt avatar Apr 17 '24 18:04 mrmundt

@MAiNGO-github - This is insidious, and you would never have known it happened. maingopy isn't installing correctly:

Collecting maingopy
  Downloading maingopy-0.7.3.tar.gz (17.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.9/17.9 MB 75.6 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [13 lines of output]
      Traceback (most recent call last):
        File "/tmp/pip-install-du9lfhn7/maingopy_85dd9705743e442785b6d05edb86f03d/setup.py", line 7, in <module>
          from skbuild import setup
      ModuleNotFoundError: No module named 'skbuild'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-du9lfhn7/maingopy_85dd9705743e442785b6d05edb86f03d/setup.py", line 9, in <module>
Error:           raise ImportError('Error during setup of maingopy: maingopy requires scikit-build, which is not available.')
      ImportError: Error during setup of maingopy: maingopy requires scikit-build, which is not available.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
WARNING: MAiNGO is not available

mrmundt avatar Apr 18 '24 19:04 mrmundt

I think this looks great. I have one minor change request, could you add maingo to the list of appsi solvers in this documentation page: https://github.com/Pyomo/pyomo/blob/main/doc/OnlineDocs/library_reference/appsi/appsi.solvers.rst

Added in last two commits.

mrmundt avatar May 08 '24 14:05 mrmundt