Skip to content

Commit b90217c

Browse files
committed
Clean: silence ruff RUF100 and Pyright false positives from solver stubs
1 parent 3366d86 commit b90217c

8 files changed

Lines changed: 11 additions & 11 deletions

File tree

pkg/pyepo/metric/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def SPOError(
5959
optmodel._setFullObj(optmodel._fullCost(c))
6060
_, optobj = optmodel.solve()
6161
# per-instance regret
62-
regret_sum += calRegret(optmodel, cp, c, optobj)
62+
regret_sum += calRegret(optmodel, cp, c, optobj) # type: ignore[arg-type]
6363
optobj_sum += np.abs(optobj)
6464
# normalized regret
6565
return regret_sum / (optobj_sum + _EPS)

pkg/pyepo/model/copt/compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _read_sol(self):
6262
try:
6363
# MVar.x is a coptpy NdArray; tolist() flattens it to plain floats
6464
return np.asarray(self.x.x.tolist(), dtype=float), self._model.objVal
65-
except Exception as e: # noqa: BLE001 coptpy raises generic errors on no-solution
65+
except Exception as e: # coptpy raises generic errors on no-solution
6666
raise RuntimeError(f"COPT found no solution (status {self._model.status}).") from e
6767

6868
def _add_cut(self, coef, rhs):

pkg/pyepo/model/copt/coptmodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def solve(self) -> tuple[np.ndarray, float]:
112112
else:
113113
sol = np.asarray(self._model.getInfo("Value", self._vars_list))
114114
obj = self._model.objVal
115-
except Exception as e: # noqa: BLE001 coptpy raises generic errors on no-solution
115+
except Exception as e: # coptpy raises generic errors on no-solution
116116
raise RuntimeError(f"COPT found no solution (status {self._model.status}).") from e
117117
return sol, obj
118118

@@ -127,7 +127,7 @@ def copy(self) -> Self:
127127
new_model._model = self._model.clone()
128128
new_vars = new_model._model.getVars()
129129
if _is_mvar(self.x):
130-
new_model.x = _CoptMVar.fromlist(new_vars)
130+
new_model.x = _CoptMVar.fromlist(new_vars) # type: ignore[union-attr]
131131
new_model._vars_list = None
132132
else:
133133
new_model.x = {key: new_vars[i] for i, key in enumerate(self.x)}

pkg/pyepo/model/copt/tsp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class tspDFJModel(tspABModel):
180180
overridden here.
181181
"""
182182

183-
class _SubtourCallback(CallbackBase):
183+
class _SubtourCallback(CallbackBase): # type: ignore[misc]
184184
"""
185185
A callback class for subtour elimination
186186
"""
@@ -255,7 +255,7 @@ def solve(self) -> tuple[np.ndarray, float]:
255255
def _addExtraConstr(self, coefs: np.ndarray | torch.Tensor | list, rhs: float) -> None:
256256
"""Add a single linear constraint to ``self._model`` using the DFJ variable scheme."""
257257
expr = LinExpr()
258-
expr.addTerms(self._cost_vars, coefs.tolist())
258+
expr.addTerms(self._cost_vars, coefs.tolist()) # type: ignore[attr-defined]
259259
self._model.addConstr(expr <= rhs)
260260

261261

pkg/pyepo/model/copt/vrp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class vrpRCIModel(vrpABModel):
4747
branch-and-cut via a COPT callback.
4848
"""
4949

50-
class _RCICallback(CallbackBase):
50+
class _RCICallback(CallbackBase): # type: ignore[misc]
5151
"""A callback for rounded-capacity / subtour elimination cuts."""
5252

5353
def __init__(self, x, n, edges, demands, capacity):

pkg/pyepo/model/grb/compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _getModel(self) -> tuple:
3737
# build the gurobi model from the finalized IR
3838
prob = self.problem
3939
m = gp.Model()
40-
m.Params.outputFlag = 0
40+
m.Params.outputFlag = 0 # type: ignore[attr-defined]
4141
# objective sense (EPO -> Gurobi)
4242
m.modelSense = GRB.MAXIMIZE if prob.objective.modelSense == EPO.MAXIMIZE else GRB.MINIMIZE
4343
x = self._build_flat_vars(m)

pkg/pyepo/model/grb/grbmodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def setObj(self, c: np.ndarray | torch.Tensor | list) -> None:
8383
c = costToNumpy(c)
8484
if isinstance(self.x, gp.MVar):
8585
# direct Obj attr write skips MLinExpr allocation
86-
self.x.Obj = c
86+
self.x.Obj = c # type: ignore[attr-defined]
8787
else:
8888
# batch C-level coefficient update
8989
self._model.setAttr("Obj", self._vars_list, c.tolist())
@@ -101,7 +101,7 @@ def solve(self) -> tuple[np.ndarray, float]:
101101
if self._model.SolCount == 0:
102102
raise RuntimeError(f"Gurobi found no solution (status {self._model.Status}).")
103103
if isinstance(self.x, gp.MVar):
104-
sol = self.x.x
104+
sol = self.x.x # type: ignore[attr-defined]
105105
else:
106106
sol = np.asarray(self._model.getAttr("X", self._vars_list))
107107
obj = self._model.objVal

pkg/pyepo/model/grb/shortestpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _getModel(self) -> tuple:
4545
b = np.zeros(num_nodes, dtype=np.float64)
4646
b[0] = -1.0
4747
b[num_nodes - 1] = 1.0
48-
m.addConstr(A @ x == b)
48+
m.addConstr(A @ x == b) # type: ignore[call-overload, arg-type]
4949
return m, x
5050

5151

0 commit comments

Comments
 (0)