コード例 #1
0
ファイル: cache_opt_comp.py プロジェクト: goldmanm/pyJac
def plotco(lang, smem_default=False, norm=True):
    desc = 'gpu' if lang == 'cuda' else 'cpu'
    if lang == 'c':
        smem_default=False

    fig, ax = plt.subplots()
    miny = None

    linestyle = ''
    plot_std = False
    nco_marker = 'o'
    co_marker = 's'

    #pyjac
    plotdata1 = [x for x in data if not x.finite_difference
                    and x.lang == lang
                    and not x.cache_opt
                    and x.smem==smem_default]

    plotdata2 = [x for x in data if not x.finite_difference
                    and x.lang == lang
                    and x.cache_opt
                    and x.smem==smem_default]

    if norm:
        xvals = sorted(list(set([p.num_reacs for p in plotdata1] + [p.num_reacs for p in plotdata2])))
        def get_y(plotdata, x):
            return np.mean(next(pd for pd in plotdata if pd.num_reacs == x).y)
        ymax = [max(get_y(plotdata1, x), get_y(plotdata2, x)) for x in xvals]
        for i, x in enumerate(xvals):
            for pd in [pdtest for pdtest in plotdata1 + plotdata2 if pdtest.num_reacs == x]:
                pd.y = np.array(pd.y / ymax[i])

    def fake_norm(x):
        return np.array(x.y)

    thenorm = None if not norm else fake_norm
    miny = plot(plotdata1, nco_marker, 'Non Cache-Optimized', miny, norm=thenorm)
    miny = plot(plotdata2, nco_marker, 'Cache-Optimized', miny, norm=thenorm)

    if not norm:
        ax.set_yscale('log')
    ax.set_ylim(ymin=miny*0.95)
    ax.legend(loc=0, numpoints=1)
    # add some text for labels, title and axes ticks
    ax.set_ylabel('Mean evaluation time / condition (ms)')
    #ax.set_title('GPU Jacobian Evaluation Performance for {} mechanism'.format(thedir))
    ax.set_xlabel('Number of reactions')
    #ax.legend(loc=0)
    plt.savefig('cache_opt_{}.pdf'.format(desc))
    plt.close() 
コード例 #2
0
def fullscale_comp(lang,
                   plot_std=True,
                   homedir=None,
                   cache_opt_default=False,
                   smem_default=False,
                   loc_override=None,
                   text_loc=None,
                   fontsize=10,
                   color_list=['b', 'g', 'r', 'k']):
    if lang == 'c':
        langs = ['c', 'tchem']
        desc = 'cpu'
        smem_default = False
    elif lang == 'cuda':
        langs = ['cuda']
        desc = 'gpu'
    else:
        raise Exception('unknown lang {}'.format(lang))

    def thefilter(x):
        return x.cache_opt == cache_opt_default and x.smem == smem_default

    fit_vals = []
    data = get_data(homedir)
    data = [x for x in data if x.lang in langs]
    data = filter(thefilter, data)
    data = get_fullscale(data)
    if not len(data):
        print 'no data found... exiting'
        sys.exit(-1)

    fig, ax = plt.subplots()
    miny = None

    linestyle = ''

    fitvals = []
    retdata = []
    color_ind = 0
    text_ind = None
    if text_loc:
        text_ind = 0

    #FD
    plotdata = [x for x in data if x.finite_difference]
    if plotdata:
        color = color_list[color_ind]
        color_ind += 1
        miny, they, thez = plot(plotdata,
                                FD_marker,
                                'Finite Difference',
                                miny,
                                return_y=True,
                                color=color)
        theloc = None
        if text_ind is not None:
            theloc = text_loc[text_ind]
            text_ind += 1
        fitvals.append(
            fit_order(plotdata,
                      they,
                      thez,
                      None,
                      color,
                      text_loc=theloc,
                      fontsize=fontsize))
        retdata.append(they)

    for lang in langs:
        plotdata = [
            x for x in data if not x.finite_difference and x.lang == lang
        ]
        color = color_list[color_ind]
        color_ind += 1
        if plotdata:
            name, marker = nice_names(plotdata[0])
            miny, they, thez = plot(plotdata,
                                    marker,
                                    name,
                                    miny,
                                    return_y=True,
                                    color=color)
            theloc = None
            if text_ind is not None:
                theloc = text_loc[text_ind]
                text_ind += 1
            fitvals.append(
                fit_order(plotdata,
                          they,
                          thez,
                          None,
                          color,
                          text_loc=theloc,
                          fontsize=fontsize))
            retdata.append(they)

    ax.set_yscale('log')
    ax.set_ylim(ymin=miny * 0.95)
    loc = 0 if loc_override is None else loc_override
    ax.legend(loc=loc, numpoints=1, fontsize=10)
    # add some text for labels, title and axes ticks
    ax.set_ylabel('Mean evaluation time / condition (ms)')
    #ax.set_title('GPU Jacobian Evaluation Performance for {} mechanism'.format(thedir))
    ax.set_xlabel('Number of Reactions')
    #ax.legend(loc=0)
    plt.savefig('{}_norm.pdf'.format(desc))
    plt.close()

    return fitvals, retdata
