def test_n2_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = om.Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() n2(p, outfile=self.compare_html_filename, show_browser=DEBUG_BROWSER) n2(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG_BROWSER) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.sqlite_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao n2 --no_browser %s' % self.sqlite_db_filename2) # Compare models from the files generated from the Problem and the recording sqlite_model_data = self._extract_compressed_model( self.sqlite_html_filename) compare_model_data = self._extract_compressed_model( self.compare_html_filename) self.assertTrue( sqlite_model_data == compare_model_data, 'Model data from sqlite does not match data from Problem.')
def test_n2_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() n2(p, outfile=self.compare_html_filename, show_browser=DEBUG_BROWSER) n2(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG_BROWSER) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.sqlite_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao n2 --no_browser %s' % self.sqlite_db_filename2) # Compare the sizes of the files generated from the Problem and the recording size1 = os.path.getsize(self.sqlite_html_filename) size2 = os.path.getsize(self.compare_html_filename) self.assertTrue( size1 == size2, 'File size of ' + self.sqlite_html_filename + ' is ' + str(size1) + ', but size of ' + self.compare_html_filename + ' is ' + str(size2))
def test_model_viewer_has_correct_data_from_sqlite(self): """ Verify that the correct data exists when a model structure is recorded and then pulled out of a sqlite db file and compared to the expected structure. Uses the SellarStateConnection model. """ p = om.Problem(model=SellarStateConnection()) r = SqliteRecorder(self.sqlite_db_filename) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() model_viewer_data = _get_viewer_data(self.sqlite_db_filename) with open(os.path.join(self.parent_dir, 'sellar_tree.json')) as json_file: expected_tree = json.load(json_file) # check expected model tree self.check_model_viewer_data( model_viewer_data, expected_tree, self.expected_pathnames, self.expected_conns, self.expected_abs2prom, self.expected_declare_partials, self.expected_driver_name, self.expected_design_vars_names, self.expected_responses_names)
def test_view_model_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup(check=False) p.final_setup() r.shutdown() view_model(self.sqlite_db_filename2, outfile=self.sqlite_filename, show_browser=False) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100)
def test_model_viewer_has_correct_data_from_sqlite(self): """ Verify that the correct data exists when a model structure is recorded and then pulled out of a sqlite db file and compared to the expected structure. Uses the SellarStateConnection model. """ p = Problem(model=SellarStateConnection()) r = SqliteRecorder(self.sqlite_db_filename) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() model_viewer_data = _get_viewer_data(self.sqlite_db_filename) print(model_viewer_data['tree']) # check expected model tree self.assertDictEqual(model_viewer_data['tree'], self.expected_tree) # check expected system pathnames pathnames = model_viewer_data['sys_pathnames_list'] self.assertListEqual(sorted(pathnames), self.expected_pathnames) # check expected connections, after mapping cycle_arrows indices back to pathnames connections = sorted(model_viewer_data['connections_list'], key=lambda x: (x['tgt'], x['src'])) for conn in connections: if 'cycle_arrows' in conn: cycle_arrows = [] for src, tgt in conn['cycle_arrows']: cycle_arrows.append(' '.join( [pathnames[src], pathnames[tgt]])) conn['cycle_arrows'] = sorted(cycle_arrows) self.assertEqual(len(connections), len(self.expected_conns)) for c, ex in zip(connections, self.expected_conns): self.assertEqual(c['src'], ex['src']) self.assertEqual(c['tgt'], ex['tgt']) self.assertEqual(c.get('cycle_arrows', []), ex.get('cycle_arrows', [])) # check expected abs2prom map self.assertDictEqual(model_viewer_data['abs2prom'], self.expected_abs2prom)
def test_view_model_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup(check=False) p.final_setup() r.shutdown() view_model(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao view_model --no_browser %s' % self.sqlite_db_filename2)
def test_model_viewer_has_correct_data_from_sqlite(self): """ Verify that the correct data exists when a model structure is recorded and then pulled out of a sqlite db file and compared to the expected structure. Uses the SellarStateConnection model. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename) p.driver.add_recorder(r) p.setup(check=False) p.final_setup() r.shutdown() model_viewer_data = _get_viewer_data(self.sqlite_db_filename) tree_json = json.dumps(model_viewer_data['tree']) conns_json = json.dumps(model_viewer_data['connections_list']) self.assertEqual(self.expected_tree_json, tree_json) self.assertEqual(self.expected_conns_json, conns_json)
def test_view_model_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() view_model(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao view_model --no_browser %s' % self.sqlite_db_filename2)
def test_model_viewer_has_correct_data_from_sqlite(self): """ Verify that the correct data exists when a model structure is recorded and then pulled out of a sqlite db file and compared to the expected structure. Uses the SellarStateConnection model. """ p = Problem(model=SellarStateConnection()) r = SqliteRecorder(self.sqlite_db_filename) p.driver.add_recorder(r) p.setup(check=False) p.final_setup() r.shutdown() model_viewer_data = _get_viewer_data(self.sqlite_db_filename) # check expected model tree self.assertDictEqual(model_viewer_data['tree'], self.expected_tree) # check expected system pathnames pathnames = model_viewer_data['sys_pathnames_list'] self.assertListEqual(sorted(pathnames), self.expected_pathnames) # check expected connections, after mapping cycle_arrows indices back to pathnames connections = model_viewer_data['connections_list'] for conn in connections: if 'cycle_arrows' in conn: cycle_arrows = [] for src, tgt in conn['cycle_arrows']: cycle_arrows.append(' '.join([pathnames[src], pathnames[tgt]])) conn['cycle_arrows'] = sorted(cycle_arrows) self.assertListEqual(connections, self.expected_conns) # check expected abs2prom map self.assertDictEqual(model_viewer_data['abs2prom'], self.expected_abs2prom)