@@ -1338,55 +1338,29 @@ def processObjectiveGradient(self, funcsSens):
1338
1338
nobj = len (self .objectives )
1339
1339
gobj = np .zeros ((nobj , self .ndvs ))
1340
1340
1341
- cond = False
1342
- # this version is required for python 3 compatibility
1343
- cond = isinstance (list (funcsSens .keys ())[0 ], str )
1344
- if cond : # we have a nested dictionary
1345
- iObj = 0
1346
- for objKey in self .objectives .keys ():
1347
- if objKey in funcsSens :
1348
- for dvGroup in funcsSens [objKey ]:
1349
- if dvGroup in dvGroups :
1350
- # Now check that the array is the correct length:
1351
- ss = self .dvOffset [dvGroup ]
1352
- tmp = np .array (funcsSens [objKey ][dvGroup ]).squeeze ()
1353
- if tmp .size == ss [1 ] - ss [0 ]:
1354
- # Everything checks out so set:
1355
- gobj [iObj , ss [0 ] : ss [1 ]] = tmp
1356
- else :
1357
- raise Error (
1358
- (
1359
- "The shape of the objective derivative for dvGroup '{}' is the incorrect length. "
1360
- + "Expecting a shape of {} but received a shape of {}."
1361
- ).format (dvGroup , (ss [1 ] - ss [0 ],), funcsSens [objKey ][dvGroup ].shape )
1362
- )
1363
- else :
1364
- raise Error ("The dvGroup key '%s' is not valid" % dvGroup )
1365
- else :
1366
- raise Error ("The key for the objective gradient, '%s', was not found." % objKey )
1367
- iObj += 1
1368
- else : # Then it must be a tuple; assume flat dict
1369
- for (objKey , dvGroup ), val in funcsSens .items ():
1370
- if objKey in self .objectives .keys ():
1371
- try :
1372
- iObj = self .objectiveIdx [objKey ]
1373
- except KeyError :
1374
- raise Error ("The key for the objective gradient, '%s', was not found." % objKey )
1375
- try :
1341
+ iObj = 0
1342
+ for objKey in self .objectives .keys ():
1343
+ if objKey in funcsSens :
1344
+ for dvGroup in funcsSens [objKey ]:
1345
+ if dvGroup in dvGroups :
1346
+ # Now check that the array is the correct length:
1376
1347
ss = self .dvOffset [dvGroup ]
1377
- except KeyError :
1378
- raise Error ("The dvGroup key '%s' is not valid" % dvGroup )
1379
- tmp = np .array (val ).squeeze ()
1380
- if tmp .size == ss [1 ] - ss [0 ]:
1381
- # Everything checks out so set:
1382
- gobj [iObj , ss [0 ] : ss [1 ]] = tmp
1348
+ tmp = np .array (funcsSens [objKey ][dvGroup ]).squeeze ()
1349
+ if tmp .size == ss [1 ] - ss [0 ]:
1350
+ # Everything checks out so set:
1351
+ gobj [iObj , ss [0 ] : ss [1 ]] = tmp
1352
+ else :
1353
+ raise Error (
1354
+ (
1355
+ "The shape of the objective derivative for dvGroup '{}' is the incorrect length. "
1356
+ + "Expecting a shape of {} but received a shape of {}."
1357
+ ).format (dvGroup , (ss [1 ] - ss [0 ],), funcsSens [objKey ][dvGroup ].shape )
1358
+ )
1383
1359
else :
1384
- raise Error (
1385
- (
1386
- "The shape of the objective derivative for dvGroup '{}' is the incorrect length. "
1387
- + "Expecting a shape of {} but received a shape of {}."
1388
- ).format (dvGroup , (ss [1 ] - ss [0 ],), val .shape )
1389
- )
1360
+ raise Error ("The dvGroup key '%s' is not valid" % dvGroup )
1361
+ else :
1362
+ raise Error ("The key for the objective gradient, '%s', was not found." % objKey )
1363
+ iObj += 1
1390
1364
1391
1365
# Note that we looped over the keys in funcsSens[objKey]
1392
1366
# and not the variable keys since a variable key not in
@@ -1468,21 +1442,17 @@ def processConstraintJacobian(self, gcon):
1468
1442
ndvs = ss [1 ] - ss [0 ]
1469
1443
1470
1444
gotDerivative = False
1471
- try : # Try using a nested dictionary return
1445
+ try :
1472
1446
if dvGroup in gcon [iCon ]:
1473
1447
tmp = convertToCOO (gcon [iCon ][dvGroup ])
1474
1448
gotDerivative = True
1475
1449
except KeyError :
1476
- try : # Using tuple dictornary return
1477
- tmp = convertToCOO (gcon [iCon , dvGroup ])
1478
- gotDerivative = True
1479
- except KeyError :
1480
- raise Error (
1481
- (
1482
- "The constraint Jacobian entry for '{}' with respect to '{}', as was defined in addConGroup(), "
1483
- + "was not found in constraint Jacobian dictionary provided."
1484
- ).format (con .name , dvGroup )
1485
- )
1450
+ raise Error (
1451
+ (
1452
+ "The constraint Jacobian entry for '{}' with respect to '{}', as was defined in addConGroup(), "
1453
+ + "was not found in constraint Jacobian dictionary provided."
1454
+ ).format (con .name , dvGroup )
1455
+ )
1486
1456
if not gotDerivative :
1487
1457
# All keys for this constraint must be returned
1488
1458
# since the user has explictly specified the wrt.
0 commit comments