def test_reading_driver_recording_with_system_vars(self): prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = pyOptSparseDriver(optimizer='SLSQP') driver.options['print_results'] = False driver.opt_settings['ACC'] = 1e-9 driver.recording_options['record_desvars'] = True driver.recording_options['record_responses'] = True driver.recording_options['record_objectives'] = True driver.recording_options['record_constraints'] = True driver.recording_options['includes'] = ['mda.d2.y2',] driver.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) # Test values from one case, the last case last_case = cr.driver_cases.get_case(-1) np.testing.assert_almost_equal(last_case.outputs['z'], prob['pz.z'], err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('pz.z')) np.testing.assert_almost_equal(last_case.outputs['x'], prob['px.x'], err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('px.x')) np.testing.assert_almost_equal(last_case.outputs['y2'], prob['mda.d2.y2'], err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('mda.d2.y2'))
def test_load_solver_cases(self): prob = SellarProblem() prob.setup() model = prob.model model.nonlinear_solver = NewtonSolver() model.linear_solver = LinearBlockGS() model.linear_solver.add_recorder(self.recorder) prob.run_model() prob.cleanup() cr = CaseReader(self.filename) case = cr.solver_cases.get_case(0) # Add one to all the inputs just to change the model # so we can see if loading the case values really changes the model for name in prob.model._inputs: model._inputs[name] += 1.0 for name in prob.model._outputs: model._outputs[name] += 1.0 # Now load in the case we recorded prob.load_case(case) _assert_model_matches_case(case, model)
def test_get_child_cases_system(self): prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = pyOptSparseDriver(optimizer='SLSQP') driver.options['print_results'] = False driver.opt_settings['ACC'] = 1e-9 model = prob.model model.add_recorder(self.recorder) model.nonlinear_solver.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) coords = [ 'rank0:SLSQP|0|root._solve_nonlinear|0|NLRunOnce|0', 'rank0:SLSQP|1|root._solve_nonlinear|1|NLRunOnce|0', 'rank0:SLSQP|2|root._solve_nonlinear|2|NLRunOnce|0', 'rank0:SLSQP|3|root._solve_nonlinear|3|NLRunOnce|0', 'rank0:SLSQP|4|root._solve_nonlinear|4|NLRunOnce|0', 'rank0:SLSQP|5|root._solve_nonlinear|5|NLRunOnce|0', 'rank0:SLSQP|6|root._solve_nonlinear|6|NLRunOnce|0' ] ind = 0 for c in cr.get_cases(recursive=True): self.assertEqual(c.iteration_coordinate, coords[ind]) ind += 1
def test_loading_cases(self): prob = SellarProblem() prob.setup() prob.add_recorder(self.recorder) prob.driver.add_recorder(self.recorder) prob.model.add_recorder(self.recorder) prob.model.nonlinear_solver.add_recorder(self.recorder) prob.run_driver() prob.record_iteration('c_1') prob.record_iteration('c_2') prob.cleanup() cr = CaseReader(self.filename) self.assertEqual(len(cr.driver_cases._cases), 0) self.assertEqual(len(cr.solver_cases._cases), 0) self.assertEqual(len(cr.system_cases._cases), 0) self.assertEqual(len(cr.problem_cases._cases), 0) cr.load_cases() # assert that we have now stored each of the cases self.assertEqual(len(cr.driver_cases._cases), cr.driver_cases.num_cases) self.assertEqual(len(cr.solver_cases._cases), cr.solver_cases.num_cases) self.assertEqual(len(cr.system_cases._cases), cr.system_cases.num_cases) self.assertEqual(len(cr.problem_cases._cases), cr.problem_cases.num_cases) for case_type in (cr.driver_cases, cr.solver_cases, cr.system_cases, cr.problem_cases): for case in case_type.list_cases(): self.assertTrue(case in case_type._cases) self.assertEqual(case, case_type._cases[case].iteration_coordinate)
def test_load_bad_system_case(self): prob = SellarProblem(SellarDerivativesGrouped) prob.model.add_recorder(self.recorder) driver = prob.driver = ScipyOptimizeDriver() driver.options['optimizer'] = 'SLSQP' driver.options['tol'] = 1e-9 driver.options['disp'] = False driver.recording_options['record_desvars'] = True driver.recording_options['record_responses'] = True driver.recording_options['record_objectives'] = True driver.recording_options['record_constraints'] = True prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) case = cr.system_cases.get_case(0) # try to load it into a completely different model prob = SellarProblem() prob.setup() error_msg = "Input variable, '[^']+', recorded in the case is not found in the model" with assertRaisesRegex(self, KeyError, error_msg): prob.load_case(case)
def test_feature_reading_derivatives(self): prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = ScipyOptimizeDriver(optimizer='SLSQP') driver.recording_options['record_derivatives'] = True driver.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) # Get derivatives associated with the first iteration. deriv_case = cr.driver_derivative_cases.get_case('rank0:SLSQP|1') # Get all derivatives from that case. derivs = deriv_case.get_derivatives() # See what derivatives have been recorded. self.assertEqual(set(derivs.keys), set([('obj', 'z'), ('con2', 'z'), ('con1', 'x'), ('obj', 'x'), ('con2', 'x'), ('con1', 'z')])) # Get specific derivative. assert_rel_error(self, derivs['obj', 'z'], [[9.61001056, 1.78448534]], 1e-4)
def test_subsystem_load_system_cases(self): prob = SellarProblem() prob.setup() model = prob.model model.recording_options['record_inputs'] = True model.recording_options['record_outputs'] = True model.recording_options['record_residuals'] = True # Only record a subsystem model.d2.add_recorder(self.recorder) prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) case = cr.system_cases.get_case(0) # Add one to all the inputs just to change the model # so we can see if loading the case values really changes the model for name in prob.model._inputs: model._inputs[name] += 1.0 for name in prob.model._outputs: model._outputs[name] += 1.0 # Now load in the case we recorded prob.load_case(case) _assert_model_matches_case(case, model.d2)
def test_reading_solver_metadata(self): prob = SellarProblem(linear_solver=LinearBlockGS()) prob.setup() prob.model.nonlinear_solver.add_recorder(self.recorder) prob.model.linear_solver.add_recorder(self.recorder) d1 = prob.model.d1 # SellarDis1withDerivatives (an ExplicitComponent) d1.nonlinear_solver = NonlinearBlockGS(maxiter=5) d1.nonlinear_solver.add_recorder(self.recorder) prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) self.assertEqual( sorted(cr.solver_metadata.keys()), sorted([ 'root.LinearBlockGS', 'root.NonlinearBlockGS', 'd1.NonlinearBlockGS' ])) self.assertEqual( cr.solver_metadata['d1.NonlinearBlockGS']['solver_options'] ['maxiter'], 5) self.assertEqual( cr.solver_metadata['root.NonlinearBlockGS']['solver_options'] ['maxiter'], 10) self.assertEqual( cr.solver_metadata['root.LinearBlockGS']['solver_class'], 'LinearBlockGS')
def test_get_vars(self): prob = SellarProblem() prob.setup() prob.model.add_recorder(self.recorder) prob.model.recording_options['record_residuals'] = True prob.driver.add_recorder(self.recorder) prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) driver_case = cr.driver_cases.get_case(0) desvars = driver_case.get_desvars() objectives = driver_case.get_objectives() constraints = driver_case.get_constraints() responses = driver_case.get_responses() expected_desvars = {"x": 1., "z": [5., 2.]} expected_objectives = {"obj": 28.58830817, } expected_constraints = {"con1": -22.42830237, "con2": -11.94151185} expected_responses = expected_objectives.copy() expected_responses.update(expected_constraints) for expected_set, actual_set in ((expected_desvars, desvars), (expected_objectives, objectives), (expected_constraints, constraints), (expected_responses, responses)): self.assertEqual(len(expected_set), len(actual_set.keys)) for k in actual_set: np.testing.assert_almost_equal(expected_set[k], actual_set[k])
def test_format_version(self): prob = SellarProblem() prob.model.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) self.assertEqual(cr.format_version, format_version, msg='format version not read correctly')
def run_driver(name, driver): pb = SellarProblem() case_recorder_filename = "test_openturns_doe_{}.sqlite".format(name) recorder = SqliteRecorder(case_recorder_filename) pb.driver = driver pb.driver.add_recorder(recorder) pb.setup() pb.run_driver() pb.cleanup() return pb, case_recorder_filename
def test_list_inputs(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) inputs = cr.list_inputs(None, True, True, True) expected_inputs = { 'obj_cmp.x': {'value': [1.]}, 'd2.z': {'value': [5., 2.]}, 'con_cmp2.y2': {'value': [12.05848815]}, 'obj_cmp.y2': {'value': [12.05848815]}, 'obj_cmp.z': {'value': [5., 2.]}, 'd1.x': {'value': [1.]}, 'd1.z': {'value': [5., 2.]}, 'd1.y2': {'value': [12.05848815]}, 'con_cmp1.y1': {'value': [25.58830237]}, 'obj_cmp.y1': {'value': [25.58830237]}, 'd2.y1': {'value': [25.58830237]} } self.assertEqual(len(inputs), 11) for o in inputs: vals = o[1] name = o[0] expected = expected_inputs[name] np.testing.assert_almost_equal(vals['value'], expected['value']) expected_inputs_case = { 'd1.z': {'value': [5., 2.]}, 'd1.x': {'value': [1.]}, 'd1.y2': {'value': [12.27257053]} } sys_case = cr.system_cases.get_case(1) inputs_case = cr.list_inputs(sys_case, True, True, True, None) for o in inputs_case: vals = o[1] name = o[0] expected = expected_inputs_case[name] np.testing.assert_almost_equal(vals['value'], expected['value'])
def test_optimization_load_system_cases(self): prob = SellarProblem(SellarDerivativesGrouped) prob.model.add_recorder(self.recorder) driver = prob.driver = ScipyOptimizeDriver() driver.options['optimizer'] = 'SLSQP' driver.options['tol'] = 1e-9 driver.options['disp'] = False driver.recording_options['record_desvars'] = True driver.recording_options['record_responses'] = True driver.recording_options['record_objectives'] = True driver.recording_options['record_constraints'] = True prob.setup() prob.run_driver() prob.cleanup() inputs_before = prob.model.list_inputs(values=True, units=True) outputs_before = prob.model.list_outputs(values=True, units=True) cr = CaseReader(self.filename) # get third case third_case = cr.system_cases.get_case(2) iter_count_before = driver.iter_count # run the model again with a fresh model prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = ScipyOptimizeDriver() driver.options['optimizer'] = 'SLSQP' driver.options['tol'] = 1e-9 driver.options['disp'] = False prob.setup() prob.load_case(third_case) prob.run_driver() prob.cleanup() inputs_after = prob.model.list_inputs(values=True, units=True) outputs_after = prob.model.list_outputs(values=True, units=True) iter_count_after = driver.iter_count for before, after in zip(inputs_before, inputs_after): np.testing.assert_almost_equal(before[1]['value'], after[1]['value']) for before, after in zip(outputs_before, outputs_after): np.testing.assert_almost_equal(before[1]['value'], after[1]['value']) # Should take one less iteration since we gave it a head start in the second run self.assertEqual(iter_count_before, iter_count_after + 1)
def test_reader_instantiates(self): """ Test that CaseReader returns an SqliteCaseReader. """ prob = SellarProblem() prob.model.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) self.assertTrue(isinstance(cr, SqliteCaseReader), msg='CaseReader not returning the correct subclass.')
def test_reading_driver_cases(self): """ Tests that the reader returns params correctly. """ prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = pyOptSparseDriver(optimizer='SLSQP') driver.options['print_results'] = False driver.opt_settings['ACC'] = 1e-9 driver.recording_options['record_desvars'] = True driver.recording_options['record_responses'] = True driver.recording_options['record_objectives'] = True driver.recording_options['record_constraints'] = True driver.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) # Test to see if we got the correct number of cases self.assertEqual(cr.driver_cases.num_cases, 7) self.assertEqual(cr.system_cases.num_cases, 0) self.assertEqual(cr.solver_cases.num_cases, 0) # Test to see if the access by case keys works: seventh_slsqp_iteration_case = cr.driver_cases.get_case( 'rank0:SLSQP|5') np.testing.assert_almost_equal( seventh_slsqp_iteration_case.outputs['z'], [1.97846296, -2.21388305e-13], decimal=2, err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('pz.z')) # Test values from one case, the last case last_case = cr.driver_cases.get_case(-1) np.testing.assert_almost_equal(last_case.outputs['z'], prob['z'], err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('pz.z')) np.testing.assert_almost_equal(last_case.outputs['x'], [-0.00309521], decimal=2, err_msg='Case reader gives ' 'incorrect Parameter value' ' for {0}'.format('px.x')) # Test to see if the case keys (iteration coords) come back correctly case_keys = cr.driver_cases.list_cases() print(case_keys) for i, iter_coord in enumerate(case_keys): self.assertEqual(iter_coord, 'rank0:SLSQP|{}'.format(i))
def test_reading_solver_cases(self): prob = SellarProblem() prob.setup() solver = prob.model.nonlinear_solver solver.add_recorder(self.recorder) solver.recording_options['record_abs_error'] = True solver.recording_options['record_rel_error'] = True solver.recording_options['record_solver_residuals'] = True prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) # Test to see if we got the correct number of cases self.assertEqual(cr.driver_cases.num_cases, 0) self.assertEqual(cr.system_cases.num_cases, 0) self.assertEqual(cr.solver_cases.num_cases, 7) # Test values from cases last_case = cr.solver_cases.get_case(-1) np.testing.assert_almost_equal( last_case.abs_err, [ 0.0, ], err_msg='Case reader gives incorrect value for abs_err') np.testing.assert_almost_equal( last_case.rel_err, [ 0.0, ], err_msg='Case reader gives incorrect value for rel_err') np.testing.assert_almost_equal( last_case.outputs['x'], [ 1.0, ], err_msg='Case reader gives ' 'incorrect output value for {0}'.format('x')) np.testing.assert_almost_equal( last_case.residuals['con2'], [ 0.0, ], err_msg='Case reader gives ' 'incorrect residual value for {0}'.format('con_cmp2.con2')) # Test to see if the case keys ( iteration coords ) come back correctly case_keys = cr.system_cases.list_cases() for i, iter_coord in enumerate(case_keys): self.assertEqual( iter_coord, 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|{}'. format(i))
def assert_case_generation(self, n, driver): pb = SellarProblem() pb.driver = driver case_recorder_filename = "test_smt_doe_driver_{}.sqlite".format(n) recorder = SqliteRecorder(case_recorder_filename) pb.driver.add_recorder(recorder) pb.setup() pb.run_driver() pb.cleanup() reader = CaseReader(case_recorder_filename) cases = reader.list_cases("driver") os.remove(case_recorder_filename) self.assertEqual(len(cases), n)
def test_reading_system_cases(self): prob = SellarProblem() model = prob.model model.recording_options['record_inputs'] = True model.recording_options['record_outputs'] = True model.recording_options['record_residuals'] = True model.recording_options['record_metadata'] = False model.add_recorder(self.recorder) prob.setup() model.d1.add_recorder(self.recorder) # SellarDis1withDerivatives (an ExplicitComp) model.obj_cmp.add_recorder(self.recorder) # an ExecComp prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) # Test to see if we got the correct number of cases self.assertEqual(cr.driver_cases.num_cases, 0) self.assertEqual(cr.system_cases.num_cases, 15) self.assertEqual(cr.solver_cases.num_cases, 0) # Test values from cases second_last_case = cr.system_cases.get_case(-2) np.testing.assert_almost_equal(second_last_case.inputs['y2'], [12.05848815, ], err_msg='Case reader gives ' 'incorrect input value for {0}'.format('obj_cmp.y2')) np.testing.assert_almost_equal(second_last_case.outputs['obj'], [28.58830817, ], err_msg='Case reader gives ' 'incorrect output value for {0}'.format('obj_cmp.obj')) np.testing.assert_almost_equal(second_last_case.residuals['obj'], [0.0, ], err_msg='Case reader gives ' 'incorrect residual value for {0}'.format('obj_cmp.obj')) # Test to see if the case keys ( iteration coords ) come back correctly case_keys = cr.system_cases.list_cases()[:-1] # Skip the last one for i, iter_coord in enumerate(case_keys): if i % 2 == 0: last_solver = 'd1._solve_nonlinear' else: last_solver = 'obj_cmp._solve_nonlinear' solver_iter_count = i // 2 self.assertEqual(iter_coord, 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|{iter}|' '{solver}|{iter}'.format(iter=solver_iter_count, solver=last_solver))
def test_auto_ivc_case(self): prob = SellarProblem(SellarDerivativesGrouped) prob.driver = om.ScipyOptimizeDriver(tol=1e-9, disp=False) prob.driver.add_recorder(self.recorder) prob.setup() prob.run_driver() prob.cleanup() cr = om.CaseReader(self.filename) first_case = cr.list_cases()[0] data_dict = _get_viewer_data(self.filename, case_id=first_case) vals = data_dict['tree']['children'][0]['children'] ivc_0_val = vals[0]['value'] ivc_1_val = vals[1]['value'] self.assertEqual(ivc_0_val, [5., 2]) self.assertEqual(ivc_1_val, np.array([1.]))
def test_get_child_cases(self): prob = SellarProblem(SellarDerivativesGrouped, nonlinear_solver=NonlinearRunOnce) driver = prob.driver = pyOptSparseDriver(optimizer='SLSQP') driver.options['print_results'] = False driver.opt_settings['ACC'] = 1e-9 driver.recording_options['record_desvars'] = True driver.recording_options['record_responses'] = True driver.recording_options['record_objectives'] = True driver.recording_options['record_constraints'] = True driver.add_recorder(self.recorder) prob.setup() model = prob.model model.add_recorder(self.recorder) model.nonlinear_solver.add_recorder(self.recorder) prob.run_driver() prob.cleanup() cr = CaseReader(self.filename) expected_coords = [ 'rank0:SLSQP|0', 'rank0:SLSQP|1', 'rank0:SLSQP|2', 'rank0:SLSQP|3', 'rank0:SLSQP|4', 'rank0:SLSQP|5', 'rank0:SLSQP|6', ] ind = 0 for c in cr.get_cases(): self.assertEqual(c.iteration_coordinate, expected_coords[ind]) ind += 1 coords_2 = [ 'rank0:SLSQP|0', 'rank0:SLSQP|0|root._solve_nonlinear|0|NLRunOnce|0', 'rank0:SLSQP|1', 'rank0:SLSQP|1|root._solve_nonlinear|1|NLRunOnce|0', 'rank0:SLSQP|2', 'rank0:SLSQP|2|root._solve_nonlinear|2|NLRunOnce|0', 'rank0:SLSQP|3', 'rank0:SLSQP|3|root._solve_nonlinear|3|NLRunOnce|0', 'rank0:SLSQP|4', 'rank0:SLSQP|4|root._solve_nonlinear|4|NLRunOnce|0', 'rank0:SLSQP|5', 'rank0:SLSQP|5|root._solve_nonlinear|5|NLRunOnce|0', 'rank0:SLSQP|6', 'rank0:SLSQP|6|root._solve_nonlinear|6|NLRunOnce|0' ] ind = 0 for c in cr.get_cases(recursive=True): self.assertEqual(c.iteration_coordinate, coords_2[ind]) ind += 1 coord_children = [ 'rank0:SLSQP|0|root._solve_nonlinear|0|NLRunOnce|0' ] for c in cr.get_cases('rank0:SLSQP|0', True): self.assertEqual(c.iteration_coordinate, coord_children[0])
def setUp(self): # override notebook flag for system, variable table and sqlite_reader from openmdao.core import system from openmdao.utils import variable_table from openmdao.recorders import sqlite_reader system.notebook = variable_table.notebook = sqlite_reader.notebook = True # capture HTML output from variable_table self.html_stream = StringIO() variable_table.HTML = lambda x: self.html_stream.write(x) sqlite_reader.HTML = lambda x: self.html_stream.write(x) # create recorder self.filename = "cases.sql" self.recorder = om.SqliteRecorder(self.filename, record_viewer_data=False) # create & run problem, generate case prob = SellarProblem() prob.setup() prob.add_recorder(self.recorder) prob.driver.add_recorder(self.recorder) prob.model.d1.add_recorder(self.recorder) prob.run_driver() prob.record('final') prob.cleanup() # expected results self.prob = prob self.expected_headers = ['driver', 'problem', 'system'] self.expected_sources = ['driver', 'problem', 'root.d1'] self.expected_source_vars = { 'driver': { 'inputs': [], 'outputs': ['con1', 'con2', 'obj', 'x', 'z'], 'residuals': [] }, 'problem': { 'inputs': [], 'outputs': ['con1', 'con2', 'obj', 'x', 'y1', 'y2', 'z'], 'residuals': [] }, 'root.d1': { 'inputs': ['x', 'y2', 'z'], 'outputs': ['y1'], 'residuals': ['y1'] } } self.expected_cases = [ 'rank0:Driver|0|root._solve_nonlinear|0|d1._solve_nonlinear|0', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|1|d1._solve_nonlinear|1', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|2|d1._solve_nonlinear|2', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|3|d1._solve_nonlinear|3', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|4|d1._solve_nonlinear|4', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|5|d1._solve_nonlinear|5', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|6|d1._solve_nonlinear|6', 'rank0:Driver|0|root._solve_nonlinear|0|NonlinearBlockGS|7|d1._solve_nonlinear|7', 'rank0:Driver|0', 'final', ]
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)
# -*- coding: utf-8 -*- from openmdao.test_suite.components.sellar import SellarProblem problem = SellarProblem() problem.setup() problem.final_setup()
from openmdao.api import Problem, SqliteRecorder from openmdao.test_suite.components.sellar import SellarProblem, SellarDerivativesGrouped from openmdao.drivers.pyoptsparse_driver import pyOptSparseDriver recorder = SqliteRecorder("sellar_grouped.db") prob = SellarProblem(SellarDerivativesGrouped) driver = prob.driver = pyOptSparseDriver(optimizer='SLSQP') prob.model.add_recorder(recorder, True) driver.add_recorder(recorder) prob.setup() prob.run_driver() prob.cleanup()