コード例 #1
0
    def _speedup_analysis(self, N_generator=None, filename=None, **kwargs):
        if N_generator is None:

            def N_generator(n):
                return n

        N = self.SCM_approximation.N

        print(TextBox("SCM speedup analysis begins", fill="="))
        print("")

        speedup_analysis_table = SpeedupAnalysisTable(self.testing_set)
        speedup_analysis_table.set_Nmax(N)
        speedup_analysis_table.add_column("speedup",
                                          group_name="speedup",
                                          operations=("min", "mean", "max"))

        exact_timer = Timer("parallel")
        SCM_timer = Timer("serial")

        for (mu_index, mu) in enumerate(self.testing_set):
            print(TextLine("SCM " + str(mu_index), fill="~"))

            self.SCM_approximation.set_mu(mu)

            exact_timer.start()
            self.SCM_approximation.evaluate_stability_factor()
            elapsed_exact = exact_timer.stop()

            for n in range(1, N + 1):  # n = 1, ... N
                n_arg = N_generator(n)

                if n_arg is not None:
                    SCM_timer.start()
                    self.SCM_approximation.get_stability_factor_lower_bound(
                        n_arg)
                    self.SCM_approximation.get_stability_factor_upper_bound(
                        n_arg)
                    elapsed_SCM = SCM_timer.stop()
                    speedup_analysis_table[
                        "speedup", n, mu_index] = elapsed_exact / elapsed_SCM
                else:
                    speedup_analysis_table["speedup", n,
                                           mu_index] = NotImplemented

        # Print
        print("")
        print(speedup_analysis_table)

        print("")
        print(TextBox("SCM speedup analysis ends", fill="="))
        print("")

        # Export speedup analysis table
        speedup_analysis_table.save(
            self.folder["speedup_analysis"],
            "speedup_analysis" if filename is None else filename)
コード例 #2
0
    def _speedup_analysis(self, N_generator=None, filename=None, **kwargs):
        if N_generator is None:
            def N_generator():
                N = self.EIM_approximation.N
                for n in range(1, N + 1):  # n = 1, ... N
                    yield n

        def N_generator_max():
            *_, Nmax = N_generator()
            return Nmax

        interpolation_method_name = self.EIM_approximation.parametrized_expression.interpolation_method_name()
        description = self.EIM_approximation.parametrized_expression.description()

        print(TextBox(interpolation_method_name + " speedup analysis begins for" + "\n"
                      + "\n".join(description), fill="="))
        print("")

        speedup_analysis_table = SpeedupAnalysisTable(self.testing_set)
        speedup_analysis_table.set_Nmax(N_generator_max())
        speedup_analysis_table.add_column("speedup", group_name="speedup", operations=("min", "mean", "max"))

        evaluate_timer = Timer("parallel")
        EIM_timer = Timer("serial")

        for (mu_index, mu) in enumerate(self.testing_set):
            print(TextLine(interpolation_method_name + " " + str(mu_index), fill=":"))

            self.EIM_approximation.set_mu(mu)

            # Evaluate the exact function on the truth grid
            evaluate_timer.start()
            self.EIM_approximation.evaluate_parametrized_expression()
            elapsed_evaluate = evaluate_timer.stop()

            for n in N_generator():
                EIM_timer.start()
                self.EIM_approximation.solve(n)
                elapsed_EIM = EIM_timer.stop()
                speedup_analysis_table["speedup", n, mu_index] = elapsed_evaluate / elapsed_EIM

        # Print
        print("")
        print(speedup_analysis_table)

        print("")
        print(TextBox(interpolation_method_name + " speedup analysis ends for" + "\n"
                      + "\n".join(description), fill="="))
        print("")

        # Export speedup analysis table
        speedup_analysis_table.save(self.folder["speedup_analysis"],
                                    "speedup_analysis" if filename is None else filename)
コード例 #3
0
 def __init__(self, *args, **kwargs):
     OriginalBenchmarkFixture.__init__(self, *args, **kwargs)
     # Customize self._timer
     self._timer = Timer("parallel")
