def test_dataflow_multi_level(self): p = Problem(model=Group()) root = p.model indep = root.add_subsystem("indep", IndepVarComp('x', 1.0)) G1 = root.add_subsystem("G1", Group()) C1 = G1.add_subsystem("C1", MyComp()) C2 = G1.add_subsystem("C2", MyComp()) C3 = root.add_subsystem("C3", MyComp()) C4 = root.add_subsystem("C4", MyComp()) root.connect("C4.y", "G1.C2.a") root.connect("C4.y", "C3.a") root.connect("G1.C2.y", "G1.C1.a") root.connect("G1.C1.y", "C4.a") # make sure no system has dangling inputs so we avoid that warning root.connect("indep.x", "G1.C1.b") root.connect("indep.x", "G1.C2.b") root.connect("indep.x", "C3.b") root.connect("indep.x", "C4.b") # set iterative solvers since we have cycles root.linear_solver = LinearBlockGS() root.nonlinear_solver = NonlinearBlockGS() testlogger = TestLogger() p.setup(check=True, logger=testlogger) # Conclude setup but don't run model. p.final_setup() warnings = testlogger.get('warning') self.assertEqual(len(warnings), 1) info = testlogger.get('info') self.assertEqual( info[0], "The following groups contain cycles:\n Group '' has the following cycles: [['G1', 'C4']]\n" ) self.assertEqual( warnings[0], "The following systems are executed out-of-order:\n System 'C3' executes out-of-order with respect to its source systems ['C4']\n System 'G1.C1' executes out-of-order with respect to its source systems ['G1.C2']\n" ) # test comps_only cycle check graph = root.compute_sys_graph(comps_only=True) sccs = [sorted(s) for s in get_sccs_topo(graph) if len(s) > 1] self.assertEqual([['C4', 'G1.C1', 'G1.C2']], sccs)
def test_dataflow_multi_level(self): p = Problem() root = p.model root.add_subsystem("indep", IndepVarComp('x', 1.0)) G1 = root.add_subsystem("G1", Group()) G1.add_subsystem("C1", MyComp()) G1.add_subsystem("C2", MyComp()) root.add_subsystem("C3", MyComp()) root.add_subsystem("C4", MyComp()) root.connect("C4.y", "G1.C2.a") root.connect("C4.y", "C3.a") root.connect("G1.C2.y", "G1.C1.a") root.connect("G1.C1.y", "C4.a") # make sure no system has dangling inputs so we avoid that warning root.connect("indep.x", "G1.C1.b") root.connect("indep.x", "G1.C2.b") root.connect("indep.x", "C3.b") root.connect("indep.x", "C4.b") # set iterative solvers since we have cycles root.linear_solver = LinearBlockGS() root.nonlinear_solver = NonlinearBlockGS() testlogger = TestLogger() p.setup(check=['cycles', 'out_of_order'], logger=testlogger) p.final_setup() expected_info = ( "The following groups contain cycles:\n" " Group '' has the following cycles: [['G1', 'C4']]\n" ) expected_warning = ( "The following systems are executed out-of-order:\n" " System 'C3' executes out-of-order with respect to its source systems ['C4']\n" " System 'G1.C1' executes out-of-order with respect to its source systems ['G1.C2']\n" ) testlogger.find_in('info', expected_info) testlogger.find_in('warning', expected_warning) # test comps_only cycle check graph = root.compute_sys_graph(comps_only=True) sccs = [sorted(s) for s in get_sccs_topo(graph) if len(s) > 1] self.assertEqual([['C4', 'G1.C1', 'G1.C2']], sccs)
def test_dataflow_multi_level(self): p = Problem(model=Group()) root = p.model indep = root.add_subsystem("indep", IndepVarComp('x', 1.0)) G1 = root.add_subsystem("G1", Group()) C1 = G1.add_subsystem("C1", MyComp()) C2 = G1.add_subsystem("C2", MyComp()) C3 = root.add_subsystem("C3", MyComp()) C4 = root.add_subsystem("C4", MyComp()) root.connect("C4.y", "G1.C2.a") root.connect("C4.y", "C3.a") root.connect("G1.C2.y", "G1.C1.a") root.connect("G1.C1.y", "C4.a") # make sure no system has dangling inputs so we avoid that warning root.connect("indep.x", "G1.C1.b") root.connect("indep.x", "G1.C2.b") root.connect("indep.x", "C3.b") root.connect("indep.x", "C4.b") testlogger = TestLogger() p.setup(logger=testlogger) # Conclude setup but don't run model. p.final_setup() warnings = testlogger.get('warning') self.assertEqual(len(warnings), 3) self.assertEqual(warnings[0], "Group '' has the following cycles: [['G1', 'C4']]") self.assertEqual( warnings[1], "System 'C3' executes out-of-order with respect to its source systems ['C4']" ) self.assertEqual( warnings[2], "System 'G1.C1' executes out-of-order with respect to its source systems ['G1.C2']" ) # test comps_only cycle check graph = root.compute_sys_graph(comps_only=True) sccs = [sorted(s) for s in get_sccs_topo(graph) if len(s) > 1] self.assertEqual([['C4', 'G1.C1', 'G1.C2']], sccs)