Exemplo n.º 1
0
    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)
Exemplo n.º 2
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',
        ]