From 82b89bd6a382083323b07a875347ccc5d3a5ed27 Mon Sep 17 00:00:00 2001 From: Soren Davis Date: Mon, 8 Jul 2024 09:17:01 -0600 Subject: [PATCH 1/4] fix build_linking_constraints error in kernel conic primal_geomean.as_domain() --- pyomo/core/kernel/conic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/core/kernel/conic.py b/pyomo/core/kernel/conic.py index 1bb5f1b6ce8..cfc3e351b4d 100644 --- a/pyomo/core/kernel/conic.py +++ b/pyomo/core/kernel/conic.py @@ -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 From 8f311049360a5c4f5f2bba70aafea4794d087642 Mon Sep 17 00:00:00 2001 From: Soren Davis Date: Mon, 8 Jul 2024 10:18:11 -0600 Subject: [PATCH 2/4] fix apparent same issue in dual_geomean --- pyomo/core/kernel/conic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/core/kernel/conic.py b/pyomo/core/kernel/conic.py index cfc3e351b4d..bd78ba310f4 100644 --- a/pyomo/core/kernel/conic.py +++ b/pyomo/core/kernel/conic.py @@ -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]) b.q = cls(r=b.r, x=b.x) return b From a41efb574b9f50ffc3498f15d18d45ddbe0e1d94 Mon Sep 17 00:00:00 2001 From: Soren Davis Date: Fri, 12 Jul 2024 11:46:27 -0600 Subject: [PATCH 3/4] test for proper structure of changed as_domain() methods --- pyomo/core/tests/unit/kernel/test_conic.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pyomo/core/tests/unit/kernel/test_conic.py b/pyomo/core/tests/unit/kernel/test_conic.py index ccfbcca7e1f..fc70b421060 100644 --- a/pyomo/core/tests/unit/kernel/test_conic.py +++ b/pyomo/core/tests/unit/kernel/test_conic.py @@ -35,6 +35,8 @@ primal_power, dual_exponential, dual_power, + primal_geomean, + dual_geomean, ) @@ -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, +# 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([], []) From a8a78a78e9f5e68f811ee416aeb6154beade4122 Mon Sep 17 00:00:00 2001 From: Soren Davis Date: Wed, 17 Jul 2024 10:38:46 -0600 Subject: [PATCH 4/4] Be more direct with my comments --- pyomo/core/tests/unit/kernel/test_conic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyomo/core/tests/unit/kernel/test_conic.py b/pyomo/core/tests/unit/kernel/test_conic.py index fc70b421060..bd97c13fc2e 100644 --- a/pyomo/core/tests/unit/kernel/test_conic.py +++ b/pyomo/core/tests/unit/kernel/test_conic.py @@ -786,8 +786,8 @@ def test_as_domain(self): x[1].value = None -# these mosek 10 constraints are really anemic and can't be evaluated, pprinted, -# checked for convexity, pickled, etc. +# These mosek 10 constraints can't be evaluated, pprinted, checked for convexity, +# pickled, etc., so I won't use the _conic_tester_base for them class Test_primal_geomean(unittest.TestCase): def test_as_domain(self): b = primal_geomean.as_domain(r=[2, 3], x=6)