コード例 #3
0
ファイル: fullscale_comp.py プロジェクト: goldmanm/pyJac
def fullscale_comp(lang, plot_std=True, homedir=None,
                        cache_opt_default=False,
                        smem_default=False,
                        loc_override=None,
                        text_loc=None, fontsize=10,
                        color_list=['b', 'g', 'r', 'k']):
    if lang == 'c':
        langs = ['c', 'tchem']
        desc = 'cpu'
        smem_default=False
    elif lang == 'cuda':
        langs = ['cuda']
        desc = 'gpu'
    else:
        raise Exception('unknown lang {}'.format(lang))

    def thefilter(x):
        return x.cache_opt==cache_opt_default and x.smem == smem_default
    
    fit_vals = []
    data = get_data(homedir)
    data = [x for x in data if x.lang in langs]
    data = filter(thefilter, data)
    data = get_fullscale(data)
    if not len(data):
        print 'no data found... exiting'
        sys.exit(-1)

    fig, ax = plt.subplots()
    miny = None

    linestyle = ''

    fitvals = []
    retdata = []
    color_ind = 0
    text_ind = None
    if text_loc:
        text_ind = 0

    #FD
    plotdata = [x for x in data if x.finite_difference]
    if plotdata:
        color = color_list[color_ind]
        color_ind += 1
        miny, they, thez = plot(plotdata, FD_marker, 'Finite Difference', miny, return_y=True, color=color)
        theloc = None
        if text_ind is not None:
            theloc = text_loc[text_ind]
            text_ind += 1
        fitvals.append(
            fit_order(plotdata, they, thez, None, color, text_loc=theloc, fontsize=fontsize)
            )
        retdata.append(they)

    for lang in langs:
        plotdata = [x for x in data if not x.finite_difference
                        and x.lang == lang]
        color = color_list[color_ind]
        color_ind += 1
        if plotdata:
            name, marker = nice_names(plotdata[0])
            miny, they, thez = plot(plotdata, marker, name, miny, return_y=True, color=color)
            theloc = None
            if text_ind is not None:
                theloc = text_loc[text_ind]
                text_ind += 1
            fitvals.append(
                fit_order(plotdata, they, thez, None, color, text_loc=theloc, fontsize=fontsize)
            )
            retdata.append(they)

    ax.set_yscale('log')
    ax.set_ylim(ymin=miny*0.95)
    loc = 0 if loc_override is None else loc_override
    ax.legend(loc=loc, numpoints=1, fontsize=10)
    # add some text for labels, title and axes ticks
    ax.set_ylabel('Mean evaluation time / condition (ms)')
    #ax.set_title('GPU Jacobian Evaluation Performance for {} mechanism'.format(thedir))
    ax.set_xlabel('Number of Reactions')
    #ax.legend(loc=0)
    plt.savefig('{}_norm.pdf'.format(desc))
    plt.close()

    return fitvals, retdata
コード例 #4
0
ファイル: perf_plotter.py プロジェクト: arghdos/SPyJac-paper
def plotter(data_clean,
            plot_name='',
            show=True,
            plot_reacs=True,
            norm=True,
            legend_handler=None,
            marker_func=None,
            minx=None,
            miny=None,
            maxx=None,
            maxy=None,
            ylog=False,
            return_vals=False,
            **filters):

    # create fig, ax
    plt.figure()
    ax = plt.subplot(1, 1, 1)

    data = get_filtered_data(data_clean, **filters)

    # now plot data
    to_plot = ['runtime']
    if filters.pop('plot_compilation', False):
        to_plot.append('comptime')
    if filters.pop('plot_overhead', False):
        to_plot.append('overhead')
    # get data
    plot_data = flatten(data)
    # get labels

    diffs, diff_locs, diff_check = get_diffs(plot_data)
    plot_cores = False
    if 'cores' in [diff_check[loc] for loc in diff_locs]:
        # can only process one
        plot_cores = len(diff_locs) == 1
        if plot_cores:
            diffs = [sorted(data.keys())]
            diff_locs = [-1]
            diff_check.append('mechdata.mech')
            plot_reacs = False
            plot_cores = True

    retval = None
    # delete diff for vecwidth / par thing
    if 'vectype' in [diff_check[loc] for loc in diff_locs]:
        ind = next((i for i, loc in enumerate(diff_locs)
                    if diff_check[loc] == 'vecwidth'), None)
        if ind is not None:
            diffs.pop(ind)
            diff_locs.pop(ind)

    if len(diff_locs) > 2:
        raise NotImplementedError
    if not diff_locs:
        # regular plot
        for plot in to_plot:
            gp.plot(*gp.process_data(plot_data, plot, reacs_as_x=plot_reacs))
    else:
        # create map dict
        loc_map = {}
        for i, diff in enumerate(diffs):
            for subdiff in diff:
                loc_map[subdiff] = diff_locs[i]

        # sort
        try:
            diffs = [sorted(diff, key=lambda x: float(x)) for diff in diffs]
        except:
            if plot_cores:
                # sort by mech size
                diffs = [
                    sorted(diff, key=lambda x: data[x][0].mechdata.n_reactions)
                    for diff in diffs
                ]
            else:
                diffs = [sorted(diff) for diff in diffs]

        # first pass - process data
        x_vals = []
        y_vals = []
        z_vals = []
        labels = []

        def __get_compound_names(val1, val2):
            c1 = diff_check[loc_map[val1]]
            c2 = diff_check[loc_map[val2]]

            # generic name ordering
            ordering = ['vectype', 'order']

            # sort by order
            check_vals = [None for _ in diff_check]
            check_vals[loc_map[val1]] = c1
            check_vals[loc_map[val2]] = c2
            check_vals = sorted(check_vals,
                                key=lambda x: 100
                                if x not in ordering else ordering.index(x))

            # remove none
            check_vals = [x for x in check_vals if x is not None]

            # and return str
            return ' - '.join(
                ps.pretty_names(check).format(val1 if check == c1 else val2)
                for check in check_vals)

        # handle 2 diffs
        if len(diffs) == 1:
            for val in [subdiff for diff in diffs for subdiff in diff]:
                check = diff_check[loc_map[val]]
                match = [
                    x for x in plot_data
                    if __compare(x, check, val, plot_cores=plot_cores)
                ]
                if match:
                    labels.append(ps.pretty_names(check).format(val))
                    x, y, z = gp.process_data(match,
                                              'runtime',
                                              reacs_as_x=plot_reacs,
                                              plot_cores=plot_cores)
                    x_vals.append(x)
                    y_vals.append(y)
                    z_vals.append(z)
        else:
            iterator = [
                zip(x, diffs[1])
                for x in itertools.permutations(diffs[0], len(diffs[0]))
            ]
            iterator = [subiter for i in iterator for subiter in i]
            for val1, val2 in iterator:
                match = [
                    x for x in plot_data
                    if __compare(x,
                                 diff_check[loc_map[val1]],
                                 val1,
                                 plot_cores=plot_cores)
                    and __compare(x, diff_check[loc_map[val2]], val2)
                ]
                if match:
                    labels.append(__get_compound_names(val1, val2))
                    x, y, z = gp.process_data(match,
                                              'runtime',
                                              reacs_as_x=plot_reacs,
                                              plot_cores=plot_cores)
                    x_vals.append(x)
                    y_vals.append(y)
                    z_vals.append(z)

        if return_vals:

            def __copy_arr(val):
                return [v[:] for v in val]

            retval = [
                __copy_arr(x_vals),
                __copy_arr(y_vals),
                __copy_arr(z_vals),
                copy.copy(labels)
            ]

        # second pass - normalize
        if norm and not plot_cores:
            xlen = len(next(x for x in x_vals if x))
            # find the max y for each x
            for ix in range(xlen):
                y_max = np.max(
                    [y_vals[i][ix] for i in range(len(y_vals)) if y_vals[i]])
                # divide
                for i in range(len(y_vals)):
                    z_vals[i][ix] = (z_vals[i][ix] /
                                     y_vals[i][ix]) * (y_max / y_vals[i][ix])
                    y_vals[i][ix] = y_max / y_vals[i][ix]

        elif norm:
            # parallel scaling eff
            for ix in range(len(x_vals)):
                for i in range(1, len(x_vals[ix])):
                    # scaling eff is t1 / (N * tN)
                    y_vals[ix][i] = y_vals[ix][0] / \
                        (x_vals[ix][i] * y_vals[ix][i])
                    # update uncertainty
                    z_vals[ix][i] = y_vals[ix][i] * np.sqrt(
                        np.power(z_vals[ix][0] / y_vals[ix][0], 2) +
                        np.power(z_vals[ix][i] / y_vals[ix][i], 2))
                # remove first entry (1 core)
                assert x_vals[ix][0] == 1
                x_vals[ix] = x_vals[ix][1:]
                y_vals[ix] = y_vals[ix][1:]
                z_vals[ix] = z_vals[ix][1:]

        if ylog:
            ax.set_yscale('log')

        # and finally plot
        for i in range(len(y_vals)):
            gp.plot(x_vals[i],
                    y_vals[i],
                    z_vals[i],
                    labels=labels,
                    plot_ind=i,
                    marker_func=marker_func)
        ax.set_xlim([minx, maxx])
        ax.set_ylim([miny, maxy])

    ylabel = r'Runtime (\si{\milli\second} / state)'
    xlabel = r'Number of {} in Model'.format(
        'Species' if not plot_reacs else 'Reactions')
    if norm:
        ylabel = 'Speedup'
        if plot_cores:
            ylabel = 'Parallel Scaling Efficiency'
    if plot_cores:
        xlabel = 'Number of Cores'

    plt.ylabel(ylabel)
    plt.xlabel(xlabel)
    if legend_handler:
        plt.legend(*legend_handler, **ps.legend_style).draggable()
    else:
        plt.legend(**ps.legend_style)
    ps.finalize()
    if plot_name:
        plt.savefig(plot_name)
    if show:
        plt.show()
    return retval
コード例 #5
0
def fullscale_comp(lang, plot_std=True, homedir=None,
                   cache_opt_default=False,
                   smem_default=False,
                   loc_override=None,
                   text_loc=None,
                   color_list=['b', 'g', 'r', 'k']
                   ):
    if lang == 'c':
        langs = ['c', 'tchem']
        desc = 'cpu'
        smem_default = False
    elif lang == 'cuda':
        langs = ['cuda']
        desc = 'gpu'
    else:
        raise Exception('unknown lang {}'.format(lang))

    def thefilter(x):
        return (x.cache_opt==cache_opt_default and
                x.smem == smem_default and
                x.lang in langs
                )

    fit_vals = []
    data = get_data(homedir)
    data = [x for x in data if thefilter(x)]
    data = get_fullscale(data)
    if not len(data):
        print('no data found... exiting')
        sys.exit(-1)

    fig, ax = plt.subplots()

    linestyle = ''

    fitvals = []
    retdata = []
    color_ind = 0
    text_ind = None
    if text_loc:
        text_ind = 0

    # finite difference
    plotdata = [x for x in data if x.finite_difference]
    if plotdata:
        color = color_list[color_ind]
        color_ind += 1
        (minx, miny), y_vals, err_vals = plot(plotdata, FD_marker,
                                              'Finite Difference',
                                              return_y=True, color=color
                                              )
        theloc = None
        if text_ind is not None:
            theloc = text_loc[text_ind]
            text_ind += 1
        fitvals.append(
            fit_order(plotdata, y_vals, err_vals, color=color, text_loc=theloc)
            )
        retdata.append(y_vals)

    for lang in langs:
        plotdata = [x for x in data if not x.finite_difference
                    and x.lang == lang
                    ]
        color = color_list[color_ind]
        color_ind += 1
        if plotdata:
            name, marker = nice_names(plotdata[0])
            (minx, miny), y_vals, err_vals = plot(plotdata, marker, name,
                                                  minx, miny,
                                                  return_y=True, color=color
                                                  )
            theloc = None
            if text_ind is not None:
                theloc = text_loc[text_ind]
                text_ind += 1
            fitvals.append(
                fit_order(plotdata, y_vals, err_vals, None, color, text_loc=theloc)
                )
            retdata.append(y_vals)

    ax.set_yscale('log')
    ax.set_ylim(ymin=miny*0.85)
    ax.set_xlim(xmin=0)
    loc = 0 if loc_override is None else loc_override
    ax.legend(loc=loc, numpoints=1, fontsize=font_size,
              shadow=True, fancybox=True
              )
    # add some text for labels, title and axes ticks
    ax.set_ylabel('Mean evaluation time / condition (ms)', fontsize=font_size)
    ax.set_xlabel('Number of Reactions', fontsize=font_size)

    if homedir is None:
        homedir = os.path.join(sys.path[0], '../')
        homedir = os.path.realpath(homedir)
    d = os.path.join(homedir, 'figures')

    pp = PdfPages(os.path.join(d, '{}_performance_comparison.pdf'.format(desc)))
    pp.savefig()
    pp.close()

    plt.close()

    return fitvals, retdata