Skip to content

Commit 5cf85d5

Browse files
committed
fix tests
1 parent a7791e1 commit 5cf85d5

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

pyomo/contrib/pynumero/algorithms/solvers/tests/test_cyipopt_interfaces.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def test_model1_CyIpoptNLP_scaling(self):
156156

157157
cynlp = CyIpoptNLP(PyomoNLP(m))
158158
obj_scaling, x_scaling, g_scaling = cynlp.scaling_factors()
159-
self.assertTrue(obj_scaling is None)
160-
self.assertTrue(x_scaling is None)
161-
self.assertTrue(g_scaling is None)
159+
self.assertTrue(obj_scaling == 1.0)
160+
self.assertTrue((x_scaling == 1.0).all())
161+
self.assertTrue((g_scaling == 1.0).all())
162162

163163
def _check_model1(self, nlp, cynlp):
164164
# test x_init

pyomo/contrib/pynumero/interfaces/tests/test_external_grey_box_model.py

+33-4
Original file line numberDiff line numberDiff line change
@@ -1827,18 +1827,47 @@ def create_model_two_equalities_two_outputs(self, external_model):
18271827
m.egb.outputs['Pout'].setub(70)
18281828
return m
18291829

1830-
def test_scaling_all_missing(self):
1830+
def test_scaling_all_one(self):
18311831
m = self.create_model_two_equalities_two_outputs(
18321832
ex_models.PressureDropTwoEqualitiesTwoOutputs()
18331833
)
18341834
m.obj = pyo.Objective(expr=(m.egb.outputs['Pout'] - 20) ** 2)
18351835
pyomo_nlp = PyomoGreyBoxNLP(m)
18361836
fs = pyomo_nlp.get_obj_scaling()
1837+
self.assertEqual(fs, 1.0)
1838+
1839+
comparison_x_order = [
1840+
'egb.inputs[Pin]',
1841+
'egb.inputs[c]',
1842+
'egb.inputs[F]',
1843+
'egb.inputs[P1]',
1844+
'egb.inputs[P3]',
1845+
'egb.outputs[P2]',
1846+
'egb.outputs[Pout]',
1847+
'hin',
1848+
'hout',
1849+
]
1850+
x_order = pyomo_nlp.variable_names()
18371851
xs = pyomo_nlp.get_primals_scaling()
1852+
comparison_xs = np.asarray([1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=np.float64)
1853+
check_vectors_specific_order(
1854+
self, xs, x_order, comparison_xs, comparison_x_order
1855+
)
1856+
1857+
comparison_c_order = [
1858+
'egb.pdrop1',
1859+
'egb.pdrop3',
1860+
'egb.P2_con',
1861+
'egb.Pout_con',
1862+
'incon',
1863+
'outcon',
1864+
]
1865+
c_order = pyomo_nlp.constraint_names()
18381866
cs = pyomo_nlp.get_constraints_scaling()
1839-
self.assertIsNone(fs)
1840-
self.assertIsNone(xs)
1841-
self.assertIsNone(cs)
1867+
comparison_cs = np.asarray([1, 1, 1, 1, 1, 1], dtype=np.float64)
1868+
check_vectors_specific_order(
1869+
self, cs, c_order, comparison_cs, comparison_c_order
1870+
)
18421871

18431872
def test_scaling_pyomo_model_only(self):
18441873
m = self.create_model_two_equalities_two_outputs(

pyomo/contrib/pynumero/interfaces/tests/test_pyomo_grey_box_nlp.py

+35-4
Original file line numberDiff line numberDiff line change
@@ -2248,18 +2248,49 @@ def create_model_two_equalities_two_outputs(self, external_model):
22482248
m.egb.outputs['Pout'].setub(70)
22492249
return m
22502250

2251-
def test_scaling_all_missing(self):
2251+
def test_scaling_all_one(self):
22522252
m = self.create_model_two_equalities_two_outputs(
22532253
ex_models.PressureDropTwoEqualitiesTwoOutputs()
22542254
)
22552255
m.obj = pyo.Objective(expr=(m.egb.outputs['Pout'] - 20) ** 2)
22562256
pyomo_nlp = PyomoNLPWithGreyBoxBlocks(m)
2257+
2258+
comparison_x_order = [
2259+
'egb.inputs[Pin]',
2260+
'egb.inputs[c]',
2261+
'egb.inputs[F]',
2262+
'egb.inputs[P1]',
2263+
'egb.inputs[P3]',
2264+
'egb.outputs[P2]',
2265+
'egb.outputs[Pout]',
2266+
'hin',
2267+
'hout',
2268+
]
2269+
x_order = pyomo_nlp.primals_names()
2270+
comparison_c_order = [
2271+
'egb.pdrop1',
2272+
'egb.pdrop3',
2273+
'egb.output_constraints[P2]',
2274+
'egb.output_constraints[Pout]',
2275+
'incon',
2276+
'outcon',
2277+
]
2278+
c_order = pyomo_nlp.constraint_names()
2279+
22572280
fs = pyomo_nlp.get_obj_scaling()
2281+
self.assertEqual(fs, 1.0)
2282+
22582283
xs = pyomo_nlp.get_primals_scaling()
2284+
comparison_xs = np.asarray([1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=np.float64)
2285+
check_vectors_specific_order(
2286+
self, xs, x_order, comparison_xs, comparison_x_order
2287+
)
2288+
22592289
cs = pyomo_nlp.get_constraints_scaling()
2260-
self.assertIsNone(fs)
2261-
self.assertIsNone(xs)
2262-
self.assertIsNone(cs)
2290+
comparison_cs = np.asarray([1, 1, 1, 1, 1, 1], dtype=np.float64)
2291+
check_vectors_specific_order(
2292+
self, cs, c_order, comparison_cs, comparison_c_order
2293+
)
22632294

22642295
def test_scaling_pyomo_model_only(self):
22652296
m = self.create_model_two_equalities_two_outputs(

0 commit comments

Comments
 (0)