def test_mode_auto(self): # Make sure mode=auto chooses correctly for all prob sizes as well # as for abs/rel/etc paths prob = Problem() root = prob.root = Group() root.add('p1', ParamComp('a', 1.0), promotes=['*']) root.add('p2', ParamComp('b', 1.0), promotes=['*']) root.add('comp', ExecComp(['x = 2.0*a + 3.0*b', 'y=4.0*a - 1.0*b']), promotes=['*']) root.ln_solver.options['mode'] = 'auto' prob.setup(check=False) prob.run() mode = prob._mode('auto', ['a'], ['x']) self.assertEqual(mode, 'fwd') mode = prob._mode('auto', ['a', 'b'], ['x']) self.assertEqual(mode, 'rev') # make sure _check function does it too #try: #mode = prob._check_for_matrix_matrix(['a'], ['x']) #except Exception as err: #msg = "Group '' must have the same mode as root to use Matrix Matrix." #self.assertEqual(text_type(err), msg) #else: #self.fail('Exception expected') root.ln_solver.options['mode'] = 'fwd' mode = prob._check_for_matrix_matrix(['a', 'b'], ['x']) self.assertEqual(mode, 'fwd')
def test_mode_auto(self): # Make sure mode=auto chooses correctly for all prob sizes as well # as for abs/rel/etc paths prob = Problem() root = prob.root = Group() root.add("p1", ParamComp("a", 1.0), promotes=["*"]) root.add("p2", ParamComp("b", 1.0), promotes=["*"]) root.add("comp", ExecComp(["x = 2.0*a + 3.0*b", "y=4.0*a - 1.0*b"]), promotes=["*"]) root.ln_solver.options["mode"] = "auto" prob.setup(check=False) prob.run() mode = prob._mode("auto", ["a"], ["x"]) self.assertEqual(mode, "fwd") mode = prob._mode("auto", ["a", "b"], ["x"]) self.assertEqual(mode, "rev") # make sure _check function does it too # try: # mode = prob._check_for_matrix_matrix(['a'], ['x']) # except Exception as err: # msg = "Group '' must have the same mode as root to use Matrix Matrix." # self.assertEqual(text_type(err), msg) # else: # self.fail('Exception expected') root.ln_solver.options["mode"] = "fwd" mode = prob._check_for_matrix_matrix(["a", "b"], ["x"]) self.assertEqual(mode, "fwd")
def test_check_matrix_matrix(self): prob = Problem() root = prob.root = Group() root.add('p1', ParamComp('a', 1.0), promotes=['*']) root.add('p2', ParamComp('b', 1.0), promotes=['*']) sub1 = root.add('sub1', Group(), promotes=['*']) sub2 = sub1.add('sub2', Group(), promotes=['*']) sub2.add('comp', ExecComp(['x = 2.0*a + 3.0*b', 'y=4.0*a - 1.0*b']), promotes=['*']) root.ln_solver.options['mode'] = 'fwd' sub1.ln_solver.options['mode'] = 'fwd' sub2.ln_solver.options['mode'] = 'fwd' prob.setup(check=False) prob.run() # NOTE: this call won't actually calculate mode because default ln_solver # is ScipyGMRES and its default mode is 'fwd', not 'auto'. mode = prob._check_for_matrix_matrix(['a'], ['x']) root.ln_solver.options['mode'] = 'rev' sub1.ln_solver.options['mode'] = 'rev' try: mode = prob._check_for_matrix_matrix(['a'], ['x']) except Exception as err: msg = "Group 'sub2' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." self.assertEqual(text_type(err), msg) else: self.fail('Exception expected') sub1.ln_solver.options['mode'] = 'fwd' sub2.ln_solver.options['mode'] = 'rev' try: mode = prob._check_for_matrix_matrix(['a'], ['x']) except Exception as err: msg = "Group 'sub1' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." self.assertEqual(text_type(err), msg) else: self.fail('Exception expected') sub1.ln_solver.options['mode'] = 'rev' mode = prob._check_for_matrix_matrix(['a'], ['x'])
def test_check_matrix_matrix(self): prob = Problem() root = prob.root = Group() root.add("p1", ParamComp("a", 1.0), promotes=["*"]) root.add("p2", ParamComp("b", 1.0), promotes=["*"]) sub1 = root.add("sub1", Group(), promotes=["*"]) sub2 = sub1.add("sub2", Group(), promotes=["*"]) sub2.add("comp", ExecComp(["x = 2.0*a + 3.0*b", "y=4.0*a - 1.0*b"]), promotes=["*"]) prob.setup(check=False) prob.run() # NOTE: this call won't actually calculate mode because default ln_solver # is ScipyGMRES and its default mode is 'fwd', not 'auto'. mode = prob._check_for_matrix_matrix(["a"], ["x"]) root.ln_solver.options["mode"] = "rev" sub1.ln_solver.options["mode"] = "rev" try: mode = prob._check_for_matrix_matrix(["a"], ["x"]) except Exception as err: msg = ( "Group 'sub2' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." ) self.assertEqual(text_type(err), msg) else: self.fail("Exception expected") sub1.ln_solver.options["mode"] = "fwd" sub2.ln_solver.options["mode"] = "rev" try: mode = prob._check_for_matrix_matrix(["a"], ["x"]) except Exception as err: msg = ( "Group 'sub1' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." ) self.assertEqual(text_type(err), msg) else: self.fail("Exception expected") sub1.ln_solver.options["mode"] = "rev" mode = prob._check_for_matrix_matrix(["a"], ["x"])
def test_check_matrix_matrix(self): prob = Problem() root = prob.root = Group() root.add('p1', ParamComp('a', 1.0), promotes=['*']) root.add('p2', ParamComp('b', 1.0), promotes=['*']) sub1 = root.add('sub1', Group(), promotes=['*']) sub2 = sub1.add('sub2', Group(), promotes=['*']) sub2.add('comp', ExecComp(['x = 2.0*a + 3.0*b', 'y=4.0*a - 1.0*b']), promotes=['*']) prob.setup(check=False) prob.run() # NOTE: this call won't actually calculate mode because default ln_solver # is ScipyGMRES and its default mode is 'fwd', not 'auto'. mode = prob._check_for_matrix_matrix(['a'], ['x']) root.ln_solver.options['mode'] = 'rev' sub1.ln_solver.options['mode'] = 'rev' try: mode = prob._check_for_matrix_matrix(['a'], ['x']) except Exception as err: msg = "Group 'sub2' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." self.assertEqual(text_type(err), msg) else: self.fail('Exception expected') sub1.ln_solver.options['mode'] = 'fwd' sub2.ln_solver.options['mode'] = 'rev' try: mode = prob._check_for_matrix_matrix(['a'], ['x']) except Exception as err: msg = "Group 'sub1' has mode 'fwd' but the root group has mode 'rev'. Modes must match to use Matrix Matrix." self.assertEqual(text_type(err), msg) else: self.fail('Exception expected') sub1.ln_solver.options['mode'] = 'rev' mode = prob._check_for_matrix_matrix(['a'], ['x'])
def test_mode_auto(self): # Make sure mode=auto chooses correctly for all prob sizes as well # as for abs/rel/etc paths prob = Problem() root = prob.root = Group() root.add('p1', ParamComp('a', 1.0), promotes=['*']) root.add('p2', ParamComp('b', 1.0), promotes=['*']) root.add('comp', ExecComp(['x = 2.0*a + 3.0*b', 'y=4.0*a - 1.0*b']), promotes=['*']) root.ln_solver.options['mode'] = 'auto' prob.setup(check=False) prob.run() mode = prob._mode('auto', ['a'], ['x']) self.assertEqual(mode, 'fwd') mode = prob._mode('auto', ['a', 'b'], ['x']) self.assertEqual(mode, 'rev') # make sure _check function does it too #try: #mode = prob._check_for_matrix_matrix(['a'], ['x']) #except Exception as err: #msg = "Group '' must have the same mode as root to use Matrix Matrix." #self.assertEqual(text_type(err), msg) #else: #self.fail('Exception expected') root.ln_solver.options['mode'] = 'fwd' mode = prob._check_for_matrix_matrix(['a', 'b'], ['x']) self.assertEqual(mode, 'fwd')