def test_list_outputs(self): prob = SellarProblem() prob.model.add_recorder(self.recorder) prob.model.recording_options['record_residuals'] = True prob.setup() d1 = prob.model.d1 # SellarDis1withDerivatives (an ExplicitComp) d1.nonlinear_solver = NonlinearBlockGS(maxiter=5) d1.add_recorder(self.recorder) prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) outputs = cr.list_outputs(None, True, True, True, True, None, True, True, True, True, True, True) expected_outputs = { 'd2.y2': {'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1,), 'values': [12.0584882]}, 'con_cmp1.con1': {'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1,), 'values': [-22.4283024]}, 'pz.z': {'lower': None, 'ref': 1.0, 'resids': [0., 0.], 'shape': (2,), 'values': [5., 2.]}, 'obj_cmp.obj': {'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1,), 'values': [28.5883082]}, 'px.x': {'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1,), 'values': [1.]}, 'con_cmp2.con2': {'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1,), 'values': [-11.9415118]}, 'd1.y1': {'lower': None, 'ref': 1.0, 'resids': [1.318e-10], 'shape': (1,), 'values': [25.5883024]} } self.assertEqual(len(outputs), 7) for o in outputs: vals = o[1] name = o[0] expected = expected_outputs[name] self.assertEqual(vals['lower'], expected['lower']) self.assertEqual(vals['ref'], expected['ref']) self.assertEqual(vals['shape'], expected['shape']) np.testing.assert_almost_equal(vals['resids'], expected['resids']) np.testing.assert_almost_equal(vals['value'], expected['values']) expected_outputs_case = { 'd1.y1': {'lower': None, 'ref': 1.0, 'resids': [1.318e-10], 'shape': (1,), 'values': [25.5454859]} } sys_case = cr.system_cases.get_case(1) outputs_case = cr.list_outputs(sys_case, True, True, True, True, None, True, True, True, True, True, True) for o in outputs_case: vals = o[1] name = o[0] expected = expected_outputs_case[name] self.assertEqual(vals['lower'], expected['lower']) self.assertEqual(vals['ref'], expected['ref']) self.assertEqual(vals['shape'], expected['shape']) np.testing.assert_almost_equal(vals['resids'], expected['resids']) np.testing.assert_almost_equal(vals['value'], expected['values']) for o in outputs_case: vals = o[1] name = o[0] expected = expected_outputs_case[name] self.assertEqual(vals['lower'], expected['lower']) self.assertEqual(vals['ref'], expected['ref']) self.assertEqual(vals['shape'], expected['shape']) np.testing.assert_almost_equal(vals['resids'], expected['resids']) np.testing.assert_almost_equal(vals['value'], expected['values']) impl_outputs_case = cr.list_outputs(sys_case, False, True) self.assertEqual(len(impl_outputs_case), 0)
def test_list_outputs(self): self.setup_sellar_model() nonlinear_solver = self.prob.model.nonlinear_solver linear_solver = self.prob.model.linear_solver d1 = self.prob.model.d1 # instance of SellarDis1withDerivatives, a Group d1.nonlinear_solver = NonlinearBlockGS() d1.nonlinear_solver.options['maxiter'] = 5 self.prob.model.add_recorder(self.recorder) self.prob.model.d1.add_recorder(self.recorder) self.prob.model.recording_options['record_residuals'] = True self.prob.setup(check=False) self.prob.run_driver() self.prob.cleanup() cr = CaseReader(self.filename) outputs = cr.list_outputs(None, True, True, True, True, None, True, True, True, True, True, True) expected_outputs = { 'd2.y2': { 'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1, ), 'values': [12.0584882] }, 'con_cmp1.con1': { 'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1, ), 'values': [-22.4283024] }, 'pz.z': { 'lower': None, 'ref': 1.0, 'resids': [0., 0.], 'shape': (2, ), 'values': [5., 2.] }, 'obj_cmp.obj': { 'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1, ), 'values': [28.5883082] }, 'px.x': { 'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1, ), 'values': [1.] }, 'con_cmp2.con2': { 'lower': None, 'ref': 1.0, 'resids': [0.], 'shape': (1, ), 'values': [-11.9415118] }, 'd1.y1': { 'lower': None, 'ref': 1.0, 'resids': [1.318e-10], 'shape': (1, ), 'values': [25.5883024] } } self.assertEqual(len(outputs), 7) for o in outputs: vals = o[1] name = o[0] expected = expected_outputs[name] self.assertEqual(vals['lower'], expected['lower']) self.assertEqual(vals['ref'], expected['ref']) self.assertEqual(vals['shape'], expected['shape']) np.testing.assert_almost_equal(vals['resids'], expected['resids']) np.testing.assert_almost_equal(vals['value'], expected['values']) expected_outputs_case = { 'd1.y1': { 'lower': None, 'ref': 1.0, 'resids': [1.318e-10], 'shape': (1, ), 'values': [25.5454859] } } outputs_case = cr.list_outputs(1, True, True, True, True, None, True, True, True, True, True, True) for o in outputs_case: vals = o[1] name = o[0] expected = expected_outputs_case[name] self.assertEqual(vals['lower'], expected['lower']) self.assertEqual(vals['ref'], expected['ref']) self.assertEqual(vals['shape'], expected['shape']) np.testing.assert_almost_equal(vals['resids'], expected['resids']) np.testing.assert_almost_equal(vals['value'], expected['values'])