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

Kernel: fix bug in conic geomean #3310

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions pyomo/core/kernel/conic.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def as_domain(cls, r, x):
b = block()
b.r = variable_tuple([variable(lb=0) for i in range(len(r))])
b.x = variable()
b.c = _build_linking_constraints(list(r) + [x], list(b.r) + [x])
b.c = _build_linking_constraints(list(r) + [x], list(b.r) + [b.x])
b.q = cls(r=b.r, x=b.x)
return b

Expand Down Expand Up @@ -934,7 +934,7 @@ def as_domain(cls, r, x):
b = block()
b.r = variable_tuple([variable(lb=0) for i in range(len(r))])
b.x = variable()
b.c = _build_linking_constraints(list(r) + [x], list(b.r) + [x])
b.c = _build_linking_constraints(list(r) + [x], list(b.r) + [b.x])
mrmundt marked this conversation as resolved.
Show resolved Hide resolved
b.q = cls(r=b.r, x=b.x)
return b

Expand Down
36 changes: 36 additions & 0 deletions pyomo/core/tests/unit/kernel/test_conic.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
primal_power,
dual_exponential,
dual_power,
primal_geomean,
dual_geomean,
)


Expand Down Expand Up @@ -784,6 +786,40 @@ def test_as_domain(self):
x[1].value = None


# these mosek 10 constraints are really anemic and can't be evaluated, pprinted,
sadavis1 marked this conversation as resolved.
Show resolved Hide resolved
# checked for convexity, pickled, etc.
class Test_primal_geomean(unittest.TestCase):
def test_as_domain(self):
b = primal_geomean.as_domain(r=[2, 3], x=6)
self.assertIs(type(b), block)
self.assertIs(type(b.q), primal_geomean)
self.assertIs(type(b.r), variable_tuple)
self.assertIs(type(b.x), variable)
self.assertIs(type(b.c), constraint_tuple)
self.assertExpressionsEqual(b.c[0].body, b.r[0])
self.assertExpressionsEqual(b.c[0].rhs, 2)
self.assertExpressionsEqual(b.c[1].body, b.r[1])
self.assertExpressionsEqual(b.c[1].rhs, 3)
self.assertExpressionsEqual(b.c[2].body, b.x)
self.assertExpressionsEqual(b.c[2].rhs, 6)


class Test_dual_geomean(unittest.TestCase):
def test_as_domain(self):
b = dual_geomean.as_domain(r=[2, 3], x=6)
self.assertIs(type(b), block)
self.assertIs(type(b.q), dual_geomean)
self.assertIs(type(b.r), variable_tuple)
self.assertIs(type(b.x), variable)
self.assertIs(type(b.c), constraint_tuple)
self.assertExpressionsEqual(b.c[0].body, b.r[0])
self.assertExpressionsEqual(b.c[0].rhs, 2)
self.assertExpressionsEqual(b.c[1].body, b.r[1])
self.assertExpressionsEqual(b.c[1].rhs, 3)
self.assertExpressionsEqual(b.c[2].body, b.x)
self.assertExpressionsEqual(b.c[2].rhs, 6)


class TestMisc(unittest.TestCase):
def test_build_linking_constraints(self):
c = _build_linking_constraints([], [])
Expand Down
Loading