@@ -1242,9 +1242,8 @@ def test_pyros_nl_and_ampl_writer_tol(self):
1242
1242
)
1243
1243
def test_pyros_math_domain_error (self ):
1244
1244
"""
1245
- Test PyROS on a two-stage problem, discrete
1246
- set type with a math domain error evaluating
1247
- second-stage inequality constraint expressions in separation.
1245
+ Test PyROS behavior is as expected when there are errors
1246
+ encountered while evaluating separation problem objectives.
1248
1247
"""
1249
1248
m = ConcreteModel ()
1250
1249
m .q = Param (initialize = 1 , mutable = True )
@@ -1259,16 +1258,35 @@ def test_pyros_math_domain_error(self):
1259
1258
pyros_solver = SolverFactory ("pyros" )
1260
1259
1261
1260
with self .assertRaisesRegex (
1262
- expected_exception = ArithmeticError ,
1263
- expected_regex = (
1264
- "Evaluation of second-stage inequality constraint.*math domain error.*"
1265
- ),
1266
- msg = "ValueError arising from math domain error not raised" ,
1261
+ expected_exception = ValueError ,
1262
+ expected_regex = "math domain error" ,
1263
+ msg = "Exception arising from math domain error not raised" ,
1267
1264
):
1268
1265
# should raise math domain error:
1269
1266
# (1) lower bounding constraint on x2 solved first
1270
- # in separation, q = 0 in worst case
1271
- # (2) now tries to evaluate log(q), but q = 0
1267
+ # in separation. Solution has q = 0
1268
+ # (2) upon solution of the first separation problem,
1269
+ # evaluation of x2 - log(q) at q = 0
1270
+ # results in exception
1271
+ pyros_solver .solve (
1272
+ model = m ,
1273
+ first_stage_variables = [m .x1 ],
1274
+ second_stage_variables = [m .x2 ],
1275
+ uncertain_params = [m .q ],
1276
+ uncertainty_set = box_set ,
1277
+ local_solver = local_solver ,
1278
+ global_solver = global_solver ,
1279
+ decision_rule_order = 1 ,
1280
+ tee = True ,
1281
+ )
1282
+
1283
+ # this should result in error stemming from division by zero
1284
+ m .x2 .setub (1 / m .q )
1285
+ with self .assertRaisesRegex (
1286
+ expected_exception = ZeroDivisionError ,
1287
+ expected_regex = "float division by zero" ,
1288
+ msg = "Exception arising from math domain error not raised" ,
1289
+ ):
1272
1290
pyros_solver .solve (
1273
1291
model = m ,
1274
1292
first_stage_variables = [m .x1 ],
0 commit comments