コード例 #1
0
def compare_performance_1():
    counts = [100, 200, 400]
    labels = ['Verle', 'Threading', 'Multiprocessing', 'Cython', 'OpenCL']

    m_lists = {
        overall_verle: [],
        overall_verle_threading: [],
        overall_verle_multiprocessing: [],
        overall_verle_cython: [],
        overall_verle_opencl: []
    }

    tGrid = np.linspace(0, 5, 500)

    for count in counts:
        particleList = generate_random_particles(count)

        for i, method in enumerate(m_lists.keys()):
            start_time = time.time()
            particle_list = method(supercopy(particleList), tGrid)[1]
            total = time.time() - start_time

            m_lists[method].append(total)

            print(labels[i] + " done computing " + str(count) + ": " +
                  str(total))

    for i, lst in zip(range(len(labels)), m_lists.values()):
        plt.plot(counts, lst, label=labels[i])

    plt.xlabel('time')
    plt.ylabel('nodes')
    plt.legend()

    plt.show()
コード例 #2
0
ファイル: gui.py プロジェクト: whatcouldbepizza/other_tasks
    def __init__(self, ):
        """
        Main constructor
        """
        super(MyMainWindow, self).__init__()

        self.setupUi(self)
        self.connect_click_handlers()

        self.emitter = Emitter()

        self.particleList = []

        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)

        self.setLayouts()

        self.ax = self.figure.add_subplot(1, 1, 1)

        self.emitter_vector = Arrow(self.emitter.coordinates[0],
                                    self.emitter.coordinates[1],
                                    self.emitter.vector[0] / 20,
                                    self.emitter.vector[1] / 20,
                                    width=0.09)

        self.figure.canvas.mpl_connect('button_press_event',
                                       self.changeEmitter)

        self.solar_mode = False

        self.particleList = self.initialize_solar_system()
        self.particleListV = supercopy(self.particleList)

        self.toDraw = supercopy(self.particleList)

        self.animation = FuncAnimation(self.figure,
                                       self.draw_particles,
                                       interval=10)

        self.x_scale = None

        self.inaccuracy_iter = [[], []]
        self.i = 0
コード例 #3
0
def compare_performance_2():
    counts = [100, 200, 400]
    labels = ['Verle', 'Threading', 'Multiprocessing', 'Cython', 'OpenCL']

    m_lists = {
        overall_verle: [],
        overall_verle_threading: [],
        overall_verle_multiprocessing: [],
        overall_verle_cython: [],
        overall_verle_opencl: []
    }

    tGrid = np.linspace(0, 5, 100)

    for count in counts:
        particleList = generate_random_particles(count)

        for i, method in enumerate(m_lists.keys()):
            times = []

            for it in range(5):
                start_time = time.time()
                particle_list = method(supercopy(particleList), tGrid)[1]
                total = time.time() - start_time

                times.append(total)

                print(labels[i] + " computed " + str(it + 1) +
                      " iteration for " + str(count) + ": " + str(total))

            av = sum(times) / len(times)
            m_lists[method].append(av)

            print(labels[i] + " done computing " + str(count) + ", average: " +
                  str(av))

    for method in m_lists.keys():
        if method == overall_verle:
            continue

        for i in range(len(counts)):
            m_lists[method][i] = m_lists[overall_verle][i] / m_lists[method][i]

    for i, lst in zip(range(len(labels)), m_lists.values()):
        if i == 0:
            continue

        plt.plot(counts, lst, label=labels[i])

    plt.xlabel('speedup')
    plt.ylabel('nodes')
    plt.legend()

    plt.show()
コード例 #4
0
def compare(particleList):
    """
    Compare odeint and Verle methods
    """
    T = 1
    delta_t = 0.5
    tGrid = np.linspace(0, T, T / delta_t + 1)

    #result_list = []

    #if len(particleList) == 1:
    #    first_result = \
    #    [
    #        particleList[0].coordinates[0],
    #        particleList[0].coordinates[1],
    #        particleList[0].speed[0],
    #        particleList[0].speed[1]
    #    ]
    #    result_list.append(first_result)

    #    for i, _ in enumerate(tGrid):
    #        partial_result = \
    #        [
    #            result_list[-1][0] + result_list[-1][2],
    #            result_list[-1][1] + result_list[-1][3],
    #            result_list[-1][2],
    #            result_list[-1][3]
    #        ]
    #        result_list.append(partial_result)
    #        # TODO: do something

    odeint_list = supercopy(particleList)
    verle_list = supercopy(particleList)

    start_time = datetime.datetime.now()
    odeint_result, all_odeint = overall_odeint(odeint_list, tGrid)
    print("Odeint time: " + str(datetime.datetime.now() - start_time))

    start_time = datetime.datetime.now()
    verle_result, all_verle = overall_verle(verle_list, tGrid)
    print("Verle time: " + str(datetime.datetime.now() - start_time))
