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

[fix] Make the hybrid interface work for numpy>=2.0 #266

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Next Release
1.8.2
-----
* fix the feasibility check in the hybrid solver
* make optlang compatible with numpy>=2.0

1.8.1
-----
Expand Down
18 changes: 9 additions & 9 deletions src/optlang/matrix_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from collections import defaultdict
from typing import NamedTuple

from numpy import Infinity, array, concatenate, zeros
from numpy import inf, array, concatenate, zeros
from scipy.sparse import csc_matrix

from optlang import available_solvers, interface, symbolics
Expand Down Expand Up @@ -495,15 +495,15 @@ def name(self, value):
def lb(self, value):
self._check_valid_lower_bound(value)
if getattr(self, "problem", None) is not None:
lb = -Infinity if value is None else float(value)
lb = -inf if value is None else float(value)
self.problem.problem.constraint_lbs[self.name] = lb
self._lb = value

@interface.Constraint.ub.setter
def ub(self, value):
self._check_valid_upper_bound(value)
if getattr(self, "problem", None) is not None:
ub = Infinity if value is None else float(value)
ub = inf if value is None else float(value)
self.problem.problem.constraint_ubs[self.name] = ub
self._ub = value

Expand Down Expand Up @@ -899,18 +899,18 @@ def optimize(self):
def _set_variable_bounds_on_problem(self, var_lb, var_ub):
self.problem.reset()
for var, val in var_lb:
lb = -Infinity if val is None else float(val)
lb = -inf if val is None else float(val)
self.problem.variable_lbs[var.name] = lb
for var, val in var_ub:
ub = Infinity if val is None else val
ub = inf if val is None else val
self.problem.variable_ubs[var.name] = float(ub)

def _add_variables(self, variables):
super()._add_variables(variables)
self.problem.reset()
for variable in variables:
lb = -Infinity if variable.lb is None else float(variable.lb)
ub = Infinity if variable.ub is None else float(variable.ub)
lb = -inf if variable.lb is None else float(variable.lb)
ub = inf if variable.ub is None else float(variable.ub)
self.problem.variables.add(variable.name)
self.problem.variable_lbs[variable.name] = lb
self.problem.variable_ubs[variable.name] = ub
Expand Down Expand Up @@ -940,8 +940,8 @@ def _add_constraints(self, constraints, sloppy=False):
constraint._problem = None
if constraint.is_Linear:
_, coeff_dict, _ = parse_optimization_expression(constraint)
lb = -Infinity if constraint.lb is None else float(constraint.lb)
ub = Infinity if constraint.ub is None else float(constraint.ub)
lb = -inf if constraint.lb is None else float(constraint.lb)
ub = inf if constraint.ub is None else float(constraint.ub)
self.problem.constraints.add(constraint.name)
self.problem.constraint_coefs.update(
{
Expand Down
Loading