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

Enable the hybrid solver interface #1366

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions release-notes/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

## New features

* Added a new "hybrid" solver that exposes an HIGHS/OSQP combinations for large scale
LPs, MILPs, and QPs.

## Fixes

## Other

## Deprecated features

* The OSQP solver is deprecated in favor of the hybrid solver which also uses OSQP but
will not attempt to solve LPs with OSQP anymore. Setting the `model.solver = "osqp"`
will now use the hybrid interface and will raise an error in a future release.

## Backwards incompatible changes
24 changes: 12 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parse = (?P<major>\d+)
\.(?P<minor>\d+)
\.(?P<patch>\d+)
(?P<release>[a]*)(?P<num>\d*)
serialize =
serialize =
{major}.{minor}.{patch}{release}{num}
{major}.{minor}.{patch}
tag_name = {new_version}
Expand All @@ -15,15 +15,15 @@ tag_name = {new_version}
name = cobra
url = https://opencobra.github.io/cobrapy
download_url = https://pypi.org/project/cobra
project_urls =
project_urls =
Source Code = https://github.com/opencobra/cobrapy
Documentation = https://cobrapy.readthedocs.io
Bug Tracker = https://github.com/opencobra/cobrapy/issues
author = The cobrapy core development team.
author_email = [email protected]
maintainer = Moritz E. Beber
maintainer_email = [email protected]
classifiers =
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Expand All @@ -40,7 +40,7 @@ license = LGPL-2.0-or-later OR GPL-2.0-or-later
description = COBRApy is a package for constraint-based modeling of metabolic networks.
long_description = file: README.rst, INSTALL.rst
long_description_content_type = text/x-rst
keywords =
keywords =
metabolism
biology
constraint-based
Expand All @@ -52,39 +52,39 @@ keywords =

[options]
zip_safe = True
install_requires =
install_requires =
appdirs ~=1.4
depinfo ~=2.2
diskcache ~=5.0
future
httpx ~=0.24
importlib_resources
numpy >=1.13
optlang ~=1.5
optlang ~=1.8
pandas >=1.0,<3.0
pydantic >=1.6
python-libsbml ~=5.19
rich >=8.0
ruamel.yaml ~=0.16
swiglpk
tests_require =
tests_require =
tox
packages = find:
package_dir =
package_dir =
= src

[options.packages.find]
where = src

[options.package_data]
cobra =
cobra =
data/*
io/*.json

[options.extras_require]
array =
array =
scipy
development =
development =
black
bumpversion
isort
Expand All @@ -96,7 +96,7 @@ universal = 1
[bumpversion:part:release]
optional_value = placeholder
first_value = placeholder
values =
values =
placeholder
a

Expand Down
10 changes: 5 additions & 5 deletions src/cobra/util/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
solvers = {
match.split("_interface")[0]: getattr(optlang, match)
for match in dir(optlang)
if "_interface" in match
if "_interface" in match and match != "matrix_interface"
}

# Defines all the QP solvers implemented in optlang.
qp_solvers = ["cplex", "gurobi", "osqp"]
qp_solvers = ["cplex", "gurobi", "hybrid"]

# optlang solution statuses which still allow retrieving primal values
has_primals = [NUMERIC, FEASIBLE, INFEASIBLE, SUBOPTIMAL, ITERATION_LIMIT, TIME_LIMIT]
Expand Down Expand Up @@ -252,9 +252,9 @@ def get_solver_name(mip: bool = False, qp: bool = False) -> str:
if len(solvers) == 0:
raise SolverNotFound("No solvers found.")
# Those lists need to be updated as optlang implements more solvers
mip_order = ["gurobi", "cplex", "glpk"]
lp_order = ["glpk", "cplex", "gurobi"]
qp_order = ["gurobi", "cplex", "osqp"]
mip_order = ["gurobi", "cplex", "hybrid", "glpk"]
lp_order = ["glpk", "hybrid", "cplex", "gurobi"]
qp_order = ["cplex", "gurobi", "hybrid"]

if mip is False and qp is False:
for solver_name in lp_order:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_flux_analysis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# solutions.
@pytest.fixture(
scope="session",
params=[s for s in ["glpk", "cplex", "gurobi"] if s in sutil.solvers],
params=[s for s in ["glpk", "cplex", "gurobi", "hybrid"] if s in sutil.solvers],
)
def all_solvers(request) -> List[str]:
"""Return the avaialble solvers."""
Expand All @@ -24,7 +24,7 @@ def all_solvers(request) -> List[str]:

@pytest.fixture(
scope="session",
params=[s for s in ["cplex", "gurobi", "osqp"] if s in sutil.solvers],
params=[s for s in ["cplex", "gurobi", "hybrid"] if s in sutil.solvers],
)
def qp_solvers(request) -> List[str]:
"""Return the available QP solvers."""
Expand Down
8 changes: 5 additions & 3 deletions tests/test_flux_analysis/test_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_single_gene_deletion_fba_benchmark(
) -> None:
"""Benchmark single gene deletion using FBA."""
model.solver = all_solvers
benchmark(single_gene_deletion, model)
benchmark(single_gene_deletion, model, model.genes[1::10])
cdiener marked this conversation as resolved.
Show resolved Hide resolved


def test_single_gene_deletion_fba(model: Model, all_solvers: List[str]) -> None:
Expand Down Expand Up @@ -187,7 +187,9 @@ def test_single_reaction_deletion_benchmark(
) -> None:
"""Benchmark single reaction deletion."""
model.solver = all_solvers
benchmark(single_reaction_deletion, model=model, processes=1)
benchmark(
single_reaction_deletion, model=model, genes=model.genes[1::10], processes=1
)


def test_single_reaction_deletion(model: Model, all_solvers) -> None:
Expand Down Expand Up @@ -410,7 +412,7 @@ def test_double_reaction_deletion_benchmark(
large_model: Model, benchmark: Callable
) -> None:
"""Benchmark double reaction deletion."""
reactions = large_model.reactions[1::100]
reactions = large_model.reactions[100:105]
benchmark(double_reaction_deletion, large_model, reaction_list1=reactions)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_flux_analysis/test_variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_flux_variability_benchmark(
benchmark(
flux_variability_analysis,
large_model,
reaction_list=large_model.reactions[1::3],
reaction_list=large_model.reactions[1::100],
processes=1,
)

Expand Down Expand Up @@ -106,7 +106,7 @@ def test_flux_variability_loopless_benchmark(
flux_variability_analysis,
model,
loopless=True,
reaction_list=model.reactions[1::3],
reaction_list=model.reactions[1::50],
)


Expand Down
Loading