コード例 #5
0
ファイル: gui.py プロジェクト: whatcouldbepizza/other_tasks
    def draw_particles(self, frame):
        """
        Function to draw all particles
        """
        if self.pauseRadioButton.isChecked():
            return

        self.i += 1

        for i in range(len(self.toDraw)):
            try:
                self.toDraw[i].circle.remove()
            except Exception:
                pass

        delta_t = 0.01 if self.solar_mode else 1

        odeint_list = supercopy(self.particleList)
        verle_list = supercopy(self.particleListV)

        start_time = datetime.datetime.now()
        verle_list = overall_verle(verle_list, [0, delta_t / 2, delta_t])[0]
        #verle_list = overall_verle_threading(verle_list, [0, delta_t / 2, delta_t])[0]
        #verle_list = overall_verle_multiprocessing(verle_list, [0, delta_t / 2, delta_t])[0]
        #verle_list = overall_verle_cython(verle_list, [0, delta_t / 2, delta_t])[0]
        #verle_list = overall_verle_opencl(verle_list, [0, delta_t / 2, delta_t])[0]
        print("Verle iteration: {}".format(datetime.datetime.now() -
                                           start_time))

        #start_time = datetime.datetime.now()
        odeint_list = overall_odeint(odeint_list, [0, delta_t / 2, delta_t])[0]
        #print("Odeint iteration: {}".format(datetime.datetime.now() - start_time))

        self.particleList = to_particle_list(odeint_list, self.particleList)
        self.particleListV = to_particle_list(verle_list_, self.particleListV)

        metric = .0

        for p_1, p_2 in zip(self.particleList, self.particleListV):
            dist = np.array(p_1.coordinates) - np.array(p_2.coordinates)
            metric += np.linalg.norm(dist)

        self.inaccuracy_iter[0].append(self.i)
        self.inaccuracy_iter[1].append(metric)

        self.toDraw = supercopy(
            self.particleListV) if self.methodCheckBox.isChecked(
            ) else supercopy(self.particleList)

        if len(self.toDraw) != 0:

            if self.x_scale is None:
                self.x_scale = max(
                    [elem.coordinates[0] for elem in self.toDraw] + [100])
            max_m = max([elem.mass for elem in self.toDraw])

            sorted_masses = sorted([elem.mass for elem in self.toDraw])
            masses_map = dict()
            sizes = np.linspace(0.01, 0.03, len(sorted_masses))

            for i, elem in enumerate(sorted_masses):
                masses_map[elem] = sizes[i]

            for i in range(len(self.toDraw)):

                self.toDraw[i].create_circle(
                    coordinates=[
                        self.toDraw[i].coordinates[0] / (self.x_scale * 2.1) +
                        0.5, self.toDraw[i].coordinates[1] /
                        (self.x_scale * 2.1) + 0.5
                    ],
                    size=masses_map[self.toDraw[i].mass],
                    color=self.toDraw[i].color)

                self.ax.add_artist(self.toDraw[i].circle)

        self.figure.canvas.draw_idle()
コード例 #6
0
def compare_accuracy():
    solar_system = initialize_solar_system()

    odeint_list_0 = supercopy(solar_system)
    verle_list_0 = supercopy(solar_system)
    verle_list_t_0 = supercopy(solar_system)
    verle_list_m_0 = supercopy(solar_system)
    verle_list_c_0 = supercopy(solar_system)
    verle_list_o_0 = supercopy(solar_system)

    tGrid = np.linspace(0, 5, 500)

    odeint_list = overall_odeint(odeint_list_0, tGrid)[1]
    verle_list = overall_verle(verle_list_0, tGrid)[1]
    verle_list_t = overall_verle_threading(verle_list_t_0, tGrid)[1]
    verle_list_m = overall_verle_multiprocessing(verle_list_m_0, tGrid)[1]
    verle_list_c = overall_verle_cython(verle_list_c_0, tGrid)[1]
    verle_list_o = overall_verle_opencl(verle_list_o_0, tGrid)[1]

    inacc_v = []
    inacc_vt = []
    inacc_vm = []
    inacc_vc = []
    inacc_vo = []

    for t in range(len(tGrid)):
        metric_v = .0
        metric_vt = .0
        metric_vm = .0
        metric_vc = .0
        metric_vo = .0

        for p_o, p_v, p_vt, p_vm, p_vc, p_vo in zip(
                odeint_list[t], verle_list[t], verle_list_t[t],
                verle_list_m[t], verle_list_c[t], verle_list_o[t]):
            dist_v = (np.array(p_o[:2]) - np.array(p_v[:2]))
            dist_vt = (np.array(p_o[:2]) - np.array(p_vt[:2]))
            dist_vm = (np.array(p_o[:2]) - np.array(p_vm[:2]))
            dist_vc = (np.array(p_o[:2]) - np.array(p_vc[:2]))
            dist_vo = (np.array(p_o[:2]) - np.array(p_vo[:2]))

            metric_v += np.linalg.norm(dist_v)
            metric_vt += np.linalg.norm(dist_vt)
            metric_vm += np.linalg.norm(dist_vm)
            metric_vc += np.linalg.norm(dist_vc)
            metric_vo += np.linalg.norm(dist_vo)

        inacc_v.append(metric_v)
        inacc_vt.append(metric_vt)
        inacc_vm.append(metric_vm)
        inacc_vc.append(metric_vc)
        inacc_vo.append(metric_vo)

    plt.plot(tGrid, inacc_v, label='Verle')
    plt.plot(tGrid, inacc_vt, label='Threading')
    plt.plot(tGrid, inacc_vm, label='Multiprocessing')
    plt.plot(tGrid, inacc_vc, label='Cython')
    plt.plot(tGrid, inacc_vo, label='OpenCL')

    plt.legend()
    plt.show()