Example #1
0
    def test_can_715(self):
        # this test is just to show the superiority of bicoloring vs. single coloring in
        # either direction.  Bicoloring gives only 21 colors in this case vs. 105 for either
        # fwd or rev.
        matdir = os.path.join(os.path.dirname(openmdao.test_suite.__file__), 'matrices')

        # uses matrix can_715 from the sparse matrix collection website
        mat = load_npz(os.path.join(matdir, 'can_715.npz')).toarray()
        mat = np.asarray(mat, dtype=bool)
        coloring = get_simul_meta(None, 'auto', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 21)

        # verify that unidirectional colorings are much worse (105 vs 21 for bidirectional)
        coloring = get_simul_meta(None, 'fwd', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 105)

        coloring = get_simul_meta(None, 'rev', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 105)
Example #2
0
    def test_can_715(self):
        # this test is just to show the superiority of bicoloring vs. single coloring in
        # either direction.  Bicoloring gives only 21 colors in this case vs. 105 for either
        # fwd or rev.
        matdir = os.path.join(os.path.dirname(openmdao.test_suite.__file__), 'matrices')

        # uses matrix can_715 from the sparse matrix collection website
        mat = load_npz(os.path.join(matdir, 'can_715.npz')).toarray()
        mat = np.asarray(mat, dtype=bool)
        coloring = get_simul_meta(None, 'auto', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 21)

        # verify that unidirectional colorings are much worse (105 vs 21 for bidirectional)
        coloring = get_simul_meta(None, 'fwd', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 105)

        coloring = get_simul_meta(None, 'rev', include_sparsity=False, setup=False,
                                  run_model=False, bool_jac=mat,
                                  stream=None)

        tot_size, tot_colors, fwd_solves, rev_solves, pct = _solves_info(coloring)

        self.assertEqual(tot_colors, 105)
Example #3
0
 def color(self, mode='auto', stream=sys.stdout):
     self.coloring = get_simul_meta(None,
                                    mode,
                                    include_sparsity=False,
                                    setup=False,
                                    run_model=False,
                                    bool_jac=self.J,
                                    stream=stream)
     return self.coloring
Example #4
0
    def test_exclude(self):
        p = Problem()
        model = p.model

        indep = model.add_subsystem('indep', IndepVarComp())
        indep.add_output("a", val=1.0)
        indep.add_output("b", val=1.0)
        indep.add_output("c", val=1.0)
        indep.add_output("d", val=1.0)
        indep.add_output("e", val=1.0)

        obj = model.add_subsystem('obj', ExecComp('obj=a+b+c+d+ee'))
        con1 = model.add_subsystem('con1', ExecComp('con=a*2.0 + b'))
        con2 = model.add_subsystem('con2', ExecComp('con=c*3.0 + 2.0*d'))
        con3 = model.add_subsystem('con3', ExecComp('con=ee*1.5 - 3.0*c + a'))

        model.connect("indep.a", ("obj.a", "con1.a", "con3.a"))
        model.connect("indep.b", ("obj.b", "con1.b"))
        model.connect("indep.c", ("obj.c", "con2.c", "con3.c"))
        model.connect("indep.d", ("obj.d", "con2.d"))
        model.connect("indep.e", ("obj.ee", "con3.ee"))

        model.add_design_var("indep.a")
        model.add_design_var("indep.b")
        model.add_design_var("indep.c")
        model.add_design_var("indep.d")
        model.add_design_var("indep.e")

        model.add_objective('obj.obj')
        model.add_constraint('con1.con')
        model.add_constraint('con2.con')
        model.add_constraint('con3.con', simul_coloring_excludes=True)

        p.setup(mode='fwd')
        p.run_model()

        coloring = get_simul_meta(p,
                                  include_sparsity=False,
                                  setup=False,
                                  run_model=False,
                                  stream=None)
        tot_size1, tot_colors1, colored_solves1, opp_solves1, pct1, dominant_mode1 = _solves_info(
            coloring)

        # this is not a great coloring. It's just done to test simul_coloring_excludes
        self.assertEqual(opp_solves1, 2)
        self.assertEqual(tot_colors1, 4)
        self.assertEqual(coloring['rev'][0][0], [3, 0])
Example #5
0
 def color(self, mode='auto', stream=sys.stdout):
     self.coloring = get_simul_meta(None, mode, include_sparsity=False, setup=False,
                                    run_model=False, bool_jac=self.J,
                                    stream=stream)
     return self.coloring