コード例 #4
0
        def _speedup_analysis(self, N_generator=None, filename=None, **kwargs):
            if N_generator is None:

                def N_generator():
                    N = self.reduced_problem.N
                    if isinstance(N, dict):
                        N = min(N.values())
                    for n in range(1, N + 1):  # n = 1, ... N
                        yield n

            def N_generator_items():
                for n in N_generator():
                    assert isinstance(n, (dict, int))
                    if isinstance(n, int):
                        yield (n, n)
                    elif isinstance(n, dict):
                        assert len(n) == 1
                        (n_int, n_online_size_dict) = n.popitem()
                        assert isinstance(n_int, int)
                        assert isinstance(n_online_size_dict, OnlineSizeDict)
                        yield (n_int, n_online_size_dict)
                    else:
                        raise TypeError(
                            "Invalid item generated by N_generator")

            def N_generator_max():
                *_, Nmax = N_generator_items()
                assert isinstance(Nmax, tuple)
                assert len(Nmax) == 2
                assert isinstance(Nmax[0], int)
                return Nmax[0]

            print(
                TextBox(self.truth_problem.name() + " " + self.label +
                        " speedup analysis begins",
                        fill="="))
            print("")

            speedup_analysis_table = SpeedupAnalysisTable(self.testing_set)
            speedup_analysis_table.set_Nmax(N_generator_max())
            speedup_analysis_table.add_column("speedup_solve",
                                              group_name="speedup_solve",
                                              operations=("min", "mean",
                                                          "max"))
            speedup_analysis_table.add_column("speedup_output",
                                              group_name="speedup_output",
                                              operations=("min", "mean",
                                                          "max"))

            truth_timer = Timer("parallel")
            reduced_timer = Timer("serial")

            for (mu_index, mu) in enumerate(self.testing_set):
                print(TextLine(str(mu_index), fill="#"))

                self.reduced_problem.set_mu(mu)

                truth_timer.start()
                self.truth_problem.solve(**kwargs)
                elapsed_truth_solve = truth_timer.stop()

                truth_timer.start()
                self.truth_problem.compute_output()
                elapsed_truth_output = truth_timer.stop()

                for (n_int, n_arg) in N_generator_items():
                    reduced_timer.start()
                    solution = self.reduced_problem.solve(n_arg, **kwargs)
                    elapsed_reduced_solve = reduced_timer.stop()

                    reduced_timer.start()
                    output = self.reduced_problem.compute_output()
                    elapsed_reduced_output = reduced_timer.stop()

                    if solution is not NotImplemented:
                        speedup_analysis_table[
                            "speedup_solve", n_int,
                            mu_index] = elapsed_truth_solve / elapsed_reduced_solve
                    else:
                        speedup_analysis_table["speedup_solve", n_int,
                                               mu_index] = NotImplemented
                    if output is not NotImplemented:
                        speedup_analysis_table[
                            "speedup_output", n_int,
                            mu_index] = (elapsed_truth_solve +
                                         elapsed_truth_output) / (
                                             elapsed_reduced_solve +
                                             elapsed_reduced_output)
                    else:
                        speedup_analysis_table["speedup_output", n_int,
                                               mu_index] = NotImplemented

            # Print
            print("")
            print(speedup_analysis_table)

            print("")
            print(
                TextBox(self.truth_problem.name() + " " + self.label +
                        " speedup analysis ends",
                        fill="="))
            print("")

            # Export speedup analysis table
            speedup_analysis_table.save(
                self.folder["speedup_analysis"],
                "speedup_analysis" if filename is None else filename)
コード例 #5
0
 def _speedup_analysis(self, N_generator=None, filename=None, **kwargs):
     if N_generator is None:
         def N_generator(n):
             return n
             
     N = self.reduced_problem.N
     if isinstance(N, dict):
         N = min(N.values())
         
     print(TextBox(self.truth_problem.name() + " " + self.label + " speedup analysis begins", fill="="))
     print("")
     
     speedup_analysis_table = SpeedupAnalysisTable(self.testing_set)
     speedup_analysis_table.set_Nmax(N)
     speedup_analysis_table.add_column("speedup_solve", group_name="speedup_solve", operations=("min", "mean", "max"))
     speedup_analysis_table.add_column("speedup_output", group_name="speedup_output", operations=("min", "mean", "max"))
     
     truth_timer = Timer("parallel")
     reduced_timer = Timer("serial")
                 
     for (mu_index, mu) in enumerate(self.testing_set):
         print(TextLine(str(mu_index), fill="#"))
         
         self.reduced_problem.set_mu(mu)
         
         truth_timer.start()
         self.truth_problem.solve(**kwargs)
         elapsed_truth_solve = truth_timer.stop()
         
         truth_timer.start()
         self.truth_problem.compute_output()
         elapsed_truth_output = truth_timer.stop()
         
         for n in range(1, N + 1): # n = 1, ... N
             n_arg = N_generator(n)
             
             if n_arg is not None:
                 reduced_timer.start()
                 solution = self.reduced_problem.solve(n_arg, **kwargs)
                 elapsed_reduced_solve = reduced_timer.stop()
                 
                 reduced_timer.start()
                 output = self.reduced_problem.compute_output()
                 elapsed_reduced_output = reduced_timer.stop()
             else:
                 solution = NotImplemented
                 output = NotImplemented
             
             if solution is not NotImplemented:
                 speedup_analysis_table["speedup_solve", n, mu_index] = elapsed_truth_solve/elapsed_reduced_solve
             else:
                 speedup_analysis_table["speedup_solve", n, mu_index] = NotImplemented
             if output is not NotImplemented:
                 speedup_analysis_table["speedup_output", n, mu_index] = (elapsed_truth_solve + elapsed_truth_output)/(elapsed_reduced_solve + elapsed_reduced_output)
             else:
                 speedup_analysis_table["speedup_output", n, mu_index] = NotImplemented
     
     # Print
     print("")
     print(speedup_analysis_table)
     
     print("")
     print(TextBox(self.truth_problem.name() + " " + self.label + " speedup analysis ends", fill="="))
     print("")
     
     # Export speedup analysis table
     speedup_analysis_table.save(self.folder["speedup_analysis"], "speedup_analysis" if filename is None else filename)