Skip to content

Commit 09e3da9

Browse files
committed
fix tests
1 parent a7791e1 commit 09e3da9

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

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

+37-4
Original file line numberDiff line numberDiff line change
@@ -2248,18 +2248,51 @@ 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(
2285+
[1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=np.float64
2286+
)
2287+
check_vectors_specific_order(
2288+
self, xs, x_order, comparison_xs, comparison_x_order
2289+
)
2290+
22592291
cs = pyomo_nlp.get_constraints_scaling()
2260-
self.assertIsNone(fs)
2261-
self.assertIsNone(xs)
2262-
self.assertIsNone(cs)
2292+
comparison_cs = np.asarray([1, 1, 1, 1, 1, 1], dtype=np.float64)
2293+
check_vectors_specific_order(
2294+
self, cs, c_order, comparison_cs, comparison_c_order
2295+
)
22632296

22642297
def test_scaling_pyomo_model_only(self):
22652298
m = self.create_model_two_equalities_two_outputs(

0 commit comments

Comments
 (0)