Skip to content

Commit 19125ac

Browse files
committed
fix: don't freeze if model is chunked
1 parent 1122b16 commit 19125ac

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

linopy/model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,12 +890,10 @@ def add_constraints(
890890
data = data.assign_attrs(label_range=(start, end), name=name)
891891

892892
if self.chunk:
893-
if freeze:
894-
raise ValueError("Chunked constraints cannot be frozen")
895893
data = data.chunk(self.chunk)
896894

897895
constraint = MutableConstraint(data, name=name, model=self, skip_broadcast=True)
898-
return self.constraints.add(constraint, freeze=freeze)
896+
return self.constraints.add(constraint, freeze=freeze and not self.chunk)
899897

900898
def add_objective(
901899
self,

test/test_constraints.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def test_constraint_assignment_chunked() -> None:
116116
lower = pd.DataFrame(np.zeros((10, 10)))
117117
upper = pd.Series(np.ones(10))
118118
x = m.add_variables(lower, upper)
119-
with pytest.raises(ValueError, match="Chunked constraints cannot be frozen"):
120-
m.add_constraints(x, GREATER_EQUAL, 0, name="c")
121-
m.add_constraints(x, GREATER_EQUAL, 0, name="c", freeze=False)
119+
m.add_constraints(x, GREATER_EQUAL, 0, name="c")
122120
assert m.constraints.coeffs.c.data.shape == (
123121
10,
124122
10,

0 commit comments

Comments
 (0)