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

Re-implement open source solvers #363

Merged
merged 17 commits into from Oct 11, 2023

Conversation

blake-riley
Copy link
Contributor

Pull Request Checklist

  • Will your PR merge into the dev branch?
    Exceptions will be made for urgent bugfixes.
  • Have you forked from dev?
    If not, please rebase your PR onto the most recent dev tip.
  • Does your PR title succinctly describe the changes?
    Explain to a new user by completing the sentence: 'This PR will: ...'
  • Fill out the template below.

Description of the Change

Fixes #361 .

Release Notes

  • Reimplemented open-source solvers (osqp, miosqp)
    • Only the installed solvers will be listed in qfit_protein --help
    • The user can override the default-selected solver (e.g --qp-solver=CVXOPTSolver --miqp-solver=MIOSQPSolver)
  • (dev) Refactored solvers.py

@blake-riley
Copy link
Contributor Author

Yeah, we're failing tests.

A few things to work on:

  1. updating numpy and python versions to work on M1 Macs #358 changed the default python to 3.9, and numpy to 1.22 in the README. This is not what we test against.
    I've bumped numpy to 1.22 here... it seems it's not compatible with py3.7?
  2. test_solvers.py definitely needs to be updated. The refactoring in this PR (to the best of my ability) makes solvers an implementations of an interface (ABC). Whatever logic I had around ImportError in the existing implementation, it's very different now.

The advantage of an initialize() method is to pre-cache an expensive operation.

For QPSolver:
  QPSolvers are always instantiated, then solved immediately.
  There's no caching going on here.

For MIQPSolver:
  In BIC threshold loops, MIQP solver.solve is run a few times.
  The initialize method can either
    a. be made private here, since it saves us N loop iterations * 2 inner products
    b. be thrown away, since these inner products are pretty cheap as
       there aren't many conformers for MIQP
  I've decided on (a), as I don't know the performance improvement of
  pre-caching here, and maybe later on MIQP will be done in situations
  with lots of conformers?
@blake-riley blake-riley force-pushed the feature/361-open-source-solvers branch 2 times, most recently from 9260310 to bd1666e Compare October 2, 2023 11:59
@blake-riley
Copy link
Contributor Author

Awesome. We're passing now.
Some better unit tests in here too.

…lable solvers to user.

**Single responsibility**
- The solvers.py module shouldn't be responsible / shouldn't contain the
  logic for deciding _which_ solver to use.
  This should be left up to the invocation script (e.g. qfit_protein.py).
- We should however, guarantee that all Solvers will conform to a particular
  interface. solvers.py is thus an _adapter_ module between a variety of
  solver packages and the common interface we define here.

**importlib hooks, lazy module loading** (utils/optional_lazy_import.py)
- We will provide some helper functions to allow the invocation scripts
  to know what solvers are available (and present them as options to the
  user).
- Each solver must try to import its own 'driver' module (e.g. cplex,
  cvxopt). This is _modular_.
- We also want to have a lazy import: modules are not executed when they
  are imported, only on first property call.
  Without a LazyLoader, since all solver 'driver' modules are imported
  during creating the argparse options, they would be eagerly executed,
  taking a lot of time for the user.
  With a LazyLoader, while the driver modules have been "imported", we
  delay their code execution until when they are first used.
This rolls back commit a2bba46, and updates
it for the current architecture.
If the user installs with `pip install qfit[cplex]`, they get the cvxopt and cplex solver modules.
`pip install qfit[osqp]` installs the osqp + miosqp solver modules.
This is required to get pytest to test these modules
This test actually runs a QFitLigand job, so needs to know which solver to use.
WARNING: test_qfit_protein.py does not actually run a QFitProtein job,
  so it doesn't need this same mod. It should be re-written.
@blake-riley blake-riley force-pushed the feature/361-open-source-solvers branch from bd1666e to 3adcc6f Compare October 2, 2023 14:26
@stephaniewankowicz stephaniewankowicz merged commit 76f7b98 into dev Oct 11, 2023
6 checks passed
@stephaniewankowicz stephaniewankowicz deleted the feature/361-open-source-solvers branch October 11, 2023 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants